PHP 8.2.31
Preview: IdentifierManipulator.php Size: 1.80 KB
/opt/cpanel/ea-wappspector/vendor/rector/rector/vendor/rector/rector-phpunit/src/NodeAnalyzer/IdentifierManipulator.php

<?php

declare (strict_types=1);
namespace Rector\PHPUnit\NodeAnalyzer;

use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\NodeNameResolver\NodeNameResolver;
/**
 * This class renames node identifier, e.g. ClassMethod rename:
 *
 * -public function someMethod()
 * +public function newMethod()
 */
final class IdentifierManipulator
{
    /**
     * @readonly
     * @var \Rector\NodeNameResolver\NodeNameResolver
     */
    private $nodeNameResolver;
    public function __construct(NodeNameResolver $nodeNameResolver)
    {
        $this->nodeNameResolver = $nodeNameResolver;
    }
    /**
     * @param array<string, string> $renameMethodMap
     * @param \PhpParser\Node\Expr\ClassConstFetch|\PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\PropertyFetch|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Stmt\ClassMethod $node
     */
    public function renameNodeWithMap($node, array $renameMethodMap) : bool
    {
        $oldNodeMethodName = $this->resolveOldMethodName($node);
        if (!\is_string($oldNodeMethodName)) {
            return \false;
        }
        $node->name = new Identifier($renameMethodMap[$oldNodeMethodName]);
        return \true;
    }
    /**
     * @param \PhpParser\Node\Expr\ClassConstFetch|\PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\PropertyFetch|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Stmt\ClassMethod $node
     */
    private function resolveOldMethodName($node) : ?string
    {
        if ($node instanceof StaticCall || $node instanceof MethodCall) {
            return $this->nodeNameResolver->getName($node->name);
        }
        return $this->nodeNameResolver->getName($node);
    }
}

Directory Contents

Dirs: 0 × Files: 6

Name Size Perms Modified Actions
536 B lrw-r--r-- 2024-11-08 13:59:10
Edit Download
6.62 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
1.80 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
3.08 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
1.21 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download
3.59 KB lrw-r--r-- 2024-11-08 13:59:10
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).