|
3 | 3 | declare (strict_types=1); |
4 | 4 | namespace Rector\Php82\Rector\New_; |
5 | 5 |
|
6 | | -use FilesystemIterator; |
7 | 6 | use PhpParser\Node; |
8 | 7 | use PhpParser\Node\Arg; |
9 | 8 | use PhpParser\Node\Expr; |
|
12 | 11 | use PhpParser\Node\Expr\New_; |
13 | 12 | use PhpParser\Node\Name\FullyQualified; |
14 | 13 | use PHPStan\Type\ObjectType; |
15 | | -use Rector\NodeNameResolver\NodeNameResolver\ClassConstFetchNameResolver; |
| 14 | +use Rector\PhpParser\Node\Value\ValueResolver; |
16 | 15 | use Rector\Rector\AbstractRector; |
17 | 16 | use Rector\ValueObject\PhpVersionFeature; |
18 | 17 | use Rector\VersionBonding\Contract\MinPhpVersionInterface; |
19 | 18 | use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; |
20 | 19 | use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; |
21 | 20 | /** |
22 | | - * @see \Rector\Tests\Php82\Rector\New_\FilesystemIteratorSkipDots\FilesystemIteratorSkipDotsRectorTest |
| 21 | + * @see \Rector\Tests\Php82\Rector\New_\FilesystemIteratorSkipDotsRector\FilesystemIteratorSkipDotsRectorTest |
23 | 22 | */ |
24 | 23 | final class FilesystemIteratorSkipDotsRector extends AbstractRector implements MinPhpVersionInterface |
25 | 24 | { |
26 | 25 | /** |
27 | 26 | * @readonly |
28 | | - * @var \Rector\NodeNameResolver\NodeNameResolver\ClassConstFetchNameResolver |
| 27 | + * @var \Rector\PhpParser\Node\Value\ValueResolver |
29 | 28 | */ |
30 | | - private $classConstFetchNameResolver; |
31 | | - public function __construct(ClassConstFetchNameResolver $classConstFetchNameResolver) |
| 29 | + private $valueResolver; |
| 30 | + public function __construct(ValueResolver $valueResolver) |
32 | 31 | { |
33 | | - $this->classConstFetchNameResolver = $classConstFetchNameResolver; |
| 32 | + $this->valueResolver = $valueResolver; |
34 | 33 | } |
35 | 34 | public function getRuleDefinition() : RuleDefinition |
36 | 35 | { |
37 | | - return new RuleDefinition('Prior PHP 8.2 FilesystemIterator::SKIP_DOTS was always set and could not be removed, therefore FilesystemIterator::SKIP_DOTS is added in order to keep this behaviour.', [new CodeSample('new ' . FilesystemIterator::class . '(__DIR__, ' . FilesystemIterator::class . '::KEY_AS_FILENAME);', 'new ' . FilesystemIterator::class . '(__DIR__, ' . FilesystemIterator::class . '::KEY_AS_FILENAME | ' . FilesystemIterator::class . '::SKIP_DOTS);')]); |
| 36 | + return new RuleDefinition('Prior PHP 8.2 FilesystemIterator::SKIP_DOTS was always set and could not be removed, therefore FilesystemIterator::SKIP_DOTS is added in order to keep this behaviour.', [new CodeSample('new FilesystemIterator(__DIR__, FilesystemIterator::KEY_AS_FILENAME);', 'new FilesystemIterator(__DIR__, FilesystemIterator::KEY_AS_FILENAME | FilesystemIterator::SKIP_DOTS);')]); |
38 | 37 | } |
39 | 38 | public function getNodeTypes() : array |
40 | 39 | { |
@@ -90,6 +89,10 @@ private function isSkipDots(Expr $expr) : bool |
90 | 89 | // can be anything |
91 | 90 | return \true; |
92 | 91 | } |
93 | | - return $this->classConstFetchNameResolver->resolve($expr, null) === 'FilesystemIterator::SKIP_DOTS'; |
| 92 | + if (!\defined('FilesystemIterator::SKIP_DOTS')) { |
| 93 | + return \true; |
| 94 | + } |
| 95 | + $value = \constant('FilesystemIterator::SKIP_DOTS'); |
| 96 | + return $this->valueResolver->isValue($expr, $value); |
94 | 97 | } |
95 | 98 | } |
0 commit comments