diff --git a/composer.json b/composer.json index da8d1e8..b929f32 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ "require": { "php": ">=7.4", "illuminate/support": "^8.83 || ^9.0 || ^10.0 || ^11.0 || ^12.0 || ^13.0", - "rector/rector": "^2.3", + "rector/rector": "^2.4.1", "symfony/polyfill-php80": "^1.33", "symfony/polyfill-php81": "^1.33", "webmozart/assert": "^1.12 || ^2.0" diff --git a/rector.dist.php b/rector.dist.php index 2a333da..6b4ecf7 100644 --- a/rector.dist.php +++ b/rector.dist.php @@ -48,7 +48,6 @@ use Rector\Set\ValueObject\SetList; use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector; use Rector\Transform\Rector\String_\StringToClassConstantRector; -use Rector\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector; use Rector\ValueObject\PhpVersion; return RectorConfig::configure() @@ -120,7 +119,6 @@ EnumCaseToPascalCaseRector::class, GeneratorPropertyFetchToMethodCallRector::class, JsonThrowOnErrorRector::class, - SafeDeclareStrictTypesRector::class, SortAssociativeArrayByKeyRector::class, StaticArrowFunctionRector::class, StaticClosureRector::class, diff --git a/src/Exception/RectorErrorException.php b/src/Exception/RectorErrorException.php index c661d96..cd7e023 100644 --- a/src/Exception/RectorErrorException.php +++ b/src/Exception/RectorErrorException.php @@ -21,8 +21,6 @@ /** * @see \PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException - * - * @property \Rector\ValueObject\Application\File $file */ final class RectorErrorException extends Error implements ThrowableContract { @@ -35,7 +33,7 @@ public function __construct(AbstractRector $rector, string $message, array $attr \sprintf( '[%s:%s%s] %s', (new \ReflectionObject($rector))->getShortName(), - (string) Str::of((fn (): string => $this->file->getFilePath())->bindTo($rector, $rector)()) + (string) Str::of((fn (): string => $this->getFile()->getFilePath())->bindTo($rector, $rector)()) // @phpstan-ignore method.nonObject // ->chopStart(getcwd().\DIRECTORY_SEPARATOR) // ->replaceStart(getcwd().\DIRECTORY_SEPARATOR, '') ->whenStartsWith( diff --git a/src/Rector/File/AddNoinspectionDocblockToFileFirstStmtRector.php b/src/Rector/File/AddNoinspectionDocblockToFileFirstStmtRector.php index 9df3bb8..345dd75 100644 --- a/src/Rector/File/AddNoinspectionDocblockToFileFirstStmtRector.php +++ b/src/Rector/File/AddNoinspectionDocblockToFileFirstStmtRector.php @@ -157,8 +157,8 @@ private function getInspections(): array /** @var array> $inspectionsMap */ static $inspectionsMap = []; - $inspectionsMap[$this->file->getFilePath()] ??= collect($this->inspectionsMap) - ->filter(fn (array $_, string $path) => Str::is($path, $this->file->getFilePath())) + $inspectionsMap[$this->getFile()->getFilePath()] ??= collect($this->inspectionsMap) + ->filter(fn (array $_, string $path) => Str::is($path, $this->getFile()->getFilePath())) // ->flatten() ->collapse() ->unique() @@ -167,6 +167,6 @@ private function getInspections(): array // ->dd() ->all(); - return $inspectionsMap[$this->file->getFilePath()]; + return $inspectionsMap[$this->getFile()->getFilePath()]; } } diff --git a/src/Rector/File/SortFileFunctionStmtRector.php b/src/Rector/File/SortFileFunctionStmtRector.php index 135866b..37ed1a2 100644 --- a/src/Rector/File/SortFileFunctionStmtRector.php +++ b/src/Rector/File/SortFileFunctionStmtRector.php @@ -57,23 +57,23 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - $rootNode = collect($node->stmts)->first( + $stmt = collect($node->stmts)->first( static fn (Stmt $stmtNode): bool => $stmtNode instanceof Namespace_, $node ); - \assert($rootNode instanceof FileNode || $rootNode instanceof Namespace_); + \assert($stmt instanceof FileNode || $stmt instanceof Namespace_); if ( - collect($rootNode->stmts)->containsStrict( + collect($stmt->stmts)->containsStrict( static fn (Stmt $stmtNode): bool => $stmtNode instanceof ClassLike ) - || !collect($rootNode->stmts)->containsStrict( + || !collect($stmt->stmts)->containsStrict( static fn (Stmt $stmtNode): bool => $stmtNode instanceof Function_ || $stmtNode instanceof If_ ) - || !collect($rootNode->stmts)->containsStrict( + || !collect($stmt->stmts)->containsStrict( fn (Stmt $stmtNode): ?string => $this->parseFuncName($stmtNode) ) - || collect($rootNode->stmts) + || collect($stmt->stmts) ->map(fn (Stmt $stmtNode): ?string => $this->parseFuncName($stmtNode)) ->filter() ->pipe(static fn (Collection $funcNames): bool => $funcNames->all() === $funcNames->sort()->all()) @@ -82,7 +82,7 @@ public function refactor(Node $node): ?Node } /** @var list $sortedStmts */ - $sortedStmts = collect($rootNode->stmts) + $sortedStmts = collect($stmt->stmts) ->sort( fn (Stmt $a, Stmt $b): int => ($aName = $this->parseFuncName($a)) && ($bName = $this->parseFuncName($b)) ? $aName <=> $bName @@ -107,7 +107,7 @@ static function (Collection $stmtNodes, Stmt $stmtNode): Collection { // return null; // } - $rootNode->stmts = $sortedStmts; + $stmt->stmts = $sortedStmts; return $node; }