[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: ConflictingNameResolver.php
File is not writable. Editing disabled.
<?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\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; use Rector\Naming\ExpectedNameResolver\MatchParamTypeExpectedNameResolver; use Rector\Naming\PhpArray\ArrayFilter; use Rector\NodeManipulator\FunctionLikeManipulator; use Rector\PhpParser\Node\BetterNodeFinder; final class ConflictingNameResolver { /** * @readonly * @var \Rector\Naming\PhpArray\ArrayFilter */ private $arrayFilter; /** * @readonly * @var \Rector\PhpParser\Node\BetterNodeFinder */ private $betterNodeFinder; /** * @readonly * @var \Rector\Naming\Naming\ExpectedNameResolver */ private $expectedNameResolver; /** * @readonly * @var \Rector\Naming\ExpectedNameResolver\MatchParamTypeExpectedNameResolver */ private $matchParamTypeExpectedNameResolver; /** * @readonly * @var \Rector\NodeManipulator\FunctionLikeManipulator */ private $functionLikeManipulator; /** * @var array<int, string[]> */ private $conflictingVariableNamesByClassMethod = []; public function __construct(ArrayFilter $arrayFilter, BetterNodeFinder $betterNodeFinder, \Rector\Naming\Naming\ExpectedNameResolver $expectedNameResolver, MatchParamTypeExpectedNameResolver $matchParamTypeExpectedNameResolver, FunctionLikeManipulator $functionLikeManipulator) { $this->arrayFilter = $arrayFilter; $this->betterNodeFinder = $betterNodeFinder; $this->expectedNameResolver = $expectedNameResolver; $this->matchParamTypeExpectedNameResolver = $matchParamTypeExpectedNameResolver; $this->functionLikeManipulator = $functionLikeManipulator; } /** * @return string[] * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure|\PhpParser\Node\Expr\ArrowFunction $classMethod */ public function resolveConflictingVariableNamesForParam($classMethod) : array { $expectedNames = []; foreach ($classMethod->params as $param) { $expectedName = $this->matchParamTypeExpectedNameResolver->resolve($param); if ($expectedName === null) { continue; } $expectedNames[] = $expectedName; } return $this->arrayFilter->filterWithAtLeastTwoOccurences($expectedNames); } /** * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure|\PhpParser\Node\Expr\ArrowFunction $functionLike */ public function hasNameIsInFunctionLike(string $variableName, $functionLike) : bool { $conflictingVariableNames = $this->resolveConflictingVariableNamesForNew($functionLike); return \in_array($variableName, $conflictingVariableNames, \true); } /** * @return string[] * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure|\PhpParser\Node\Expr\ArrowFunction $functionLike */ private function resolveConflictingVariableNamesForNew($functionLike) : array { // cache it! $classMethodId = \spl_object_id($functionLike); if (isset($this->conflictingVariableNamesByClassMethod[$classMethodId])) { return $this->conflictingVariableNamesByClassMethod[$classMethodId]; } $paramNames = $this->functionLikeManipulator->resolveParamNames($functionLike); $newAssignNames = $this->resolveForNewAssigns($functionLike); $nonNewAssignNames = $this->resolveForNonNewAssigns($functionLike); $protectedNames = \array_merge($paramNames, $newAssignNames, $nonNewAssignNames); $protectedNames = $this->arrayFilter->filterWithAtLeastTwoOccurences($protectedNames); $this->conflictingVariableNamesByClassMethod[$classMethodId] = $protectedNames; return $protectedNames; } /** * @return string[] * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure|\PhpParser\Node\Expr\ArrowFunction $functionLike */ private function resolveForNewAssigns($functionLike) : array { $names = []; /** @var Assign[] $assigns */ $assigns = $this->betterNodeFinder->findInstanceOf((array) $functionLike->getStmts(), Assign::class); foreach ($assigns as $assign) { $name = $this->expectedNameResolver->resolveForAssignNew($assign); if ($name === null) { continue; } $names[] = $name; } return $names; } /** * @return string[] * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure|\PhpParser\Node\Expr\ArrowFunction $functionLike */ private function resolveForNonNewAssigns($functionLike) : array { $names = []; /** @var Assign[] $assigns */ $assigns = $this->betterNodeFinder->findInstanceOf((array) $functionLike->getStmts(), Assign::class); foreach ($assigns as $assign) { $name = $this->expectedNameResolver->resolveForAssignNonNew($assign); if ($name === null) { continue; } $names[] = $name; } return $names; } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: premium264.web-hosting.com
Server IP: 69.57.162.13
PHP Version: 8.1.34
Server Software: LiteSpeed
System: Linux premium264.web-hosting.com 4.18.0-553.45.1.lve.el8.x86_64 #1 SMP Wed Mar 26 12:08:09 UTC 2025 x86_64
HDD Total: 97.87 GB
HDD Free: 73.56 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
No
pkexec:
No
git:
Yes
User Info
Username: kidscntx
User ID (UID): 1154
Group ID (GID): 1112
Script Owner UID: 1154
Current Dir Owner: N/A