Skip to content

Commit bc20a09

Browse files
committed
Updated Rector to commit e7b063f554393e1465565a54f33be58e93ef0c54
rectorphp/rector-src@e7b063f Update AnonymousFunctionFactory to not allow superglobal variables in use statements (#6811)
1 parent 8191f90 commit bc20a09

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

rules/Php72/NodeFactory/AnonymousFunctionFactory.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use PhpParser\Node\UnionType;
2424
use Rector\NodeNameResolver\NodeNameResolver;
2525
use Rector\NodeTypeResolver\Node\AttributeKey;
26+
use Rector\Php\ReservedKeywordAnalyzer;
2627
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
2728
use Rector\PhpParser\Node\BetterNodeFinder;
2829
use Rector\PhpParser\Parser\InlineCodeParser;
@@ -49,18 +50,23 @@ final class AnonymousFunctionFactory
4950
* @readonly
5051
*/
5152
private InlineCodeParser $inlineCodeParser;
53+
/**
54+
* @readonly
55+
*/
56+
private ReservedKeywordAnalyzer $reservedKeywordAnalyzer;
5257
/**
5358
* @var string
5459
* @see https://regex101.com/r/jkLLlM/2
5560
*/
5661
private const DIM_FETCH_REGEX = '#(\\$|\\\\|\\x0)(?<number>\\d+)#';
57-
public function __construct(NodeNameResolver $nodeNameResolver, BetterNodeFinder $betterNodeFinder, SimpleCallableNodeTraverser $simpleCallableNodeTraverser, SimplePhpParser $simplePhpParser, InlineCodeParser $inlineCodeParser)
62+
public function __construct(NodeNameResolver $nodeNameResolver, BetterNodeFinder $betterNodeFinder, SimpleCallableNodeTraverser $simpleCallableNodeTraverser, SimplePhpParser $simplePhpParser, InlineCodeParser $inlineCodeParser, ReservedKeywordAnalyzer $reservedKeywordAnalyzer)
5863
{
5964
$this->nodeNameResolver = $nodeNameResolver;
6065
$this->betterNodeFinder = $betterNodeFinder;
6166
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
6267
$this->simplePhpParser = $simplePhpParser;
6368
$this->inlineCodeParser = $inlineCodeParser;
69+
$this->reservedKeywordAnalyzer = $reservedKeywordAnalyzer;
6470
}
6571
/**
6672
* @api
@@ -150,6 +156,10 @@ private function createUseVariablesFromParams(array $nodes, array $params) : arr
150156
if (\in_array($variableName, $paramNames, \true)) {
151157
continue;
152158
}
159+
// Superglobal variables cannot be in a use statement
160+
if ($this->reservedKeywordAnalyzer->isNativeVariable($variableName)) {
161+
continue;
162+
}
153163
if ($variable->getAttribute(AttributeKey::IS_BEING_ASSIGNED) === \true || $variable->getAttribute(AttributeKey::IS_PARAM_VAR) === \true || $variable->getAttribute(AttributeKey::IS_VARIABLE_LOOP) === \true) {
154164
$alreadyAssignedVariables[] = $variableName;
155165
}

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = '6307286c278beedcb8ca379ff31d73cf31628544';
22+
public const PACKAGE_VERSION = 'e7b063f554393e1465565a54f33be58e93ef0c54';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2025-03-26 17:18:58';
27+
public const RELEASE_DATE = '2025-03-28 01:26:54';
2828
/**
2929
* @var int
3030
*/

0 commit comments

Comments
 (0)