REDROOM
PHP 8.2.31
Path:
Logout
Edit File
Size: 3.73 KB
Close
/opt/cpanel/ea-wappspector/vendor/rector/rector/rules/Naming/Naming/OverridenExistingNamesResolver.php
Text
Base64
<?php declare (strict_types=1); namespace Rector\Naming\Naming; use PhpParser\Node\Expr\ArrowFunction; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; use Rector\Naming\PhpArray\ArrayFilter; use Rector\NodeNameResolver\NodeNameResolver; use Rector\PhpParser\Node\BetterNodeFinder; final class OverridenExistingNamesResolver { /** * @readonly * @var \Rector\Naming\PhpArray\ArrayFilter */ private $arrayFilter; /** * @readonly * @var \Rector\PhpParser\Node\BetterNodeFinder */ private $betterNodeFinder; /** * @readonly * @var \Rector\NodeNameResolver\NodeNameResolver */ private $nodeNameResolver; /** * @var array<int, array<int, string>> */ private $overridenExistingVariableNamesByClassMethod = []; public function __construct(ArrayFilter $arrayFilter, BetterNodeFinder $betterNodeFinder, NodeNameResolver $nodeNameResolver) { $this->arrayFilter = $arrayFilter; $this->betterNodeFinder = $betterNodeFinder; $this->nodeNameResolver = $nodeNameResolver; } /** * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike */ public function hasNameInClassMethodForNew(string $variableName, $functionLike) : bool { $overridenVariableNames = $this->resolveOveriddenNamesForNew($functionLike); return \in_array($variableName, $overridenVariableNames, \true); } /** * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure|\PhpParser\Node\Expr\ArrowFunction $classMethod */ public function hasNameInFunctionLikeForParam(string $expectedName, $classMethod) : bool { /** @var Assign[] $assigns */ $assigns = $this->betterNodeFinder->findInstanceOf((array) $classMethod->getStmts(), Assign::class); $usedVariableNames = []; foreach ($assigns as $assign) { if (!$assign->var instanceof Variable) { continue; } $variableName = $this->nodeNameResolver->getName($assign->var); if ($variableName === null) { continue; } $usedVariableNames[] = $variableName; } return \in_array($expectedName, $usedVariableNames, \true); } /** * @return string[] * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike */ private function resolveOveriddenNamesForNew($functionLike) : array { $classMethodId = \spl_object_id($functionLike); if (isset($this->overridenExistingVariableNamesByClassMethod[$classMethodId])) { return $this->overridenExistingVariableNamesByClassMethod[$classMethodId]; } $currentlyUsedNames = []; /** @var Assign[] $assigns */ $assigns = $this->betterNodeFinder->findInstanceOf((array) $functionLike->stmts, Assign::class); foreach ($assigns as $assign) { /** @var Variable $assignVariable */ $assignVariable = $assign->var; $currentVariableName = $this->nodeNameResolver->getName($assignVariable); if ($currentVariableName === null) { continue; } $currentlyUsedNames[] = $currentVariableName; } $currentlyUsedNames = \array_values($currentlyUsedNames); $currentlyUsedNames = $this->arrayFilter->filterWithAtLeastTwoOccurences($currentlyUsedNames); $this->overridenExistingVariableNamesByClassMethod[$classMethodId] = $currentlyUsedNames; return $currentlyUsedNames; } }
Save
Close
Exit & Reset
Text mode: syntax highlighting auto-detects file type.
Directory Contents
Dirs: 0 × Files: 7
Delete Selected
Select All
Select None
Sort:
Name
Size
Modified
Enable drag-to-move
Name
Size
Perms
Modified
Actions
AliasNameResolver.php
1.23 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
ConflictingNameResolver.php
5.32 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
ExpectedNameResolver.php
7.71 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
OverridenExistingNamesResolver.php
3.73 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
PropertyNaming.php
9.60 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
UseImportsResolver.php
2.46 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
VariableNaming.php
4.86 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Zip Selected
If ZipArchive is unavailable, a
.tar
will be created (no compression).