From 44674a8099664fa09e2b00afddb88b72a71fbd31 Mon Sep 17 00:00:00 2001 From: Geni Jaho Date: Thu, 12 Dec 2024 15:00:04 +0100 Subject: [PATCH] Rector 2.0 (#277) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * PHPStan & Rector 2.0 support (#271) * Update rector dependency to 2.0.0-rc1 (#273) * Update rector to 2.0.0.rc2 * Simplify composer scripts * Fix downgrade scripts * Add MigrateToSimplifiedAttributeRector to Laravel 9 set (#275) * Update Duster and use latest Pint configuration (#276) * Update Duster * Remove pint.json and run Duster * Refactor into our own AbstractRector that implements DocumentedRuleInterface * Update to Rector 2.0 --------- Co-authored-by: Michael Wikberg <130439907+mwikberg-virta@users.noreply.github.com> Co-authored-by: Abdul Malik Ikhsan Co-authored-by: M ɑ k s <90793591+maks-oleksyuk@users.noreply.github.com> --- .github/workflows/downgraded_release.yaml | 4 +- build/composer-php-72.json | 2 +- build/rector-downgrade-php-72.php | 5 +- composer.json | 23 ++++----- config/config.php | 3 +- config/sets/laravel90.php | 4 ++ phpstan.neon | 8 +-- pint.json | 6 --- src/AbstractRector.php | 8 +++ .../LumenRouteRegisteringMethodAnalyzer.php | 3 +- src/NodeAnalyzer/StaticCallAnalyzer.php | 3 +- src/NodeFactory/AppAssignFactory.php | 3 +- src/NodeFactory/ModelFactoryNodeFactory.php | 3 +- .../RouterRegisterNodeAnalyzer.php | 3 +- .../EnvVariableToEnvHelperRector.php | 2 +- .../RequestVariablesToRequestFacadeRector.php | 2 +- ...AppArrayAccessToStandaloneAssignRector.php | 5 +- ...abaseExpressionCastsToMethodCallRector.php | 2 +- .../AddArgumentDefaultValueRector.php | 2 +- .../AddGenericReturnTypeToRelationsRector.php | 42 +++++----------- .../AddParentBootToModelClassMethodRector.php | 5 +- ...ntRegisterToEventServiceProviderRector.php | 5 +- .../MigrateToSimplifiedAttributeRector.php | 24 ++++----- ...xtendsAnnotationToModelFactoriesRector.php | 5 +- ...ConsoleOutputFalseToConsoleTestsRector.php | 5 +- .../Class_/AnonymousMigrationsRector.php | 5 +- .../CashierStripeOptionsToStripeRector.php | 9 ++-- ...omputedMethodToComputedAttributeRector.php | 7 +-- ...mponentQueryStringToUrlAttributeRector.php | 15 +++--- .../ModelCastsPropertyToCastsMethodRector.php | 8 +-- ...pertyDeferToDeferrableProviderToRector.php | 5 +- ...RemoveModelPropertyFromFactoriesRector.php | 2 +- .../ReplaceExpectsMethodsInTestsRector.php | 4 +- .../Class_/UnifyModelDatesWithCastsRector.php | 7 ++- ...pplyDefaultInsteadOfNullCoalesceRector.php | 16 ++++-- .../EmptyToBlankAndFilledFuncRector.php | 2 +- ...EnvironmentComparisonToParameterRector.php | 2 +- ...tsWithOrEndsWithStaticMethodCallRector.php | 8 ++- .../ArgumentFuncCallToMethodCallRector.php | 5 +- ...atchNonShouldQueueToDispatchSyncRector.php | 21 ++++---- .../FactoryFuncCallToStaticCallRector.php | 2 +- .../HelperFuncCallToFacadeClassRector.php | 2 +- ...ankFuncCallToBlankFilledFuncCallRector.php | 2 +- ...hStartOfDayMethodCallToTodayFuncRector.php | 2 +- .../FuncCall/RemoveDumpDataDeadCodeRector.php | 9 ++-- .../RemoveRedundantValueCallsRector.php | 2 +- .../RemoveRedundantWithCallsRector.php | 2 +- .../SleepFuncToSleepStaticCallRector.php | 2 +- ...UnlessExceptionsToUseClassStringRector.php | 2 +- .../FuncCall/TypeHintTappableCallRector.php | 5 +- src/Rector/If_/AbortIfRector.php | 6 +-- src/Rector/If_/ReportIfRector.php | 6 +-- src/Rector/If_/ThrowIfRector.php | 50 +++++++++---------- .../AssertSeeToAssertSeeHtmlRector.php | 5 +- .../AssertStatusToAssertMethodRector.php | 2 +- ...dNegatedCollectionFilterOrRejectRector.php | 2 +- ...ngeQueryWhereDateValueWithCarbonRector.php | 8 +-- ...seExpressionToStringToMethodCallRector.php | 2 +- .../EloquentOrderByToLatestOrOldestRector.php | 18 ++++--- ...hereRelationTypeHintingParameterRector.php | 5 +- ...entWhereTypeHintClosureParameterRector.php | 2 +- .../FactoryApplyingStatesRector.php | 5 +- .../JsonCallToExplicitJsonCallRector.php | 2 +- ...menRoutesStringActionToUsesArrayRector.php | 7 ++- ...menRoutesStringMiddlewareToArrayRector.php | 10 ++-- .../RedirectBackToBackHelperRector.php | 2 +- .../RedirectRouteToToRouteHelperRector.php | 2 +- ...RefactorBlueprintGeometryColumnsRector.php | 2 +- .../ReplaceServiceContainerCallArgRector.php | 2 +- ...tsAndNotificationsWithFacadeFakeRector.php | 2 +- ...ResponseHelperCallToJsonResponseRector.php | 4 +- .../ReverseConditionableMethodCallRector.php | 2 +- ...eComponentPropertyWithinCommandsRector.php | 2 +- ...ationRuleArrayStringValueToArrayRector.php | 8 +-- .../Namespace_/FactoryDefinitionRector.php | 5 +- .../New_/AddGuardToLoginEventRector.php | 5 +- .../OptionalToNullsafeOperatorRector.php | 8 +-- .../ReplaceFakerInstanceWithHelperRector.php | 5 +- .../CarbonSetTestNowToTravelToRector.php | 10 ++-- .../DispatchToHelperFunctionsRector.php | 18 ++++--- ...loquentMagicMethodToQueryBuilderRector.php | 11 ++-- .../MinutesToSecondsInCacheRector.php | 6 +-- .../Redirect301ToPermanentRedirectRector.php | 2 +- ...sertTimesSendWithAssertSentTimesRector.php | 2 +- .../RequestStaticValidateToInjectRector.php | 9 ++-- .../StaticCall/RouteActionCallableRector.php | 24 ++++++--- src/Set/LaravelLevelSetList.php | 4 +- src/Set/LaravelSetList.php | 4 +- .../Packages/Cashier/CashierLevelSetList.php | 4 +- src/Set/Packages/Cashier/CashierSetList.php | 4 +- .../Livewire/LivewireLevelSetList.php | 4 +- src/ValueObject/AddArgumentDefaultValue.php | 3 +- .../ApplyDefaultInsteadOfNullCoalesce.php | 4 +- .../ReplaceServiceContainerCallArg.php | 3 +- .../ServiceNameTypeAndVariableName.php | 3 +- .../TypeToTimeMethodAndPosition.php | 3 +- stubs/Illuminate/Container/Container.php | 4 +- stubs/Illuminate/Contracts/Cache/Store.php | 4 +- .../Contracts/Container/Container.php | 4 +- .../Contracts/Events/Dispatcher.php | 4 +- .../Contracts/Queue/ShouldQueue.php | 4 +- .../Contracts/Routing/ResponseFactory.php | 4 +- .../Contracts/Support/DeferrableProvider.php | 4 +- .../Illuminate/Database/Eloquent/Builder.php | 8 +-- .../Database/Eloquent/Factories/Factory.php | 4 +- .../Database/Eloquent/Relations/BelongsTo.php | 4 +- .../Database/Eloquent/Relations/HasMany.php | 4 +- .../Eloquent/Relations/HasOneThrough.php | 4 +- .../Database/Eloquent/Relations/MorphTo.php | 4 +- .../Database/Eloquent/Relations/Relation.php | 4 +- .../Database/Migrations/Migration.php | 4 +- stubs/Illuminate/Database/Query/Builder.php | 12 ++--- .../Foundation/Bus/Dispatchable.php | 4 +- .../Foundation/Bus/DispatchesJobs.php | 4 +- .../Foundation/Bus/PendingChain.php | 4 +- .../Foundation/Events/Dispatchable.php | 16 ++---- .../Foundation/Exceptions/Handler.php | 4 +- .../Foundation/Http/FormRequest.php | 4 +- stubs/Illuminate/Foundation/Http/Kernel.php | 4 +- .../Providers/EventServiceProvider.php | 4 +- .../Testing/Concerns/MakesHttpRequests.php | 4 +- .../Foundation/Testing/TestCase.php | 4 +- stubs/Illuminate/Http/Response.php | 4 +- stubs/Illuminate/Mail/MailManager.php | 4 +- stubs/Illuminate/Mail/Mailable.php | 4 +- stubs/Illuminate/Mail/Mailer.php | 4 +- stubs/Illuminate/Mail/Message.php | 4 +- .../Notifications/Messages/MailMessage.php | 4 +- stubs/Illuminate/Routing/ResponseFactory.php | 4 +- stubs/Illuminate/Support/Collection.php | 4 +- stubs/Illuminate/Support/Facades/Route.php | 4 +- stubs/Illuminate/Support/ServiceProvider.php | 4 +- .../Support/Traits/Conditionable.php | 8 +-- stubs/Illuminate/Support/Traits/Tappable.php | 4 +- stubs/Illuminate/Testing/TestResponse.php | 4 +- stubs/Laravel/Cashier/Billable.php | 4 +- stubs/Livewire/Component.php | 4 +- .../with-constant-string-type.php.inc | 40 +++++++++++++++ .../Source/TestCase.php | 4 +- .../Source/QueueableJob.php | 4 +- .../Source/SomeJob.php | 4 +- .../Source/HelperObject.php | 4 +- .../Source/HelperObject.php | 4 +- .../Source/NonTappableExample.php | 4 +- ...onseHelperCallToJsonResponseRectorTest.php | 3 ++ .../FactoryDefinitionRector/Source/Model.php | 4 +- .../Source/SomeClass.php | 5 +- .../Source/OtherDispatchable.php | 3 +- .../Source/TestEvent.php | 3 +- .../Source/TestJob.php | 3 +- ...entMagicMethodToQueryBuilderRectorTest.php | 4 +- .../Source/SomeController.php | 5 +- tests/Sets/LaravelSetProviderTest.php | 21 +++++--- 153 files changed, 418 insertions(+), 509 deletions(-) delete mode 100644 pint.json create mode 100644 src/AbstractRector.php create mode 100644 tests/Rector/ClassMethod/AddGenericReturnTypeToRelationsRector/Fixture/NewGenerics/with-constant-string-type.php.inc diff --git a/.github/workflows/downgraded_release.yaml b/.github/workflows/downgraded_release.yaml index 9a2ce3ce..6741a4f0 100644 --- a/.github/workflows/downgraded_release.yaml +++ b/.github/workflows/downgraded_release.yaml @@ -15,12 +15,12 @@ jobs: steps: - - uses: "actions/checkout@v3" + uses: "actions/checkout@v4" - uses: "shivammathur/setup-php@v2" with: - php-version: 8.2 + php-version: 8.3 coverage: none - uses: "ramsey/composer-install@v2" diff --git a/build/composer-php-72.json b/build/composer-php-72.json index a53f0f7f..14959d7e 100644 --- a/build/composer-php-72.json +++ b/build/composer-php-72.json @@ -5,7 +5,7 @@ "description": "Rector upgrades rules for Laravel Framework", "require": { "php": "^7.2 || ^8.0", - "rector/rector": "^1.0" + "rector/rector": "^2.0" }, "autoload": { "psr-4": { diff --git a/build/rector-downgrade-php-72.php b/build/rector-downgrade-php-72.php index 5550cffe..720d593f 100644 --- a/build/rector-downgrade-php-72.php +++ b/build/rector-downgrade-php-72.php @@ -3,8 +3,5 @@ declare(strict_types=1); use Rector\Config\RectorConfig; -use Rector\Set\ValueObject\DowngradeLevelSetList; -return static function (RectorConfig $rectorConfig): void { - $rectorConfig->sets([DowngradeLevelSetList::DOWN_TO_PHP_72]); -}; +return RectorConfig::configure()->withDowngradeSets(php72: true); diff --git a/composer.json b/composer.json index a0688221..18b40c31 100644 --- a/composer.json +++ b/composer.json @@ -5,19 +5,20 @@ "description": "Rector upgrades rules for Laravel Framework", "require": { "php": ">=8.2", - "rector/rector": "^1.2.5" + "rector/rector": "^2.0.0", + "webmozart/assert": "^1.11", + "symplify/rule-doc-generator-contracts": "^11.2" }, "require-dev": { - "nikic/php-parser": "^4.18", + "nikic/php-parser": "^5.3", "phpstan/extension-installer": "^1.3", - "phpstan/phpstan": "^1.10", - "phpstan/phpstan-strict-rules": "^1.5", - "phpstan/phpstan-webmozart-assert": "^1.2", + "phpstan/phpstan": "^2.0", + "phpstan/phpstan-deprecation-rules": "^2.0", + "phpstan/phpstan-strict-rules": "^2.0", + "phpstan/phpstan-webmozart-assert": "^2.0", "phpunit/phpunit": "^10.5", - "symplify/phpstan-extensions": "^11.4", - "symplify/phpstan-rules": "^12.4", - "symplify/rule-doc-generator": "^12.1", - "tightenco/duster": "^2.7" + "symplify/rule-doc-generator": "^12.2", + "tightenco/duster": "^3.1" }, "autoload": { "psr-4": { @@ -31,9 +32,7 @@ "classmap": ["stubs"] }, "scripts": { - "phpstan": "vendor/bin/phpstan analyse --ansi --error-format symplify", - "check-cs": "vendor/bin/duster lint", - "fix-cs": "vendor/bin/duster fix", + "phpstan": "vendor/bin/phpstan analyse --ansi", "lint": "vendor/bin/duster lint", "fix": "vendor/bin/duster fix", "rector-dry-run": "vendor/bin/rector process --dry-run --ansi", diff --git a/config/config.php b/config/config.php index 74a42ef4..b58ec265 100644 --- a/config/config.php +++ b/config/config.php @@ -4,5 +4,4 @@ use Rector\Config\RectorConfig; -return static function (RectorConfig $rectorConfig): void { -}; +return static function (RectorConfig $rectorConfig): void {}; diff --git a/config/sets/laravel90.php b/config/sets/laravel90.php index 6c825fe7..2e0f8ae0 100644 --- a/config/sets/laravel90.php +++ b/config/sets/laravel90.php @@ -12,6 +12,7 @@ use Rector\Visibility\Rector\ClassMethod\ChangeMethodVisibilityRector; use Rector\Visibility\ValueObject\ChangeMethodVisibility; use RectorLaravel\Rector\Class_\AddExtendsAnnotationToModelFactoriesRector; +use RectorLaravel\Rector\ClassMethod\MigrateToSimplifiedAttributeRector; use RectorLaravel\Rector\PropertyFetch\ReplaceFakerInstanceWithHelperRector; // see https://laravel.com/docs/9.x/upgrade @@ -106,4 +107,7 @@ // https://github.com/laravel/framework/commit/9894c2c64dc70f7dfda2ac46dfdaa8769ce4596a new MethodCallRename('Illuminate\Testing\TestResponse', 'assertDeleted', 'assertModelMissing'), ]); + + // https://github.com/laravel/framework/commit/e0c2620b57be6416820ea7ca8e46fd2f71d2fe35 + $rectorConfig->rule(MigrateToSimplifiedAttributeRector::class); }; diff --git a/phpstan.neon b/phpstan.neon index f84cf6d3..655a811f 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,3 @@ -includes: - - vendor/symplify/phpstan-rules/config/rector-rules.neon parameters: level: max @@ -15,7 +13,7 @@ parameters: - */Source/* - *Source/* -# reportUnmatchedIgnoredErrors: false + treatPhpDocTypesAsCertain: false ignoreErrors: # false positive @@ -32,3 +30,7 @@ parameters: # Laravel Container not being recognized properly in some of the tests - '#Call to method needs\(\) on an unknown class Illuminate\\Contracts\\Container\\ContextualBindingBuilder#' + - '#Cannot call method give\(\) on mixed.#' + + # No easy replacement for this check, it's also ignored in core Rector + - '#Doing instanceof PHPStan\\Type\\Generic\\GenericObjectType is error\-prone and deprecated#' diff --git a/pint.json b/pint.json deleted file mode 100644 index a5ba00f7..00000000 --- a/pint.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "rules": { - "single_line_empty_body": false, - "concat_space": false - } -} diff --git a/src/AbstractRector.php b/src/AbstractRector.php new file mode 100644 index 00000000..6819f079 --- /dev/null +++ b/src/AbstractRector.php @@ -0,0 +1,8 @@ +|null */ - public function refactor(Node $node): Node|array|int|null + public function refactor(Node $node): ?array { if (! $node->expr instanceof Assign) { return null; diff --git a/src/Rector/Cast/DatabaseExpressionCastsToMethodCallRector.php b/src/Rector/Cast/DatabaseExpressionCastsToMethodCallRector.php index 5708e74c..29a99d9a 100644 --- a/src/Rector/Cast/DatabaseExpressionCastsToMethodCallRector.php +++ b/src/Rector/Cast/DatabaseExpressionCastsToMethodCallRector.php @@ -7,7 +7,7 @@ use PhpParser\Node; use PhpParser\Node\Expr\Cast\String_; use PhpParser\Node\Expr\StaticCall; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/ClassMethod/AddArgumentDefaultValueRector.php b/src/Rector/ClassMethod/AddArgumentDefaultValueRector.php index 8a3f88ae..748c2c0e 100644 --- a/src/Rector/ClassMethod/AddArgumentDefaultValueRector.php +++ b/src/Rector/ClassMethod/AddArgumentDefaultValueRector.php @@ -10,7 +10,7 @@ use PhpParser\Node\Param; use PhpParser\Node\Stmt\ClassLike; use Rector\Contract\Rector\ConfigurableRectorInterface; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use RectorLaravel\ValueObject\AddArgumentDefaultValue; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/ClassMethod/AddGenericReturnTypeToRelationsRector.php b/src/Rector/ClassMethod/AddGenericReturnTypeToRelationsRector.php index 92a5c43f..75acb18b 100644 --- a/src/Rector/ClassMethod/AddGenericReturnTypeToRelationsRector.php +++ b/src/Rector/ClassMethod/AddGenericReturnTypeToRelationsRector.php @@ -14,8 +14,6 @@ use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode; use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; use PHPStan\Reflection\ClassReflection; -use PHPStan\Type\Constant\ConstantStringType; -use PHPStan\Type\Generic\GenericClassStringType; use PHPStan\Type\Generic\GenericObjectType; use PHPStan\Type\ObjectType; use PHPStan\Type\ThisType; @@ -24,8 +22,9 @@ use Rector\Comments\NodeDocBlock\DocBlockUpdater; use Rector\NodeTypeResolver\TypeComparator\TypeComparator; use Rector\PhpParser\Node\BetterNodeFinder; -use Rector\Rector\AbstractScopeAwareRector; +use Rector\PHPStan\ScopeFetcher; use Rector\StaticTypeMapper\StaticTypeMapper; +use RectorLaravel\AbstractRector; use ReflectionClassConstant; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -34,7 +33,7 @@ * @see \RectorLaravel\Tests\Rector\ClassMethod\AddGenericReturnTypeToRelationsRector\AddGenericReturnTypeToRelationsRectorNewGenericsTest * @see \RectorLaravel\Tests\Rector\ClassMethod\AddGenericReturnTypeToRelationsRector\AddGenericReturnTypeToRelationsRectorOldGenericsTest */ -class AddGenericReturnTypeToRelationsRector extends AbstractScopeAwareRector +class AddGenericReturnTypeToRelationsRector extends AbstractRector { // Relation methods which are supported by this Rector. private const RELATION_METHODS = [ @@ -59,8 +58,7 @@ public function __construct( private readonly BetterNodeFinder $betterNodeFinder, private readonly StaticTypeMapper $staticTypeMapper, private readonly string $applicationClass = 'Illuminate\Foundation\Application', - ) { - } + ) {} public function getRuleDefinition(): RuleDefinition { @@ -141,12 +139,14 @@ public function getNodeTypes(): array return [ClassMethod::class]; } - public function refactorWithScope(Node $node, Scope $scope): ?Node + public function refactor(Node $node): ?Node { if (! $node instanceof ClassMethod) { return null; } + $scope = ScopeFetcher::fetch($node); + if ($this->shouldSkipNode($node, $scope)) { return null; } @@ -239,21 +239,13 @@ private function getRelatedModelClassFromMethodCall(MethodCall $methodCall): ?st { $argType = $this->getType($methodCall->getArgs()[0]->value); - if ($argType instanceof ConstantStringType && $argType->isClassStringType()->yes()) { - return $argType->getValue(); - } - - if (! $argType instanceof GenericClassStringType) { - return null; - } - - $modelType = $argType->getGenericType(); + $objectClassNames = $argType->getClassStringObjectType()->getObjectClassNames(); - if (! $modelType instanceof ObjectType) { + if ($objectClassNames === []) { return null; } - return $modelType->getClassName(); + return $objectClassNames[0]; } private function getRelationMethodCall(ClassMethod $classMethod): ?MethodCall @@ -326,21 +318,13 @@ private function getClassForIntermediateGeneric(MethodCall $methodCall): ?string $argType = $this->getType($args[1]->value); - if ($argType instanceof ConstantStringType && $argType->isClassStringType()->yes()) { - return $argType->getValue(); - } - - if (! $argType instanceof GenericClassStringType) { - return null; - } - - $modelType = $argType->getGenericType(); + $objectClassNames = $argType->getClassStringObjectType()->getObjectClassNames(); - if (! $modelType instanceof ObjectType) { + if ($objectClassNames === []) { return null; } - return $modelType->getClassName(); + return $objectClassNames[0]; } private function areNativeTypeAndPhpDocReturnTypeEqual( diff --git a/src/Rector/ClassMethod/AddParentBootToModelClassMethodRector.php b/src/Rector/ClassMethod/AddParentBootToModelClassMethodRector.php index 92e93fc0..13a3a3bc 100644 --- a/src/Rector/ClassMethod/AddParentBootToModelClassMethodRector.php +++ b/src/Rector/ClassMethod/AddParentBootToModelClassMethodRector.php @@ -8,8 +8,8 @@ use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Expression; use PHPStan\Reflection\ClassReflection; -use Rector\Rector\AbstractRector; use Rector\Reflection\ReflectionResolver; +use RectorLaravel\AbstractRector; use RectorLaravel\NodeAnalyzer\StaticCallAnalyzer; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -29,8 +29,7 @@ final class AddParentBootToModelClassMethodRector extends AbstractRector public function __construct( private readonly StaticCallAnalyzer $staticCallAnalyzer, private readonly ReflectionResolver $reflectionResolver, - ) { - } + ) {} public function getRuleDefinition(): RuleDefinition { diff --git a/src/Rector/ClassMethod/AddParentRegisterToEventServiceProviderRector.php b/src/Rector/ClassMethod/AddParentRegisterToEventServiceProviderRector.php index 01e75d8f..eaba34ee 100644 --- a/src/Rector/ClassMethod/AddParentRegisterToEventServiceProviderRector.php +++ b/src/Rector/ClassMethod/AddParentRegisterToEventServiceProviderRector.php @@ -8,8 +8,8 @@ use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Expression; use PHPStan\Reflection\ClassReflection; -use Rector\Rector\AbstractRector; use Rector\Reflection\ReflectionResolver; +use RectorLaravel\AbstractRector; use RectorLaravel\NodeAnalyzer\StaticCallAnalyzer; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -29,8 +29,7 @@ final class AddParentRegisterToEventServiceProviderRector extends AbstractRector public function __construct( private readonly StaticCallAnalyzer $staticCallAnalyzer, private readonly ReflectionResolver $reflectionResolver, - ) { - } + ) {} public function getRuleDefinition(): RuleDefinition { diff --git a/src/Rector/ClassMethod/MigrateToSimplifiedAttributeRector.php b/src/Rector/ClassMethod/MigrateToSimplifiedAttributeRector.php index dee11b1a..d83cdb23 100644 --- a/src/Rector/ClassMethod/MigrateToSimplifiedAttributeRector.php +++ b/src/Rector/ClassMethod/MigrateToSimplifiedAttributeRector.php @@ -5,11 +5,12 @@ namespace RectorLaravel\Rector\ClassMethod; use PhpParser\Comment\Doc; +use PhpParser\Modifiers; use PhpParser\Node; use PhpParser\Node\Arg; +use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\ArrayDimFetch; -use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\PropertyFetch; @@ -21,10 +22,10 @@ use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\Return_; -use PhpParser\NodeTraverser; +use PhpParser\NodeVisitor; use PHPStan\Type\ObjectType; use Rector\PhpParser\Node\BetterNodeFinder; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -33,8 +34,7 @@ final class MigrateToSimplifiedAttributeRector extends AbstractRector { public function __construct( private readonly BetterNodeFinder $betterNodeFinder - ) { - } + ) {} /** * @return array> @@ -47,7 +47,7 @@ public function getNodeTypes(): array /** * @param Class_ $node */ - public function refactor(Node $node): Node|array|int|null + public function refactor(Node $node): ?Node { if (! $this->isObjectType($node, new ObjectType('Illuminate\Database\Eloquent\Model'))) { return null; @@ -68,7 +68,7 @@ public function refactor(Node $node): Node|array|int|null if ($newNode instanceof ClassMethod) { $node->stmts[$key] = $newNode; - } elseif ($newNode === NodeTraverser::REMOVE_NODE) { + } elseif ($newNode === NodeVisitor::REMOVE_NODE) { unset($node->stmts[$key]); } } @@ -154,7 +154,7 @@ private function refactorClassMethod(ClassMethod $classMethod, array $allClassMe // is placed on the model and remove the mutator, // so we don't run the refactoring twice if ($accessor instanceof ClassMethod && $mutator instanceof ClassMethod && $this->isMutator($nodeName)) { - return NodeTraverser::REMOVE_NODE; + return NodeVisitor::REMOVE_NODE; } if ($accessor instanceof ClassMethod && $mutator instanceof ClassMethod) { @@ -194,7 +194,7 @@ private function createAccessorAndMutator( ): ClassMethod { return new ClassMethod(new Identifier($attributeName), [ 'attrGroups' => [], - 'flags' => Class_::MODIFIER_PROTECTED, + 'flags' => Modifiers::PROTECTED, 'params' => [], 'returnType' => new FullyQualified('Illuminate\\Database\\Eloquent\\Casts\\Attribute'), 'stmts' => [ @@ -206,7 +206,7 @@ private function createAccessorAndMutator( new Arg( new Closure([ 'params' => $accessor->params, - 'stmts' => $accessor->stmts, + 'stmts' => $accessor->stmts ?? [], ]), false, false, @@ -241,7 +241,7 @@ private function createAttributeClassMethod( ): ClassMethod { return new ClassMethod(new Identifier($attributeName), [ 'attrGroups' => $classMethod->attrGroups, - 'flags' => Class_::MODIFIER_PROTECTED, + 'flags' => Modifiers::PROTECTED, 'params' => [], 'returnType' => new FullyQualified('Illuminate\\Database\\Eloquent\\Casts\\Attribute'), 'stmts' => [ @@ -253,7 +253,7 @@ private function createAttributeClassMethod( new Arg( new Closure([ 'params' => $classMethod->params, - 'stmts' => $statements, + 'stmts' => $statements ?? [], ]), false, false, diff --git a/src/Rector/Class_/AddExtendsAnnotationToModelFactoriesRector.php b/src/Rector/Class_/AddExtendsAnnotationToModelFactoriesRector.php index df12fd9d..e45fd2e6 100644 --- a/src/Rector/Class_/AddExtendsAnnotationToModelFactoriesRector.php +++ b/src/Rector/Class_/AddExtendsAnnotationToModelFactoriesRector.php @@ -17,7 +17,7 @@ use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\BetterPhpDocParser\ValueObject\Type\FullyQualifiedIdentifierTypeNode; use Rector\Comments\NodeDocBlock\DocBlockUpdater; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -35,8 +35,7 @@ final class AddExtendsAnnotationToModelFactoriesRector extends AbstractRector public function __construct( private readonly DocBlockUpdater $docBlockUpdater, private readonly PhpDocInfoFactory $phpDocInfoFactory, - ) { - } + ) {} public function getRuleDefinition(): RuleDefinition { diff --git a/src/Rector/Class_/AddMockConsoleOutputFalseToConsoleTestsRector.php b/src/Rector/Class_/AddMockConsoleOutputFalseToConsoleTestsRector.php index 21a9d932..3bf3106f 100644 --- a/src/Rector/Class_/AddMockConsoleOutputFalseToConsoleTestsRector.php +++ b/src/Rector/Class_/AddMockConsoleOutputFalseToConsoleTestsRector.php @@ -20,8 +20,8 @@ use Rector\PhpParser\Node\Value\ValueResolver; use Rector\PHPUnit\NodeAnalyzer\SetUpMethodDecorator; use Rector\Privatization\NodeManipulator\VisibilityManipulator; -use Rector\Rector\AbstractRector; use Rector\ValueObject\MethodName; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -39,8 +39,7 @@ public function __construct( private readonly VisibilityManipulator $visibilityManipulator, private readonly BetterNodeFinder $betterNodeFinder, private readonly ValueResolver $valueResolver, - ) { - } + ) {} public function getRuleDefinition(): RuleDefinition { diff --git a/src/Rector/Class_/AnonymousMigrationsRector.php b/src/Rector/Class_/AnonymousMigrationsRector.php index 9e47fb6a..8716c3b8 100644 --- a/src/Rector/Class_/AnonymousMigrationsRector.php +++ b/src/Rector/Class_/AnonymousMigrationsRector.php @@ -10,7 +10,7 @@ use PhpParser\Node\Stmt\Return_; use PHPStan\Type\ObjectType; use Rector\NodeAnalyzer\ClassAnalyzer; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -24,8 +24,7 @@ final class AnonymousMigrationsRector extends AbstractRector { public function __construct( private readonly ClassAnalyzer $classAnalyzer - ) { - } + ) {} public function getRuleDefinition(): RuleDefinition { diff --git a/src/Rector/Class_/CashierStripeOptionsToStripeRector.php b/src/Rector/Class_/CashierStripeOptionsToStripeRector.php index cea4cb35..465a9bc1 100644 --- a/src/Rector/Class_/CashierStripeOptionsToStripeRector.php +++ b/src/Rector/Class_/CashierStripeOptionsToStripeRector.php @@ -11,7 +11,8 @@ use PHPStan\Analyser\Scope; use PHPStan\Reflection\ClassReflection; use PHPStan\Type\ObjectType; -use Rector\Rector\AbstractScopeAwareRector; +use Rector\PHPStan\ScopeFetcher; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -20,7 +21,7 @@ * * @see \RectorLaravel\Tests\Rector\Class_\CashierStripeOptionsToStripeRector\CashierStripeOptionsToStripeRectorTest */ -final class CashierStripeOptionsToStripeRector extends AbstractScopeAwareRector +final class CashierStripeOptionsToStripeRector extends AbstractRector { public function getRuleDefinition(): RuleDefinition { @@ -66,12 +67,14 @@ public function getNodeTypes(): array return [Class_::class]; } - public function refactorWithScope(Node $node, Scope $scope): ?Node + public function refactor(Node $node): ?Node { if (! $this->isObjectType($node, new ObjectType('Illuminate\Database\Eloquent\Model'))) { return null; } + $scope = ScopeFetcher::fetch($node); + if (! $this->usesBillableTrait($scope)) { return null; } diff --git a/src/Rector/Class_/LivewireComponentComputedMethodToComputedAttributeRector.php b/src/Rector/Class_/LivewireComponentComputedMethodToComputedAttributeRector.php index 231812bc..894e8303 100644 --- a/src/Rector/Class_/LivewireComponentComputedMethodToComputedAttributeRector.php +++ b/src/Rector/Class_/LivewireComponentComputedMethodToComputedAttributeRector.php @@ -11,7 +11,7 @@ use PhpParser\Node\Stmt\ClassMethod; use PHPStan\Type\ObjectType; use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -26,10 +26,7 @@ final class LivewireComponentComputedMethodToComputedAttributeRector extends Abs private const METHOD_PATTERN = '/^get(?\'methodName\'[\w]*)Property$/'; - public function __construct(private readonly PhpAttributeAnalyzer $phpAttributeAnalyzer) - { - - } + public function __construct(private readonly PhpAttributeAnalyzer $phpAttributeAnalyzer) {} public function getRuleDefinition(): RuleDefinition { diff --git a/src/Rector/Class_/LivewireComponentQueryStringToUrlAttributeRector.php b/src/Rector/Class_/LivewireComponentQueryStringToUrlAttributeRector.php index 03f9a786..a9b2f502 100644 --- a/src/Rector/Class_/LivewireComponentQueryStringToUrlAttributeRector.php +++ b/src/Rector/Class_/LivewireComponentQueryStringToUrlAttributeRector.php @@ -4,10 +4,10 @@ use PhpParser\Node; use PhpParser\Node\Arg; +use PhpParser\Node\ArrayItem; use PhpParser\Node\Attribute; use PhpParser\Node\AttributeGroup; use PhpParser\Node\Expr\Array_; -use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Identifier; use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Scalar; @@ -16,7 +16,7 @@ use PhpParser\Node\Stmt\Property; use PHPStan\Type\ObjectType; use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -31,10 +31,7 @@ final class LivewireComponentQueryStringToUrlAttributeRector extends AbstractRec private const QUERY_STRING_PROPERTY_NAME = 'queryString'; - public function __construct(private readonly PhpAttributeAnalyzer $phpAttributeAnalyzer) - { - - } + public function __construct(private readonly PhpAttributeAnalyzer $phpAttributeAnalyzer) {} public function getRuleDefinition(): RuleDefinition { @@ -126,7 +123,7 @@ public function refactor(Node $node): ?Class_ } /** - * @return array|null + * @return array>|null */ private function findQueryStringProperties(Property $property): ?array { @@ -181,7 +178,7 @@ private function findQueryStringProperties(Property $property): ?array } /** - * @param Node\Arg[] $args + * @param list $args */ private function addUrlAttributeToProperty(Property $property, array $args): void { @@ -197,7 +194,7 @@ private function addUrlAttributeToProperty(Property $property, array $args): voi } /** - * @return Node\Arg[]|null + * @return list|null */ private function processArrayOptionsIntoArgs(Array_ $array): ?array { diff --git a/src/Rector/Class_/ModelCastsPropertyToCastsMethodRector.php b/src/Rector/Class_/ModelCastsPropertyToCastsMethodRector.php index e531974e..eae705ca 100644 --- a/src/Rector/Class_/ModelCastsPropertyToCastsMethodRector.php +++ b/src/Rector/Class_/ModelCastsPropertyToCastsMethodRector.php @@ -3,6 +3,7 @@ namespace RectorLaravel\Rector\Class_; use PhpParser\BuilderFactory; +use PhpParser\Comment\Doc; use PhpParser\Node; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; @@ -13,7 +14,7 @@ use PHPStan\Type\ObjectType; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\Comments\NodeDocBlock\DocBlockUpdater; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -26,8 +27,7 @@ public function __construct( protected BuilderFactory $builderFactory, protected PhpDocInfoFactory $phpDocInfoFactory, protected DocBlockUpdater $docBlockUpdater, - ) { - } + ) {} public function getRuleDefinition(): RuleDefinition { @@ -90,7 +90,7 @@ public function refactor(Node $node): ?Class_ ->setReturnType('array') ->makeProtected(); - if ($stmt->getDocComment() !== null) { + if ($stmt->getDocComment() instanceof Doc) { $method->setDocComment($stmt->getDocComment()); } diff --git a/src/Rector/Class_/PropertyDeferToDeferrableProviderToRector.php b/src/Rector/Class_/PropertyDeferToDeferrableProviderToRector.php index ce320866..d34d7c47 100644 --- a/src/Rector/Class_/PropertyDeferToDeferrableProviderToRector.php +++ b/src/Rector/Class_/PropertyDeferToDeferrableProviderToRector.php @@ -11,7 +11,7 @@ use PhpParser\Node\Stmt\Property; use PHPStan\Type\ObjectType; use Rector\PhpParser\Node\Value\ValueResolver; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -24,8 +24,7 @@ final class PropertyDeferToDeferrableProviderToRector extends AbstractRector { public function __construct( private readonly ValueResolver $valueResolver, - ) { - } + ) {} public function getRuleDefinition(): RuleDefinition { diff --git a/src/Rector/Class_/RemoveModelPropertyFromFactoriesRector.php b/src/Rector/Class_/RemoveModelPropertyFromFactoriesRector.php index 89f50929..4822cff2 100644 --- a/src/Rector/Class_/RemoveModelPropertyFromFactoriesRector.php +++ b/src/Rector/Class_/RemoveModelPropertyFromFactoriesRector.php @@ -8,7 +8,7 @@ use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\Property; use PHPStan\Type\ObjectType; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/Class_/ReplaceExpectsMethodsInTestsRector.php b/src/Rector/Class_/ReplaceExpectsMethodsInTestsRector.php index d9cf3a97..52245a34 100644 --- a/src/Rector/Class_/ReplaceExpectsMethodsInTestsRector.php +++ b/src/Rector/Class_/ReplaceExpectsMethodsInTestsRector.php @@ -6,8 +6,8 @@ use PhpParser\Node; use PhpParser\Node\Arg; +use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr\Array_; -use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; @@ -18,7 +18,7 @@ use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\Expression; use PHPStan\Type\ObjectType; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/Class_/UnifyModelDatesWithCastsRector.php b/src/Rector/Class_/UnifyModelDatesWithCastsRector.php index 2cbda521..c8db04e6 100644 --- a/src/Rector/Class_/UnifyModelDatesWithCastsRector.php +++ b/src/Rector/Class_/UnifyModelDatesWithCastsRector.php @@ -6,8 +6,8 @@ use PhpParser\Builder\Property as PropertyBuilder; use PhpParser\Node; +use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr\Array_; -use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\Property; @@ -15,7 +15,7 @@ use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\NodeManipulator\ClassInsertManipulator; use Rector\PhpParser\Node\Value\ValueResolver; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; use Webmozart\Assert\Assert; @@ -31,8 +31,7 @@ public function __construct( private readonly ClassInsertManipulator $classInsertManipulator, private readonly ValueResolver $valueResolver, private readonly PhpDocInfoFactory $phpDocInfoFactory, - ) { - } + ) {} public function getRuleDefinition(): RuleDefinition { diff --git a/src/Rector/Coalesce/ApplyDefaultInsteadOfNullCoalesceRector.php b/src/Rector/Coalesce/ApplyDefaultInsteadOfNullCoalesceRector.php index 6167dc31..58d90f69 100644 --- a/src/Rector/Coalesce/ApplyDefaultInsteadOfNullCoalesceRector.php +++ b/src/Rector/Coalesce/ApplyDefaultInsteadOfNullCoalesceRector.php @@ -10,7 +10,7 @@ use PhpParser\Node\Expr\StaticCall; use PHPStan\Type\ObjectType; use Rector\Contract\Rector\ConfigurableRectorInterface; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use RectorLaravel\ValueObject\ApplyDefaultInsteadOfNullCoalesce; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -90,14 +90,20 @@ public function refactor(Node $node): MethodCall|StaticCall|FuncCall|null $call = $node->left; + if ($call instanceof MethodCall) { + $objectType = $call->var; + } elseif ($call instanceof StaticCall) { + $objectType = $call->class; + } else { + $objectType = null; + } + foreach ($this->applyDefaultWith as $applyDefaultWith) { $valid = false; - $objectType = $call->var ?? $call->class ?? null; - if ( - $applyDefaultWith->getObjectType() instanceof ObjectType && - $objectType !== null && + $applyDefaultWith->getObjectType() !== null && + $objectType instanceof Node && $this->isObjectType( $objectType, $applyDefaultWith->getObjectType()) && diff --git a/src/Rector/Empty_/EmptyToBlankAndFilledFuncRector.php b/src/Rector/Empty_/EmptyToBlankAndFilledFuncRector.php index fe6307dd..d1e9fa3d 100644 --- a/src/Rector/Empty_/EmptyToBlankAndFilledFuncRector.php +++ b/src/Rector/Empty_/EmptyToBlankAndFilledFuncRector.php @@ -7,7 +7,7 @@ use PhpParser\Node; use PhpParser\Node\Expr\BooleanNot; use PhpParser\Node\Expr\Empty_; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/Expr/AppEnvironmentComparisonToParameterRector.php b/src/Rector/Expr/AppEnvironmentComparisonToParameterRector.php index edcc28d1..19d44284 100644 --- a/src/Rector/Expr/AppEnvironmentComparisonToParameterRector.php +++ b/src/Rector/Expr/AppEnvironmentComparisonToParameterRector.php @@ -13,7 +13,7 @@ use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Scalar\String_; use PHPStan\Type\ObjectType; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/Expr/SubStrToStartsWithOrEndsWithStaticMethodCallRector/SubStrToStartsWithOrEndsWithStaticMethodCallRector.php b/src/Rector/Expr/SubStrToStartsWithOrEndsWithStaticMethodCallRector/SubStrToStartsWithOrEndsWithStaticMethodCallRector.php index 90186cdb..5131469f 100644 --- a/src/Rector/Expr/SubStrToStartsWithOrEndsWithStaticMethodCallRector/SubStrToStartsWithOrEndsWithStaticMethodCallRector.php +++ b/src/Rector/Expr/SubStrToStartsWithOrEndsWithStaticMethodCallRector/SubStrToStartsWithOrEndsWithStaticMethodCallRector.php @@ -11,7 +11,7 @@ use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\StaticCall; use Rector\PhpParser\Node\Value\ValueResolver; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -22,8 +22,7 @@ class SubStrToStartsWithOrEndsWithStaticMethodCallRector extends AbstractRector { public function __construct( private readonly ValueResolver $valueResolver, - ) { - } + ) {} public function getRuleDefinition(): RuleDefinition { @@ -98,8 +97,7 @@ public function refactor(Node $node): ?StaticCall } return $this->nodeFactory->createStaticCall('Illuminate\Support\Str', $methodName, [ - $functionCall->getArgs()[0] -->value, + $functionCall->getArgs()[0]->value, $otherNode, ]); } diff --git a/src/Rector/FuncCall/ArgumentFuncCallToMethodCallRector.php b/src/Rector/FuncCall/ArgumentFuncCallToMethodCallRector.php index 9f6d0f3f..443d23e3 100644 --- a/src/Rector/FuncCall/ArgumentFuncCallToMethodCallRector.php +++ b/src/Rector/FuncCall/ArgumentFuncCallToMethodCallRector.php @@ -14,8 +14,8 @@ use Rector\Contract\Rector\ConfigurableRectorInterface; use Rector\Exception\ShouldNotHappenException; use Rector\NodeTypeResolver\TypeAnalyzer\ArrayTypeAnalyzer; -use Rector\Rector\AbstractRector; use Rector\Transform\NodeAnalyzer\FuncCallStaticCallToMethodCallAnalyzer; +use RectorLaravel\AbstractRector; use RectorLaravel\Contract\ValueObject\ArgumentFuncCallToMethodCallInterface; use RectorLaravel\ValueObject\ArgumentFuncCallToMethodCall; use RectorLaravel\ValueObject\ArrayFuncCallToMethodCall; @@ -36,8 +36,7 @@ final class ArgumentFuncCallToMethodCallRector extends AbstractRector implements public function __construct( private readonly ArrayTypeAnalyzer $arrayTypeAnalyzer, private readonly FuncCallStaticCallToMethodCallAnalyzer $funcCallStaticCallToMethodCallAnalyzer - ) { - } + ) {} public function getRuleDefinition(): RuleDefinition { diff --git a/src/Rector/FuncCall/DispatchNonShouldQueueToDispatchSyncRector.php b/src/Rector/FuncCall/DispatchNonShouldQueueToDispatchSyncRector.php index 29f6eddb..c29bc73a 100644 --- a/src/Rector/FuncCall/DispatchNonShouldQueueToDispatchSyncRector.php +++ b/src/Rector/FuncCall/DispatchNonShouldQueueToDispatchSyncRector.php @@ -15,8 +15,8 @@ use PHPStan\Reflection\ReflectionProvider; use PHPStan\Type\ClosureType; use PHPStan\Type\ObjectType; -use Rector\Rector\AbstractRector; use Rector\StaticTypeMapper\ValueObject\Type\AliasedObjectType; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -33,9 +33,7 @@ class DispatchNonShouldQueueToDispatchSyncRector extends AbstractRector private const string DISPATCHABLE_TRAIT = 'Illuminate\Foundation\Bus\Dispatchable'; - public function __construct(private readonly ReflectionProvider $reflectionProvider) - { - } + public function __construct(private readonly ReflectionProvider $reflectionProvider) {} public function getRuleDefinition(): RuleDefinition { @@ -104,7 +102,7 @@ private function processCall(FuncCall|MethodCall|StaticCall $call): FuncCall|Met return null; } - static $objectType = new ObjectType(self::SHOULD_QUEUE_INTERFACE); + $objectType = new ObjectType(self::SHOULD_QUEUE_INTERFACE); $argumentType = $this->getType($call->args[0]->value); if ( @@ -136,15 +134,20 @@ private function processCall(FuncCall|MethodCall|StaticCall $call): FuncCall|Met private function isDispatchablesCall(MethodCall $methodCall): bool { $type = $this->getType($methodCall->var); - if (! $type instanceof ObjectType) { + + if (! $type->isObject()->yes()) { + return false; + } + + $objectClassNames = $type->getObjectClassNames(); + + if (count($objectClassNames) !== 1) { return false; } try { // Will trigger ClassNotFoundException if the class definition is not found - $reflection = $this->reflectionProvider->getClass( - $type->getClassName() - ); + $reflection = $this->reflectionProvider->getClass($objectClassNames[0]); if ($reflection->hasTraitUse(self::DISPATCHABLE_TRAIT)) { return true; diff --git a/src/Rector/FuncCall/FactoryFuncCallToStaticCallRector.php b/src/Rector/FuncCall/FactoryFuncCallToStaticCallRector.php index 3c1609e2..83655656 100644 --- a/src/Rector/FuncCall/FactoryFuncCallToStaticCallRector.php +++ b/src/Rector/FuncCall/FactoryFuncCallToStaticCallRector.php @@ -9,7 +9,7 @@ use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\StaticCall; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/FuncCall/HelperFuncCallToFacadeClassRector.php b/src/Rector/FuncCall/HelperFuncCallToFacadeClassRector.php index 5fecd651..e1201b96 100644 --- a/src/Rector/FuncCall/HelperFuncCallToFacadeClassRector.php +++ b/src/Rector/FuncCall/HelperFuncCallToFacadeClassRector.php @@ -6,7 +6,7 @@ use PhpParser\Node; use PhpParser\Node\Expr\FuncCall; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/FuncCall/NotFilledBlankFuncCallToBlankFilledFuncCallRector.php b/src/Rector/FuncCall/NotFilledBlankFuncCallToBlankFilledFuncCallRector.php index b48113c0..14f268ba 100644 --- a/src/Rector/FuncCall/NotFilledBlankFuncCallToBlankFilledFuncCallRector.php +++ b/src/Rector/FuncCall/NotFilledBlankFuncCallToBlankFilledFuncCallRector.php @@ -7,7 +7,7 @@ use PhpParser\Node; use PhpParser\Node\Expr\BooleanNot; use PhpParser\Node\Expr\FuncCall; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/FuncCall/NowFuncWithStartOfDayMethodCallToTodayFuncRector.php b/src/Rector/FuncCall/NowFuncWithStartOfDayMethodCallToTodayFuncRector.php index 9a7701c7..0ba77116 100644 --- a/src/Rector/FuncCall/NowFuncWithStartOfDayMethodCallToTodayFuncRector.php +++ b/src/Rector/FuncCall/NowFuncWithStartOfDayMethodCallToTodayFuncRector.php @@ -7,7 +7,7 @@ use PhpParser\Node; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\MethodCall; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/FuncCall/RemoveDumpDataDeadCodeRector.php b/src/Rector/FuncCall/RemoveDumpDataDeadCodeRector.php index e375b830..c5a6665f 100644 --- a/src/Rector/FuncCall/RemoveDumpDataDeadCodeRector.php +++ b/src/Rector/FuncCall/RemoveDumpDataDeadCodeRector.php @@ -7,9 +7,9 @@ use PhpParser\Node; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Stmt\Expression; -use PhpParser\NodeTraverser; +use PhpParser\NodeVisitor; use Rector\Contract\Rector\ConfigurableRectorInterface; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; use Webmozart\Assert\Assert; @@ -78,8 +78,9 @@ public function getNodeTypes(): array /** * @param Expression $node + * @return NodeVisitor::REMOVE_NODE|null */ - public function refactor(Node $node): int|Node|array|null + public function refactor(Node $node): ?int { if (! $node->expr instanceof FuncCall) { return null; @@ -89,7 +90,7 @@ public function refactor(Node $node): int|Node|array|null return null; } - return NodeTraverser::REMOVE_NODE; + return NodeVisitor::REMOVE_NODE; } /** diff --git a/src/Rector/FuncCall/RemoveRedundantValueCallsRector.php b/src/Rector/FuncCall/RemoveRedundantValueCallsRector.php index e05d8999..52eca81a 100644 --- a/src/Rector/FuncCall/RemoveRedundantValueCallsRector.php +++ b/src/Rector/FuncCall/RemoveRedundantValueCallsRector.php @@ -7,7 +7,7 @@ use PhpParser\Node\Name; use PHPStan\Type\ClosureType; use PHPStan\Type\MixedType; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/FuncCall/RemoveRedundantWithCallsRector.php b/src/Rector/FuncCall/RemoveRedundantWithCallsRector.php index b663a0b1..67896c54 100644 --- a/src/Rector/FuncCall/RemoveRedundantWithCallsRector.php +++ b/src/Rector/FuncCall/RemoveRedundantWithCallsRector.php @@ -5,7 +5,7 @@ use PhpParser\Node; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Name; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/FuncCall/SleepFuncToSleepStaticCallRector.php b/src/Rector/FuncCall/SleepFuncToSleepStaticCallRector.php index 3d428376..cdd8ad05 100644 --- a/src/Rector/FuncCall/SleepFuncToSleepStaticCallRector.php +++ b/src/Rector/FuncCall/SleepFuncToSleepStaticCallRector.php @@ -7,7 +7,7 @@ use PhpParser\Node; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Stmt\Expression; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/FuncCall/ThrowIfAndThrowUnlessExceptionsToUseClassStringRector.php b/src/Rector/FuncCall/ThrowIfAndThrowUnlessExceptionsToUseClassStringRector.php index 3ff2ddbe..284a0a26 100644 --- a/src/Rector/FuncCall/ThrowIfAndThrowUnlessExceptionsToUseClassStringRector.php +++ b/src/Rector/FuncCall/ThrowIfAndThrowUnlessExceptionsToUseClassStringRector.php @@ -8,7 +8,7 @@ use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\New_; use PhpParser\Node\Name; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/FuncCall/TypeHintTappableCallRector.php b/src/Rector/FuncCall/TypeHintTappableCallRector.php index 3c7a2e92..33587093 100644 --- a/src/Rector/FuncCall/TypeHintTappableCallRector.php +++ b/src/Rector/FuncCall/TypeHintTappableCallRector.php @@ -10,8 +10,8 @@ use PHPStan\Type\ObjectType; use Rector\NodeTypeResolver\TypeComparator\TypeComparator; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; -use Rector\Rector\AbstractRector; use Rector\StaticTypeMapper\StaticTypeMapper; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -25,8 +25,7 @@ class TypeHintTappableCallRector extends AbstractRector public function __construct( private readonly TypeComparator $typeComparator, private readonly StaticTypeMapper $staticTypeMapper - ) { - } + ) {} public function getRuleDefinition(): RuleDefinition { diff --git a/src/Rector/If_/AbortIfRector.php b/src/Rector/If_/AbortIfRector.php index a199c917..3a287242 100644 --- a/src/Rector/If_/AbortIfRector.php +++ b/src/Rector/If_/AbortIfRector.php @@ -12,8 +12,8 @@ use PhpParser\Node\Name; use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\If_; -use PhpParser\NodeTraverser; -use Rector\Rector\AbstractRector; +use PhpParser\NodeVisitor; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -112,7 +112,7 @@ private function exceptionUsesVariablesAssignedByCondition(Expr $throwExpr, Expr if ($node instanceof Variable && in_array($this->getName($node), $conditionVariables, true)) { $returnValue = true; - return NodeTraverser::STOP_TRAVERSAL; + return NodeVisitor::STOP_TRAVERSAL; } return null; diff --git a/src/Rector/If_/ReportIfRector.php b/src/Rector/If_/ReportIfRector.php index 837c6acd..1454addc 100644 --- a/src/Rector/If_/ReportIfRector.php +++ b/src/Rector/If_/ReportIfRector.php @@ -12,8 +12,8 @@ use PhpParser\Node\Name; use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\If_; -use PhpParser\NodeTraverser; -use Rector\Rector\AbstractRector; +use PhpParser\NodeVisitor; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -112,7 +112,7 @@ private function exceptionUsesVariablesAssignedByCondition(Expr $throwExpr, Expr if ($node instanceof Variable && in_array($this->getName($node), $conditionVariables, true)) { $returnValue = true; - return NodeTraverser::STOP_TRAVERSAL; + return NodeVisitor::STOP_TRAVERSAL; } return null; diff --git a/src/Rector/If_/ThrowIfRector.php b/src/Rector/If_/ThrowIfRector.php index 0bebf54b..78f10124 100644 --- a/src/Rector/If_/ThrowIfRector.php +++ b/src/Rector/If_/ThrowIfRector.php @@ -8,13 +8,13 @@ use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\BooleanNot; use PhpParser\Node\Expr\FuncCall; +use PhpParser\Node\Expr\Throw_; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Name; use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\If_; -use PhpParser\Node\Stmt\Throw_; -use PhpParser\NodeTraverser; -use Rector\Rector\AbstractRector; +use PhpParser\NodeVisitor; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -58,31 +58,31 @@ public function refactor(Node $node): ?Node $ifStmts = $node->stmts; // Check if there's a single throw statement inside the if - if (count($ifStmts) === 1 && $ifStmts[0] instanceof Throw_) { - $condition = $node->cond; - $throwExpr = $ifStmts[0]->expr; + if (count($ifStmts) !== 1 || ! $ifStmts[0] instanceof Expression || ! $ifStmts[0]->expr instanceof Throw_) { + return null; + } - if ($this->exceptionUsesVariablesAssignedByCondition($throwExpr, $condition)) { - return null; - } + $condition = $node->cond; + $throwExpr = $ifStmts[0]->expr; - // Check if the condition is a negation - if ($condition instanceof BooleanNot) { - // Create a new throw_unless function call - return new Expression(new FuncCall(new Name('throw_unless'), [ - new Arg($condition->expr), - new Arg($throwExpr), - ])); - } else { - // Create a new throw_if function call - return new Expression(new FuncCall(new Name('throw_if'), [ - new Arg($condition), - new Arg($throwExpr), - ])); - } + if ($this->exceptionUsesVariablesAssignedByCondition($throwExpr, $condition)) { + return null; } - return null; + // Check if the condition is a negation + if ($condition instanceof BooleanNot) { + // Create a new throw_unless function call + return new Expression(new FuncCall(new Name('throw_unless'), [ + new Arg($condition->expr), + new Arg($throwExpr->expr), + ])); + } else { + // Create a new throw_if function call + return new Expression(new FuncCall(new Name('throw_if'), [ + new Arg($condition), + new Arg($throwExpr->expr), + ])); + } } /** @@ -106,7 +106,7 @@ private function exceptionUsesVariablesAssignedByCondition(Expr $throwExpr, Expr if ($node instanceof Variable && in_array($this->getName($node), $conditionVariables, true)) { $returnValue = true; - return NodeTraverser::STOP_TRAVERSAL; + return NodeVisitor::STOP_TRAVERSAL; } return null; diff --git a/src/Rector/MethodCall/AssertSeeToAssertSeeHtmlRector.php b/src/Rector/MethodCall/AssertSeeToAssertSeeHtmlRector.php index 601ad4f7..36284acd 100644 --- a/src/Rector/MethodCall/AssertSeeToAssertSeeHtmlRector.php +++ b/src/Rector/MethodCall/AssertSeeToAssertSeeHtmlRector.php @@ -8,7 +8,7 @@ use PhpParser\Node\Expr\MethodCall; use PHPStan\Type\ObjectType; use Rector\PhpParser\Node\Value\ValueResolver; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -28,8 +28,7 @@ final class AssertSeeToAssertSeeHtmlRector extends AbstractRector public function __construct( private readonly ValueResolver $valueResolver - ) { - } + ) {} public function getRuleDefinition(): RuleDefinition { diff --git a/src/Rector/MethodCall/AssertStatusToAssertMethodRector.php b/src/Rector/MethodCall/AssertStatusToAssertMethodRector.php index 553b9424..e829e6ec 100644 --- a/src/Rector/MethodCall/AssertStatusToAssertMethodRector.php +++ b/src/Rector/MethodCall/AssertStatusToAssertMethodRector.php @@ -8,7 +8,7 @@ use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Identifier; use PHPStan\Type\ObjectType; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/MethodCall/AvoidNegatedCollectionFilterOrRejectRector.php b/src/Rector/MethodCall/AvoidNegatedCollectionFilterOrRejectRector.php index a3c00b21..df62414d 100644 --- a/src/Rector/MethodCall/AvoidNegatedCollectionFilterOrRejectRector.php +++ b/src/Rector/MethodCall/AvoidNegatedCollectionFilterOrRejectRector.php @@ -11,7 +11,7 @@ use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Identifier; use PHPStan\Type\ObjectType; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/MethodCall/ChangeQueryWhereDateValueWithCarbonRector.php b/src/Rector/MethodCall/ChangeQueryWhereDateValueWithCarbonRector.php index c7986632..638791be 100644 --- a/src/Rector/MethodCall/ChangeQueryWhereDateValueWithCarbonRector.php +++ b/src/Rector/MethodCall/ChangeQueryWhereDateValueWithCarbonRector.php @@ -15,7 +15,7 @@ use PhpParser\Node\Stmt\Expression; use PHPStan\Type\ObjectType; use Rector\PhpParser\Node\Value\ValueResolver; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -29,8 +29,7 @@ final class ChangeQueryWhereDateValueWithCarbonRector extends AbstractRector { public function __construct( private readonly ValueResolver $valueResolver, - ) { - } + ) {} public function getRuleDefinition(): RuleDefinition { @@ -78,8 +77,9 @@ public function getNodeTypes(): array /** * @param Expression $node + * @return array|null */ - public function refactor(Node $node): Node|array|int|null + public function refactor(Node $node): ?array { if (! $node->expr instanceof MethodCall) { return null; diff --git a/src/Rector/MethodCall/DatabaseExpressionToStringToMethodCallRector.php b/src/Rector/MethodCall/DatabaseExpressionToStringToMethodCallRector.php index 8a9f73b5..f05f2d29 100644 --- a/src/Rector/MethodCall/DatabaseExpressionToStringToMethodCallRector.php +++ b/src/Rector/MethodCall/DatabaseExpressionToStringToMethodCallRector.php @@ -7,7 +7,7 @@ use PhpParser\Node; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/MethodCall/EloquentOrderByToLatestOrOldestRector.php b/src/Rector/MethodCall/EloquentOrderByToLatestOrOldestRector.php index af240382..9cf07fce 100644 --- a/src/Rector/MethodCall/EloquentOrderByToLatestOrOldestRector.php +++ b/src/Rector/MethodCall/EloquentOrderByToLatestOrOldestRector.php @@ -6,6 +6,7 @@ use PhpParser\Node; use PhpParser\Node\Arg; +use PhpParser\Node\Expr; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Identifier; @@ -13,7 +14,7 @@ use PhpParser\Node\VariadicPlaceholder; use PHPStan\Type\ObjectType; use Rector\Contract\Rector\ConfigurableRectorInterface; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; use Webmozart\Assert\Assert; @@ -109,12 +110,12 @@ private function isOrderByMethodCall(MethodCall $methodCall): bool return $this->isObjectType($methodCall->var, new ObjectType('Illuminate\Database\Query\Builder')) && $methodCall->name instanceof Identifier && ($methodCall->name->name === 'orderBy' || $methodCall->name->name === 'orderByDesc') - && count($methodCall->args) > 0; + && $methodCall->args !== []; } private function isAllowedPattern(MethodCall $methodCall): bool { - $columnArg = $methodCall->args[0]->value ?? null; + $columnArg = $methodCall->args[0] instanceof Arg ? $methodCall->args[0]->value : null; // If no patterns are specified, consider all column names as matching if ($this->allowedPatterns === []) { @@ -150,12 +151,17 @@ private function convertOrderByToLatest(MethodCall $methodCall): MethodCall return $methodCall; } - $columnVar = $methodCall->args[0]->value ?? null; - if ($columnVar === null) { + $columnVar = $methodCall->args[0] instanceof Arg ? $methodCall->args[0]->value : null; + if (! $columnVar instanceof Expr) { return $methodCall; } - $direction = $methodCall->args[1]->value->value ?? 'asc'; + if (isset($methodCall->args[1]) && $methodCall->args[1] instanceof Arg && $methodCall->args[1]->value instanceof String_) { + $direction = $methodCall->args[1]->value->value; + } else { + $direction = 'asc'; + } + if ($this->isName($methodCall->name, 'orderByDesc')) { $newMethod = 'latest'; } else { diff --git a/src/Rector/MethodCall/EloquentWhereRelationTypeHintingParameterRector.php b/src/Rector/MethodCall/EloquentWhereRelationTypeHintingParameterRector.php index 3b863b06..4db324ae 100644 --- a/src/Rector/MethodCall/EloquentWhereRelationTypeHintingParameterRector.php +++ b/src/Rector/MethodCall/EloquentWhereRelationTypeHintingParameterRector.php @@ -12,7 +12,7 @@ use PhpParser\Node\Name; use PhpParser\Node\Name\FullyQualified; use PHPStan\Type\ObjectType; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -96,8 +96,7 @@ private function changeClosureParamType(MethodCall|StaticCall $node): void ) ? 2 : 1; /** @var ArrowFunction|Closure $closure */ - $closure = $node->getArgs()[$position] -->value; + $closure = $node->getArgs()[$position]->value; if (! isset($closure->getParams()[0])) { return; diff --git a/src/Rector/MethodCall/EloquentWhereTypeHintClosureParameterRector.php b/src/Rector/MethodCall/EloquentWhereTypeHintClosureParameterRector.php index 966cf5dd..acb40135 100644 --- a/src/Rector/MethodCall/EloquentWhereTypeHintClosureParameterRector.php +++ b/src/Rector/MethodCall/EloquentWhereTypeHintClosureParameterRector.php @@ -12,7 +12,7 @@ use PhpParser\Node\Name; use PhpParser\Node\Name\FullyQualified; use PHPStan\Type\ObjectType; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/MethodCall/FactoryApplyingStatesRector.php b/src/Rector/MethodCall/FactoryApplyingStatesRector.php index 079e5317..25b9b80a 100644 --- a/src/Rector/MethodCall/FactoryApplyingStatesRector.php +++ b/src/Rector/MethodCall/FactoryApplyingStatesRector.php @@ -11,7 +11,7 @@ use PhpParser\Node\VariadicPlaceholder; use PHPStan\Type\ObjectType; use Rector\PhpParser\Node\Value\ValueResolver; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; use Webmozart\Assert\Assert; @@ -26,8 +26,7 @@ final class FactoryApplyingStatesRector extends AbstractRector { public function __construct( private readonly ValueResolver $valueResolver, - ) { - } + ) {} public function getRuleDefinition(): RuleDefinition { diff --git a/src/Rector/MethodCall/JsonCallToExplicitJsonCallRector.php b/src/Rector/MethodCall/JsonCallToExplicitJsonCallRector.php index 80ef2b42..2a3ce5e1 100644 --- a/src/Rector/MethodCall/JsonCallToExplicitJsonCallRector.php +++ b/src/Rector/MethodCall/JsonCallToExplicitJsonCallRector.php @@ -11,7 +11,7 @@ use PhpParser\Node\Identifier; use PhpParser\Node\Scalar\String_; use PHPStan\Type\ObjectType; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/MethodCall/LumenRoutesStringActionToUsesArrayRector.php b/src/Rector/MethodCall/LumenRoutesStringActionToUsesArrayRector.php index ac26be08..9d3220ba 100644 --- a/src/Rector/MethodCall/LumenRoutesStringActionToUsesArrayRector.php +++ b/src/Rector/MethodCall/LumenRoutesStringActionToUsesArrayRector.php @@ -6,11 +6,11 @@ use PhpParser\Node; use PhpParser\Node\Arg; +use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr\Array_; -use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Scalar\String_; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use RectorLaravel\NodeAnalyzer\LumenRouteRegisteringMethodAnalyzer; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -22,8 +22,7 @@ final class LumenRoutesStringActionToUsesArrayRector extends AbstractRector { public function __construct( private readonly LumenRouteRegisteringMethodAnalyzer $lumenRouteRegisteringMethodAnalyzer - ) { - } + ) {} public function getRuleDefinition(): RuleDefinition { diff --git a/src/Rector/MethodCall/LumenRoutesStringMiddlewareToArrayRector.php b/src/Rector/MethodCall/LumenRoutesStringMiddlewareToArrayRector.php index 6ed3522b..61707365 100644 --- a/src/Rector/MethodCall/LumenRoutesStringMiddlewareToArrayRector.php +++ b/src/Rector/MethodCall/LumenRoutesStringMiddlewareToArrayRector.php @@ -5,11 +5,11 @@ namespace RectorLaravel\Rector\MethodCall; use PhpParser\Node; +use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr\Array_; -use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Scalar\String_; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use RectorLaravel\NodeAnalyzer\LumenRouteRegisteringMethodAnalyzer; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -21,8 +21,7 @@ final class LumenRoutesStringMiddlewareToArrayRector extends AbstractRector { public function __construct( private readonly LumenRouteRegisteringMethodAnalyzer $lumenRouteRegisteringMethodAnalyzer - ) { - } + ) {} public function getRuleDefinition(): RuleDefinition { @@ -139,9 +138,6 @@ private function replaceItemInArrayByKey(Array_ $array, ArrayItem $arrayItem, st if (! $this->hasKeyName($item, $keyName)) { continue; } - if (! $array->items[$i] instanceof ArrayItem) { - continue; - } $array->items[$i] = $arrayItem; } diff --git a/src/Rector/MethodCall/RedirectBackToBackHelperRector.php b/src/Rector/MethodCall/RedirectBackToBackHelperRector.php index 860ee7cf..d408f0d6 100644 --- a/src/Rector/MethodCall/RedirectBackToBackHelperRector.php +++ b/src/Rector/MethodCall/RedirectBackToBackHelperRector.php @@ -9,7 +9,7 @@ use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Name; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/MethodCall/RedirectRouteToToRouteHelperRector.php b/src/Rector/MethodCall/RedirectRouteToToRouteHelperRector.php index 2bf8bc3d..72f8a5ec 100644 --- a/src/Rector/MethodCall/RedirectRouteToToRouteHelperRector.php +++ b/src/Rector/MethodCall/RedirectRouteToToRouteHelperRector.php @@ -9,7 +9,7 @@ use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Name; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/MethodCall/RefactorBlueprintGeometryColumnsRector.php b/src/Rector/MethodCall/RefactorBlueprintGeometryColumnsRector.php index b6f72c47..5fabc017 100644 --- a/src/Rector/MethodCall/RefactorBlueprintGeometryColumnsRector.php +++ b/src/Rector/MethodCall/RefactorBlueprintGeometryColumnsRector.php @@ -8,7 +8,7 @@ use PhpParser\Node\Identifier; use PhpParser\Node\Scalar\String_; use PHPStan\Type\ObjectType; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/MethodCall/ReplaceServiceContainerCallArgRector.php b/src/Rector/MethodCall/ReplaceServiceContainerCallArgRector.php index fce7ee14..2134fd4d 100644 --- a/src/Rector/MethodCall/ReplaceServiceContainerCallArgRector.php +++ b/src/Rector/MethodCall/ReplaceServiceContainerCallArgRector.php @@ -14,7 +14,7 @@ use PhpParser\Node\Scalar\String_; use PHPStan\Type\ObjectType; use Rector\Contract\Rector\ConfigurableRectorInterface; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use RectorLaravel\ValueObject\ReplaceServiceContainerCallArg; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/MethodCall/ReplaceWithoutJobsEventsAndNotificationsWithFacadeFakeRector.php b/src/Rector/MethodCall/ReplaceWithoutJobsEventsAndNotificationsWithFacadeFakeRector.php index 68601ce3..4f011a7d 100644 --- a/src/Rector/MethodCall/ReplaceWithoutJobsEventsAndNotificationsWithFacadeFakeRector.php +++ b/src/Rector/MethodCall/ReplaceWithoutJobsEventsAndNotificationsWithFacadeFakeRector.php @@ -7,7 +7,7 @@ use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Identifier; use PHPStan\Type\ObjectType; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/MethodCall/ResponseHelperCallToJsonResponseRector.php b/src/Rector/MethodCall/ResponseHelperCallToJsonResponseRector.php index 016a8cd7..d725e793 100644 --- a/src/Rector/MethodCall/ResponseHelperCallToJsonResponseRector.php +++ b/src/Rector/MethodCall/ResponseHelperCallToJsonResponseRector.php @@ -9,7 +9,7 @@ use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\New_; use PhpParser\Node\Name\FullyQualified; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -59,7 +59,7 @@ public function refactor(Node $node): ?Node return null; } - if (count($node->var->args) > 0) { + if ($node->var->args !== []) { return null; } diff --git a/src/Rector/MethodCall/ReverseConditionableMethodCallRector.php b/src/Rector/MethodCall/ReverseConditionableMethodCallRector.php index 871cd125..d2e7888e 100644 --- a/src/Rector/MethodCall/ReverseConditionableMethodCallRector.php +++ b/src/Rector/MethodCall/ReverseConditionableMethodCallRector.php @@ -8,7 +8,7 @@ use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Identifier; use PHPStan\Type\ObjectType; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/MethodCall/UseComponentPropertyWithinCommandsRector.php b/src/Rector/MethodCall/UseComponentPropertyWithinCommandsRector.php index 41fd8700..e1849d92 100644 --- a/src/Rector/MethodCall/UseComponentPropertyWithinCommandsRector.php +++ b/src/Rector/MethodCall/UseComponentPropertyWithinCommandsRector.php @@ -13,7 +13,7 @@ use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Expression; use PHPStan\Type\ObjectType; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/MethodCall/ValidationRuleArrayStringValueToArrayRector.php b/src/Rector/MethodCall/ValidationRuleArrayStringValueToArrayRector.php index 5002ca0b..f94d773b 100644 --- a/src/Rector/MethodCall/ValidationRuleArrayStringValueToArrayRector.php +++ b/src/Rector/MethodCall/ValidationRuleArrayStringValueToArrayRector.php @@ -4,16 +4,16 @@ use PhpParser\Node; use PhpParser\Node\Arg; +use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr\Array_; -use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\Return_; -use PhpParser\NodeTraverser; +use PhpParser\NodeVisitor; use PHPStan\Type\ObjectType; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -139,7 +139,7 @@ private function refactorClassMethod(ClassLike $classLike): ?ClassLike if ($changed) { $hasChanged = true; - return NodeTraverser::STOP_TRAVERSAL; + return NodeVisitor::STOP_TRAVERSAL; } if (! $node instanceof Return_) { diff --git a/src/Rector/Namespace_/FactoryDefinitionRector.php b/src/Rector/Namespace_/FactoryDefinitionRector.php index 0d4490a8..cc0565cf 100644 --- a/src/Rector/Namespace_/FactoryDefinitionRector.php +++ b/src/Rector/Namespace_/FactoryDefinitionRector.php @@ -18,7 +18,7 @@ use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\Namespace_; use Rector\PhpParser\Node\CustomNode\FileWithoutNamespace; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use RectorLaravel\NodeFactory\ModelFactoryNodeFactory; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -33,8 +33,7 @@ final class FactoryDefinitionRector extends AbstractRector { public function __construct( private readonly ModelFactoryNodeFactory $modelFactoryNodeFactory - ) { - } + ) {} public function getRuleDefinition(): RuleDefinition { diff --git a/src/Rector/New_/AddGuardToLoginEventRector.php b/src/Rector/New_/AddGuardToLoginEventRector.php index b6f5cc8b..242b3636 100644 --- a/src/Rector/New_/AddGuardToLoginEventRector.php +++ b/src/Rector/New_/AddGuardToLoginEventRector.php @@ -11,7 +11,7 @@ use PhpParser\Node\Expr\Variable; use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt\Expression; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -68,8 +68,9 @@ public function getNodeTypes(): array /** * @param Expression $node + * @return array|null */ - public function refactor(Node $node): Node|array|int|null + public function refactor(Node $node): ?array { $newNode = $this->getNewNode($node); diff --git a/src/Rector/PropertyFetch/OptionalToNullsafeOperatorRector.php b/src/Rector/PropertyFetch/OptionalToNullsafeOperatorRector.php index 520e8ea6..aa5aabaf 100644 --- a/src/Rector/PropertyFetch/OptionalToNullsafeOperatorRector.php +++ b/src/Rector/PropertyFetch/OptionalToNullsafeOperatorRector.php @@ -18,9 +18,9 @@ use PhpParser\Node\Scalar; use Rector\Contract\Rector\ConfigurableRectorInterface; use Rector\PhpParser\Node\Value\ValueResolver; -use Rector\Rector\AbstractRector; use Rector\ValueObject\PhpVersion; use Rector\VersionBonding\Contract\MinPhpVersionInterface; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; use Webmozart\Assert\Assert; @@ -51,8 +51,7 @@ final class OptionalToNullsafeOperatorRector extends AbstractRector implements C public function __construct( private readonly ValueResolver $valueResolver, - ) { - } + ) {} public function getRuleDefinition(): RuleDefinition { @@ -132,6 +131,9 @@ public function refactor(Node $node): ?Node return new NullsafeMethodCall($firstArg->value, $node->name, $node->args); } + /** + * @return PhpVersion::PHP_80 + */ public function provideMinPhpVersion(): int { return PhpVersion::PHP_80; diff --git a/src/Rector/PropertyFetch/ReplaceFakerInstanceWithHelperRector.php b/src/Rector/PropertyFetch/ReplaceFakerInstanceWithHelperRector.php index 2d087462..21cb61dd 100644 --- a/src/Rector/PropertyFetch/ReplaceFakerInstanceWithHelperRector.php +++ b/src/Rector/PropertyFetch/ReplaceFakerInstanceWithHelperRector.php @@ -9,8 +9,8 @@ use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\PropertyFetch; use PHPStan\Reflection\ClassReflection; -use Rector\Rector\AbstractRector; use Rector\Reflection\ReflectionResolver; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -21,8 +21,7 @@ final class ReplaceFakerInstanceWithHelperRector extends AbstractRector { public function __construct( private readonly ReflectionResolver $reflectionResolver - ) { - } + ) {} public function getRuleDefinition(): RuleDefinition { diff --git a/src/Rector/StaticCall/CarbonSetTestNowToTravelToRector.php b/src/Rector/StaticCall/CarbonSetTestNowToTravelToRector.php index 02fd6a46..55df40a2 100644 --- a/src/Rector/StaticCall/CarbonSetTestNowToTravelToRector.php +++ b/src/Rector/StaticCall/CarbonSetTestNowToTravelToRector.php @@ -7,9 +7,9 @@ use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Expr\Variable; -use PHPStan\Analyser\Scope; use PHPStan\Type\ObjectType; -use Rector\Rector\AbstractScopeAwareRector; +use Rector\PHPStan\ScopeFetcher; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\Exception\PoorDocumentationException; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -17,7 +17,7 @@ /** * @see \RectorLaravel\Tests\Rector\StaticCall\CarbonSetTestNowToTravelToRector\CarbonSetTestNowToTravelToRectorTest */ -final class CarbonSetTestNowToTravelToRector extends AbstractScopeAwareRector +final class CarbonSetTestNowToTravelToRector extends AbstractRector { /** * @throws PoorDocumentationException @@ -66,12 +66,14 @@ public function getNodeTypes(): array return [StaticCall::class]; } - public function refactorWithScope(Node $node, Scope $scope): ?MethodCall + public function refactor(Node $node): ?MethodCall { if (! $node instanceof StaticCall) { return null; } + $scope = ScopeFetcher::fetch($node); + if (! $scope->isInClass()) { return null; } diff --git a/src/Rector/StaticCall/DispatchToHelperFunctionsRector.php b/src/Rector/StaticCall/DispatchToHelperFunctionsRector.php index 06580362..3044e91b 100644 --- a/src/Rector/StaticCall/DispatchToHelperFunctionsRector.php +++ b/src/Rector/StaticCall/DispatchToHelperFunctionsRector.php @@ -12,8 +12,7 @@ use PHPStan\Broker\ClassNotFoundException; use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\ReflectionProvider; -use PHPStan\Type\ObjectType; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\Exception\PoorDocumentationException; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -25,8 +24,7 @@ final class DispatchToHelperFunctionsRector extends AbstractRector { public function __construct( private readonly ReflectionProvider $reflectionProvider, - ) { - } + ) {} /** * @throws PoorDocumentationException @@ -91,14 +89,18 @@ public function refactor(Node $node): ?Node private function getClassReflection(StaticCall $staticCall): ?ClassReflection { $type = $this->getType($staticCall->class); - if (! $type instanceof ObjectType) { + if (! $type->isObject()->yes()) { + return null; + } + + $objectClassNames = $type->getObjectClassNames(); + + if (count($objectClassNames) !== 1) { return null; } try { - return $this->reflectionProvider->getClass( - $type->getClassName() - ); + return $this->reflectionProvider->getClass($objectClassNames[0]); } catch (ClassNotFoundException) { } diff --git a/src/Rector/StaticCall/EloquentMagicMethodToQueryBuilderRector.php b/src/Rector/StaticCall/EloquentMagicMethodToQueryBuilderRector.php index 7143445c..c215a9e5 100644 --- a/src/Rector/StaticCall/EloquentMagicMethodToQueryBuilderRector.php +++ b/src/Rector/StaticCall/EloquentMagicMethodToQueryBuilderRector.php @@ -11,7 +11,7 @@ use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Identifier; use Rector\Contract\Rector\ConfigurableRectorInterface; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use ReflectionException; use ReflectionMethod; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; @@ -72,13 +72,14 @@ public function refactor(Node $node): ?Node { $resolvedType = $this->nodeTypeResolver->getType($node->class); - // like for variables, example "$namespace" - // @phpstan-ignore-next-line - if (! method_exists($resolvedType, 'getClassName')) { + $classNames = $resolvedType->getObjectClassNames(); + + if ($classNames === []) { return null; } - $className = (string) $resolvedType->getClassName(); + $className = $classNames[0]; + $originalClassName = $this->getName($node->class); // like "self" or "App\Models\User" if ($originalClassName === null) { diff --git a/src/Rector/StaticCall/MinutesToSecondsInCacheRector.php b/src/Rector/StaticCall/MinutesToSecondsInCacheRector.php index 0d59e033..d0255d2d 100644 --- a/src/Rector/StaticCall/MinutesToSecondsInCacheRector.php +++ b/src/Rector/StaticCall/MinutesToSecondsInCacheRector.php @@ -10,8 +10,8 @@ use PhpParser\Node\Expr\BinaryOp\Mul; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; -use PhpParser\Node\Scalar\LNumber; -use Rector\Rector\AbstractRector; +use PhpParser\Node\Scalar\Int_; +use RectorLaravel\AbstractRector; use RectorLaravel\ValueObject\TypeToTimeMethodAndPosition; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -148,7 +148,7 @@ private function processArgumentOnPosition( return null; } - $mul = new Mul($argExpr, new LNumber(60)); + $mul = new Mul($argExpr, new Int_(60)); $node->args[$argumentPosition] = new Arg($mul); return $node; diff --git a/src/Rector/StaticCall/Redirect301ToPermanentRedirectRector.php b/src/Rector/StaticCall/Redirect301ToPermanentRedirectRector.php index c7484629..8b45699d 100644 --- a/src/Rector/StaticCall/Redirect301ToPermanentRedirectRector.php +++ b/src/Rector/StaticCall/Redirect301ToPermanentRedirectRector.php @@ -10,7 +10,7 @@ use PhpParser\Node\Identifier; use PHPStan\Type\ObjectType; use Rector\PhpParser\Node\Value\ValueResolver; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/StaticCall/ReplaceAssertTimesSendWithAssertSentTimesRector.php b/src/Rector/StaticCall/ReplaceAssertTimesSendWithAssertSentTimesRector.php index 71132e25..f4878058 100644 --- a/src/Rector/StaticCall/ReplaceAssertTimesSendWithAssertSentTimesRector.php +++ b/src/Rector/StaticCall/ReplaceAssertTimesSendWithAssertSentTimesRector.php @@ -6,7 +6,7 @@ use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Identifier; use PHPStan\Type\ObjectType; -use Rector\Rector\AbstractRector; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/src/Rector/StaticCall/RequestStaticValidateToInjectRector.php b/src/Rector/StaticCall/RequestStaticValidateToInjectRector.php index 97276d72..e0a0f41a 100644 --- a/src/Rector/StaticCall/RequestStaticValidateToInjectRector.php +++ b/src/Rector/StaticCall/RequestStaticValidateToInjectRector.php @@ -16,8 +16,9 @@ use PHPStan\Analyser\Scope; use PHPStan\Reflection\ClassReflection; use PHPStan\Type\ObjectType; -use Rector\Rector\AbstractScopeAwareRector; +use Rector\PHPStan\ScopeFetcher; use Rector\Reflection\ReflectionResolver; +use RectorLaravel\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -26,7 +27,7 @@ * * @see \RectorLaravel\Tests\Rector\StaticCall\RequestStaticValidateToInjectRector\RequestStaticValidateToInjectRectorTest */ -final class RequestStaticValidateToInjectRector extends AbstractScopeAwareRector +final class RequestStaticValidateToInjectRector extends AbstractRector { /** * @var ObjectType[] @@ -81,8 +82,10 @@ public function getNodeTypes(): array return [ClassMethod::class]; } - public function refactorWithScope(Node $node, Scope $scope): ?Node + public function refactor(Node $node): ?Node { + $scope = ScopeFetcher::fetch($node); + /** @var ClassMethod $node */ $this->traverseNodesWithCallable((array) $node->stmts, function (Node $subNode) use ($node, $scope): ?Node { if (! $subNode instanceof StaticCall && ! $subNode instanceof FuncCall) { diff --git a/src/Rector/StaticCall/RouteActionCallableRector.php b/src/Rector/StaticCall/RouteActionCallableRector.php index a433157f..017f053c 100644 --- a/src/Rector/StaticCall/RouteActionCallableRector.php +++ b/src/Rector/StaticCall/RouteActionCallableRector.php @@ -6,20 +6,20 @@ use PhpParser\Node; use PhpParser\Node\Arg; +use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr; use PhpParser\Node\Expr\Array_; -use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Identifier; use PhpParser\Node\Scalar\String_; use PHPStan\Analyser\Scope; -use PHPStan\Reflection\Php\PhpMethodReflection; +use PHPStan\Reflection\MethodReflection; use Rector\Contract\Rector\ConfigurableRectorInterface; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\PhpParser\Node\Value\ValueResolver; -use Rector\Rector\AbstractRector; use Rector\Reflection\ReflectionResolver; +use RectorLaravel\AbstractRector; use RectorLaravel\NodeFactory\RouterRegisterNodeAnalyzer; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -58,8 +58,7 @@ public function __construct( private readonly ReflectionResolver $reflectionResolver, private readonly RouterRegisterNodeAnalyzer $routerRegisterNodeAnalyzer, private readonly ValueResolver $valueResolver, - ) { - } + ) {} public function getRuleDefinition(): RuleDefinition { @@ -123,7 +122,7 @@ public function refactor(Node $node): ?Node $phpMethodReflection = $this->reflectionResolver->resolveMethodReflection($segments[0], $segments[1], $scope); - if (! $phpMethodReflection instanceof PhpMethodReflection) { + if (! $phpMethodReflection instanceof MethodReflection) { return null; } @@ -132,7 +131,7 @@ public function refactor(Node $node): ?Node $segments[1], ]); - if (is_array($argValue) && isset($argValue['as'])) { + if (is_array($argValue) && isset($argValue['as']) && is_string($argValue['as'])) { $node = new MethodCall($node, 'name', [new Arg(new String_($argValue['as']))]); } @@ -144,9 +143,17 @@ public function refactor(Node $node): ?Node if (is_string($argValue['middleware'])) { $argument = new String_($argValue['middleware']); } else { + // if any of the elements in the middleware array is not a string, return node as is + if (array_filter($argValue['middleware'], static fn ($value) => ! is_string($value)) !== []) { + return $node; + } + + /** @var list $middleware */ + $middleware = $argValue['middleware']; + $argument = new Array_(array_map( static fn ($value) => new ArrayItem(new String_($value)), - $argValue['middleware'] + $middleware )); } $node = new MethodCall($node, 'middleware', [new Arg($argument)]); @@ -164,6 +171,7 @@ public function configure(array $configuration): void Assert::isArray($routes); Assert::allString(array_keys($routes)); Assert::allString($routes); + /** @var array $routes */ $this->routes = $routes; $namespace = $configuration[self::NAMESPACE] ?? self::DEFAULT_NAMESPACE; diff --git a/src/Set/LaravelLevelSetList.php b/src/Set/LaravelLevelSetList.php index 852d3cd5..5dd9db62 100644 --- a/src/Set/LaravelLevelSetList.php +++ b/src/Set/LaravelLevelSetList.php @@ -4,9 +4,7 @@ namespace RectorLaravel\Set; -use Rector\Set\Contract\SetListInterface; - -final class LaravelLevelSetList implements SetListInterface +final class LaravelLevelSetList { /** * @var string diff --git a/src/Set/LaravelSetList.php b/src/Set/LaravelSetList.php index ad49796a..8a62c577 100644 --- a/src/Set/LaravelSetList.php +++ b/src/Set/LaravelSetList.php @@ -4,9 +4,7 @@ namespace RectorLaravel\Set; -use Rector\Set\Contract\SetListInterface; - -final class LaravelSetList implements SetListInterface +final class LaravelSetList { /** * @var string diff --git a/src/Set/Packages/Cashier/CashierLevelSetList.php b/src/Set/Packages/Cashier/CashierLevelSetList.php index b2fa4ee1..b9522ea7 100644 --- a/src/Set/Packages/Cashier/CashierLevelSetList.php +++ b/src/Set/Packages/Cashier/CashierLevelSetList.php @@ -4,9 +4,7 @@ namespace RectorLaravel\Set\Packages\Cashier; -use Rector\Set\Contract\SetListInterface; - -final class CashierLevelSetList implements SetListInterface +final class CashierLevelSetList { /** * @var string diff --git a/src/Set/Packages/Cashier/CashierSetList.php b/src/Set/Packages/Cashier/CashierSetList.php index ca727341..23f1f9fd 100644 --- a/src/Set/Packages/Cashier/CashierSetList.php +++ b/src/Set/Packages/Cashier/CashierSetList.php @@ -4,9 +4,7 @@ namespace RectorLaravel\Set\Packages\Cashier; -use Rector\Set\Contract\SetListInterface; - -final class CashierSetList implements SetListInterface +final class CashierSetList { /** * @var string diff --git a/src/Set/Packages/Livewire/LivewireLevelSetList.php b/src/Set/Packages/Livewire/LivewireLevelSetList.php index 36c3852a..1451cf63 100644 --- a/src/Set/Packages/Livewire/LivewireLevelSetList.php +++ b/src/Set/Packages/Livewire/LivewireLevelSetList.php @@ -4,9 +4,7 @@ namespace RectorLaravel\Set\Packages\Livewire; -use Rector\Set\Contract\SetListInterface; - -final class LivewireLevelSetList implements SetListInterface +final class LivewireLevelSetList { /** * @var string diff --git a/src/ValueObject/AddArgumentDefaultValue.php b/src/ValueObject/AddArgumentDefaultValue.php index 6ab9a18f..264512c1 100644 --- a/src/ValueObject/AddArgumentDefaultValue.php +++ b/src/ValueObject/AddArgumentDefaultValue.php @@ -13,8 +13,7 @@ public function __construct( private string $method, private int $position, private mixed $defaultValue - ) { - } + ) {} public function getObjectType(): ObjectType { diff --git a/src/ValueObject/ApplyDefaultInsteadOfNullCoalesce.php b/src/ValueObject/ApplyDefaultInsteadOfNullCoalesce.php index 20766a80..72314bd7 100644 --- a/src/ValueObject/ApplyDefaultInsteadOfNullCoalesce.php +++ b/src/ValueObject/ApplyDefaultInsteadOfNullCoalesce.php @@ -6,9 +6,7 @@ final readonly class ApplyDefaultInsteadOfNullCoalesce { - public function __construct(private string $methodName, private ?ObjectType $objectType = null, private int $argumentPosition = 1) - { - } + public function __construct(private string $methodName, private ?ObjectType $objectType = null, private int $argumentPosition = 1) {} public function getObjectType(): ?ObjectType { diff --git a/src/ValueObject/ReplaceServiceContainerCallArg.php b/src/ValueObject/ReplaceServiceContainerCallArg.php index 106e3ba5..4b03592f 100644 --- a/src/ValueObject/ReplaceServiceContainerCallArg.php +++ b/src/ValueObject/ReplaceServiceContainerCallArg.php @@ -9,8 +9,7 @@ public function __construct( private string|ClassConstFetch $oldService, private string|ClassConstFetch $newService - ) { - } + ) {} public function getOldService(): string|ClassConstFetch { diff --git a/src/ValueObject/ServiceNameTypeAndVariableName.php b/src/ValueObject/ServiceNameTypeAndVariableName.php index 3c2a7b8c..2a4aa57f 100644 --- a/src/ValueObject/ServiceNameTypeAndVariableName.php +++ b/src/ValueObject/ServiceNameTypeAndVariableName.php @@ -10,8 +10,7 @@ public function __construct( private string $serviceName, private string $type, private string $variableName - ) { - } + ) {} public function getServiceName(): string { diff --git a/src/ValueObject/TypeToTimeMethodAndPosition.php b/src/ValueObject/TypeToTimeMethodAndPosition.php index 74684bd7..3adffb77 100644 --- a/src/ValueObject/TypeToTimeMethodAndPosition.php +++ b/src/ValueObject/TypeToTimeMethodAndPosition.php @@ -12,8 +12,7 @@ public function __construct( private string $type, private string $methodName, private int $position - ) { - } + ) {} public function getObjectType(): ObjectType { diff --git a/stubs/Illuminate/Container/Container.php b/stubs/Illuminate/Container/Container.php index 6031aa85..700ee73d 100644 --- a/stubs/Illuminate/Container/Container.php +++ b/stubs/Illuminate/Container/Container.php @@ -4,6 +4,4 @@ use Illuminate\Contracts\Container\Container as ContainerContract; -class Container implements ContainerContract -{ -} +class Container implements ContainerContract {} diff --git a/stubs/Illuminate/Contracts/Cache/Store.php b/stubs/Illuminate/Contracts/Cache/Store.php index cf1ae18a..4b9e8c11 100644 --- a/stubs/Illuminate/Contracts/Cache/Store.php +++ b/stubs/Illuminate/Contracts/Cache/Store.php @@ -8,6 +8,4 @@ return; } -interface Store -{ -} +interface Store {} diff --git a/stubs/Illuminate/Contracts/Container/Container.php b/stubs/Illuminate/Contracts/Container/Container.php index 6e07ef11..da0007eb 100644 --- a/stubs/Illuminate/Contracts/Container/Container.php +++ b/stubs/Illuminate/Contracts/Container/Container.php @@ -2,6 +2,4 @@ namespace Illuminate\Contracts\Container; -interface Container -{ -} +interface Container {} diff --git a/stubs/Illuminate/Contracts/Events/Dispatcher.php b/stubs/Illuminate/Contracts/Events/Dispatcher.php index 97d7158d..7bf2aeb8 100644 --- a/stubs/Illuminate/Contracts/Events/Dispatcher.php +++ b/stubs/Illuminate/Contracts/Events/Dispatcher.php @@ -5,6 +5,4 @@ if (class_exists('Illuminate\Contracts\Events\Dispatcher')) { return; } -class Dispatcher -{ -} +class Dispatcher {} diff --git a/stubs/Illuminate/Contracts/Queue/ShouldQueue.php b/stubs/Illuminate/Contracts/Queue/ShouldQueue.php index 7b04e7fc..e754a386 100644 --- a/stubs/Illuminate/Contracts/Queue/ShouldQueue.php +++ b/stubs/Illuminate/Contracts/Queue/ShouldQueue.php @@ -6,6 +6,4 @@ return; } -interface ShouldQueue -{ -} +interface ShouldQueue {} diff --git a/stubs/Illuminate/Contracts/Routing/ResponseFactory.php b/stubs/Illuminate/Contracts/Routing/ResponseFactory.php index 5c3b9766..df0235b0 100644 --- a/stubs/Illuminate/Contracts/Routing/ResponseFactory.php +++ b/stubs/Illuminate/Contracts/Routing/ResponseFactory.php @@ -6,6 +6,4 @@ return; } -interface ResponseFactory -{ -} +interface ResponseFactory {} diff --git a/stubs/Illuminate/Contracts/Support/DeferrableProvider.php b/stubs/Illuminate/Contracts/Support/DeferrableProvider.php index 05bdd592..0fa592bf 100644 --- a/stubs/Illuminate/Contracts/Support/DeferrableProvider.php +++ b/stubs/Illuminate/Contracts/Support/DeferrableProvider.php @@ -8,6 +8,4 @@ return; } -interface DeferrableProvider -{ -} +interface DeferrableProvider {} diff --git a/stubs/Illuminate/Database/Eloquent/Builder.php b/stubs/Illuminate/Database/Eloquent/Builder.php index f74217a7..e914d21c 100644 --- a/stubs/Illuminate/Database/Eloquent/Builder.php +++ b/stubs/Illuminate/Database/Eloquent/Builder.php @@ -10,11 +10,7 @@ class Builder extends QueryBuilder { - public function publicMethodBelongsToEloquentQueryBuilder(): void - { - } + public function publicMethodBelongsToEloquentQueryBuilder(): void {} - public function excludablePublicMethodBelongsToEloquentQueryBuilder(): void - { - } + public function excludablePublicMethodBelongsToEloquentQueryBuilder(): void {} } diff --git a/stubs/Illuminate/Database/Eloquent/Factories/Factory.php b/stubs/Illuminate/Database/Eloquent/Factories/Factory.php index c72748a1..eddecf32 100644 --- a/stubs/Illuminate/Database/Eloquent/Factories/Factory.php +++ b/stubs/Illuminate/Database/Eloquent/Factories/Factory.php @@ -6,6 +6,4 @@ return; } -abstract class Factory -{ -} +abstract class Factory {} diff --git a/stubs/Illuminate/Database/Eloquent/Relations/BelongsTo.php b/stubs/Illuminate/Database/Eloquent/Relations/BelongsTo.php index 741d3fec..4d20bb82 100644 --- a/stubs/Illuminate/Database/Eloquent/Relations/BelongsTo.php +++ b/stubs/Illuminate/Database/Eloquent/Relations/BelongsTo.php @@ -6,6 +6,4 @@ return; } -class BelongsTo extends Relation -{ -} +class BelongsTo extends Relation {} diff --git a/stubs/Illuminate/Database/Eloquent/Relations/HasMany.php b/stubs/Illuminate/Database/Eloquent/Relations/HasMany.php index e155ac8d..5041a6a8 100644 --- a/stubs/Illuminate/Database/Eloquent/Relations/HasMany.php +++ b/stubs/Illuminate/Database/Eloquent/Relations/HasMany.php @@ -6,6 +6,4 @@ return; } -class HasMany extends Relation -{ -} +class HasMany extends Relation {} diff --git a/stubs/Illuminate/Database/Eloquent/Relations/HasOneThrough.php b/stubs/Illuminate/Database/Eloquent/Relations/HasOneThrough.php index cd1a893b..2f94e905 100644 --- a/stubs/Illuminate/Database/Eloquent/Relations/HasOneThrough.php +++ b/stubs/Illuminate/Database/Eloquent/Relations/HasOneThrough.php @@ -6,6 +6,4 @@ return; } -class HasOneThrough extends Relation -{ -} +class HasOneThrough extends Relation {} diff --git a/stubs/Illuminate/Database/Eloquent/Relations/MorphTo.php b/stubs/Illuminate/Database/Eloquent/Relations/MorphTo.php index 5ec53d2b..58156e51 100644 --- a/stubs/Illuminate/Database/Eloquent/Relations/MorphTo.php +++ b/stubs/Illuminate/Database/Eloquent/Relations/MorphTo.php @@ -6,6 +6,4 @@ return; } -class MorphTo extends BelongsTo -{ -} +class MorphTo extends BelongsTo {} diff --git a/stubs/Illuminate/Database/Eloquent/Relations/Relation.php b/stubs/Illuminate/Database/Eloquent/Relations/Relation.php index 34649f74..b5ded38c 100644 --- a/stubs/Illuminate/Database/Eloquent/Relations/Relation.php +++ b/stubs/Illuminate/Database/Eloquent/Relations/Relation.php @@ -6,6 +6,4 @@ return; } -abstract class Relation -{ -} +abstract class Relation {} diff --git a/stubs/Illuminate/Database/Migrations/Migration.php b/stubs/Illuminate/Database/Migrations/Migration.php index e706854b..27566c50 100644 --- a/stubs/Illuminate/Database/Migrations/Migration.php +++ b/stubs/Illuminate/Database/Migrations/Migration.php @@ -6,6 +6,4 @@ return; } -class Migration -{ -} +class Migration {} diff --git a/stubs/Illuminate/Database/Query/Builder.php b/stubs/Illuminate/Database/Query/Builder.php index 2b54dcbc..88573c15 100644 --- a/stubs/Illuminate/Database/Query/Builder.php +++ b/stubs/Illuminate/Database/Query/Builder.php @@ -8,15 +8,9 @@ class Builder { - public function publicMethodBelongsToQueryBuilder(): void - { - } + public function publicMethodBelongsToQueryBuilder(): void {} - protected function protectedMethodBelongsToQueryBuilder(): void - { - } + protected function protectedMethodBelongsToQueryBuilder(): void {} - private function privateMethodBelongsToQueryBuilder(): void - { - } + private function privateMethodBelongsToQueryBuilder(): void {} } diff --git a/stubs/Illuminate/Foundation/Bus/Dispatchable.php b/stubs/Illuminate/Foundation/Bus/Dispatchable.php index bc889d2d..b2b7d354 100644 --- a/stubs/Illuminate/Foundation/Bus/Dispatchable.php +++ b/stubs/Illuminate/Foundation/Bus/Dispatchable.php @@ -13,7 +13,5 @@ trait Dispatchable * @param array $chain * @return PendingChain */ - public static function withChain($chain) - { - } + public static function withChain($chain) {} } diff --git a/stubs/Illuminate/Foundation/Bus/DispatchesJobs.php b/stubs/Illuminate/Foundation/Bus/DispatchesJobs.php index 0627efa0..663d95b5 100644 --- a/stubs/Illuminate/Foundation/Bus/DispatchesJobs.php +++ b/stubs/Illuminate/Foundation/Bus/DispatchesJobs.php @@ -6,6 +6,4 @@ return; } -trait DispatchesJobs -{ -} +trait DispatchesJobs {} diff --git a/stubs/Illuminate/Foundation/Bus/PendingChain.php b/stubs/Illuminate/Foundation/Bus/PendingChain.php index dbfa3a26..561b740a 100644 --- a/stubs/Illuminate/Foundation/Bus/PendingChain.php +++ b/stubs/Illuminate/Foundation/Bus/PendingChain.php @@ -5,6 +5,4 @@ if (class_exists('Illuminate\Foundation\Bus\PendingChain')) { return; } -class PendingChain -{ -} +class PendingChain {} diff --git a/stubs/Illuminate/Foundation/Events/Dispatchable.php b/stubs/Illuminate/Foundation/Events/Dispatchable.php index 38e24646..10d05fec 100644 --- a/stubs/Illuminate/Foundation/Events/Dispatchable.php +++ b/stubs/Illuminate/Foundation/Events/Dispatchable.php @@ -7,19 +7,11 @@ } trait Dispatchable { - public static function dispatch(...$arguments) - { - } + public static function dispatch(...$arguments) {} - public static function dispatchIf($boolean, ...$arguments) - { - } + public static function dispatchIf($boolean, ...$arguments) {} - public static function dispatchUnless($boolean, ...$arguments) - { - } + public static function dispatchUnless($boolean, ...$arguments) {} - public static function broadcast() - { - } + public static function broadcast() {} } diff --git a/stubs/Illuminate/Foundation/Exceptions/Handler.php b/stubs/Illuminate/Foundation/Exceptions/Handler.php index e65d1fb5..f492617a 100644 --- a/stubs/Illuminate/Foundation/Exceptions/Handler.php +++ b/stubs/Illuminate/Foundation/Exceptions/Handler.php @@ -8,6 +8,4 @@ return; } -class Handler -{ -} +class Handler {} diff --git a/stubs/Illuminate/Foundation/Http/FormRequest.php b/stubs/Illuminate/Foundation/Http/FormRequest.php index ac5122f7..1bfcea68 100644 --- a/stubs/Illuminate/Foundation/Http/FormRequest.php +++ b/stubs/Illuminate/Foundation/Http/FormRequest.php @@ -8,6 +8,4 @@ return; } -class FormRequest -{ -} +class FormRequest {} diff --git a/stubs/Illuminate/Foundation/Http/Kernel.php b/stubs/Illuminate/Foundation/Http/Kernel.php index d00dc9d0..291509c5 100644 --- a/stubs/Illuminate/Foundation/Http/Kernel.php +++ b/stubs/Illuminate/Foundation/Http/Kernel.php @@ -8,6 +8,4 @@ return; } -class Kernel -{ -} +class Kernel {} diff --git a/stubs/Illuminate/Foundation/Support/Providers/EventServiceProvider.php b/stubs/Illuminate/Foundation/Support/Providers/EventServiceProvider.php index c9b78572..41abda0a 100644 --- a/stubs/Illuminate/Foundation/Support/Providers/EventServiceProvider.php +++ b/stubs/Illuminate/Foundation/Support/Providers/EventServiceProvider.php @@ -6,6 +6,4 @@ return; } -class EventServiceProvider -{ -} +class EventServiceProvider {} diff --git a/stubs/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php b/stubs/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php index 9f0f878a..ba8440c7 100644 --- a/stubs/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php +++ b/stubs/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php @@ -6,6 +6,4 @@ return; } -class MakesHttpRequests -{ -} +class MakesHttpRequests {} diff --git a/stubs/Illuminate/Foundation/Testing/TestCase.php b/stubs/Illuminate/Foundation/Testing/TestCase.php index ef31cd66..59ba0a8c 100644 --- a/stubs/Illuminate/Foundation/Testing/TestCase.php +++ b/stubs/Illuminate/Foundation/Testing/TestCase.php @@ -6,6 +6,4 @@ return; } -class TestCase -{ -} +class TestCase {} diff --git a/stubs/Illuminate/Http/Response.php b/stubs/Illuminate/Http/Response.php index fd40a4ec..7981b5a5 100644 --- a/stubs/Illuminate/Http/Response.php +++ b/stubs/Illuminate/Http/Response.php @@ -8,6 +8,4 @@ return; } -class Response extends SymfonyResponse -{ -} +class Response extends SymfonyResponse {} diff --git a/stubs/Illuminate/Mail/MailManager.php b/stubs/Illuminate/Mail/MailManager.php index bc3f0a9a..957ef763 100644 --- a/stubs/Illuminate/Mail/MailManager.php +++ b/stubs/Illuminate/Mail/MailManager.php @@ -8,6 +8,4 @@ return; } -class MailManager -{ -} +class MailManager {} diff --git a/stubs/Illuminate/Mail/Mailable.php b/stubs/Illuminate/Mail/Mailable.php index f92e1ccf..3c9d0c97 100644 --- a/stubs/Illuminate/Mail/Mailable.php +++ b/stubs/Illuminate/Mail/Mailable.php @@ -8,6 +8,4 @@ return; } -class Mailable -{ -} +class Mailable {} diff --git a/stubs/Illuminate/Mail/Mailer.php b/stubs/Illuminate/Mail/Mailer.php index 4fdd992b..bca79ced 100644 --- a/stubs/Illuminate/Mail/Mailer.php +++ b/stubs/Illuminate/Mail/Mailer.php @@ -8,6 +8,4 @@ return; } -class Mailer -{ -} +class Mailer {} diff --git a/stubs/Illuminate/Mail/Message.php b/stubs/Illuminate/Mail/Message.php index fbb883a2..fa2c77a2 100644 --- a/stubs/Illuminate/Mail/Message.php +++ b/stubs/Illuminate/Mail/Message.php @@ -8,6 +8,4 @@ return; } -class Message -{ -} +class Message {} diff --git a/stubs/Illuminate/Notifications/Messages/MailMessage.php b/stubs/Illuminate/Notifications/Messages/MailMessage.php index 3e25e720..c7b44812 100644 --- a/stubs/Illuminate/Notifications/Messages/MailMessage.php +++ b/stubs/Illuminate/Notifications/Messages/MailMessage.php @@ -8,6 +8,4 @@ return; } -class MailMessage -{ -} +class MailMessage {} diff --git a/stubs/Illuminate/Routing/ResponseFactory.php b/stubs/Illuminate/Routing/ResponseFactory.php index 9e624f20..29fe1f1e 100644 --- a/stubs/Illuminate/Routing/ResponseFactory.php +++ b/stubs/Illuminate/Routing/ResponseFactory.php @@ -8,6 +8,4 @@ return; } -class ResponseFactory implements \Illuminate\Contracts\Routing\ResponseFactory -{ -} +class ResponseFactory implements \Illuminate\Contracts\Routing\ResponseFactory {} diff --git a/stubs/Illuminate/Support/Collection.php b/stubs/Illuminate/Support/Collection.php index 73405ee2..d59e28f1 100644 --- a/stubs/Illuminate/Support/Collection.php +++ b/stubs/Illuminate/Support/Collection.php @@ -15,6 +15,4 @@ * * @implements \Illuminate\Support\Enumerable */ -class Collection implements Enumerable -{ -} +class Collection implements Enumerable {} diff --git a/stubs/Illuminate/Support/Facades/Route.php b/stubs/Illuminate/Support/Facades/Route.php index 805b69db..5662f7e2 100644 --- a/stubs/Illuminate/Support/Facades/Route.php +++ b/stubs/Illuminate/Support/Facades/Route.php @@ -11,6 +11,4 @@ /** * @method static \Illuminate\Routing\RouteRegistrar middleware(array|string|null $middleware) */ -class Route -{ -} +class Route {} diff --git a/stubs/Illuminate/Support/ServiceProvider.php b/stubs/Illuminate/Support/ServiceProvider.php index 491a31d8..2dbe3375 100644 --- a/stubs/Illuminate/Support/ServiceProvider.php +++ b/stubs/Illuminate/Support/ServiceProvider.php @@ -8,6 +8,4 @@ return; } -abstract class ServiceProvider -{ -} +abstract class ServiceProvider {} diff --git a/stubs/Illuminate/Support/Traits/Conditionable.php b/stubs/Illuminate/Support/Traits/Conditionable.php index 58abe2cd..dba90a51 100644 --- a/stubs/Illuminate/Support/Traits/Conditionable.php +++ b/stubs/Illuminate/Support/Traits/Conditionable.php @@ -8,11 +8,7 @@ trait Conditionable { - public function when($value = null, ?callable $callback = null, ?callable $default = null) - { - } + public function when($value = null, ?callable $callback = null, ?callable $default = null) {} - public function unless($value = null, ?callable $callback = null, ?callable $default = null) - { - } + public function unless($value = null, ?callable $callback = null, ?callable $default = null) {} } diff --git a/stubs/Illuminate/Support/Traits/Tappable.php b/stubs/Illuminate/Support/Traits/Tappable.php index e70c2934..0f5741eb 100644 --- a/stubs/Illuminate/Support/Traits/Tappable.php +++ b/stubs/Illuminate/Support/Traits/Tappable.php @@ -8,7 +8,5 @@ trait Tappable { - public function tap($callback = null) - { - } + public function tap($callback = null) {} } diff --git a/stubs/Illuminate/Testing/TestResponse.php b/stubs/Illuminate/Testing/TestResponse.php index 2960b43d..83c873a0 100644 --- a/stubs/Illuminate/Testing/TestResponse.php +++ b/stubs/Illuminate/Testing/TestResponse.php @@ -8,6 +8,4 @@ return; } -class TestResponse -{ -} +class TestResponse {} diff --git a/stubs/Laravel/Cashier/Billable.php b/stubs/Laravel/Cashier/Billable.php index cb011eb8..fcb58c65 100644 --- a/stubs/Laravel/Cashier/Billable.php +++ b/stubs/Laravel/Cashier/Billable.php @@ -6,6 +6,4 @@ return; } -trait Billable -{ -} +trait Billable {} diff --git a/stubs/Livewire/Component.php b/stubs/Livewire/Component.php index 0005a8b3..ff5473c9 100644 --- a/stubs/Livewire/Component.php +++ b/stubs/Livewire/Component.php @@ -6,6 +6,4 @@ return; } -class Component -{ -} +class Component {} diff --git a/tests/Rector/ClassMethod/AddGenericReturnTypeToRelationsRector/Fixture/NewGenerics/with-constant-string-type.php.inc b/tests/Rector/ClassMethod/AddGenericReturnTypeToRelationsRector/Fixture/NewGenerics/with-constant-string-type.php.inc new file mode 100644 index 00000000..fdb8edef --- /dev/null +++ b/tests/Rector/ClassMethod/AddGenericReturnTypeToRelationsRector/Fixture/NewGenerics/with-constant-string-type.php.inc @@ -0,0 +1,40 @@ +hasMany('RectorLaravel\Tests\Rector\ClassMethod\AddGenericReturnTypeToRelationsRector\Fixture\NewGenerics\Account'); + } +} + +?> +----- + + */ + public function accounts(): HasMany + { + return $this->hasMany('RectorLaravel\Tests\Rector\ClassMethod\AddGenericReturnTypeToRelationsRector\Fixture\NewGenerics\Account'); + } +} + +?> diff --git a/tests/Rector/Class_/ReplaceExpectsMethodsInTestsRector/Source/TestCase.php b/tests/Rector/Class_/ReplaceExpectsMethodsInTestsRector/Source/TestCase.php index 634f417e..dc011d8b 100644 --- a/tests/Rector/Class_/ReplaceExpectsMethodsInTestsRector/Source/TestCase.php +++ b/tests/Rector/Class_/ReplaceExpectsMethodsInTestsRector/Source/TestCase.php @@ -4,6 +4,4 @@ use Illuminate\Foundation\Testing\TestCase as BaseTestCase; -class TestCase extends BaseTestCase -{ -} +class TestCase extends BaseTestCase {} diff --git a/tests/Rector/FuncCall/DispatchNonShouldQueueToDispatchSyncRector/Source/QueueableJob.php b/tests/Rector/FuncCall/DispatchNonShouldQueueToDispatchSyncRector/Source/QueueableJob.php index bf5227fb..c5e4bcb6 100644 --- a/tests/Rector/FuncCall/DispatchNonShouldQueueToDispatchSyncRector/Source/QueueableJob.php +++ b/tests/Rector/FuncCall/DispatchNonShouldQueueToDispatchSyncRector/Source/QueueableJob.php @@ -4,6 +4,4 @@ use Illuminate\Contracts\Queue\ShouldQueue; -class QueueableJob implements ShouldQueue -{ -} +class QueueableJob implements ShouldQueue {} diff --git a/tests/Rector/FuncCall/DispatchNonShouldQueueToDispatchSyncRector/Source/SomeJob.php b/tests/Rector/FuncCall/DispatchNonShouldQueueToDispatchSyncRector/Source/SomeJob.php index bae82430..ec901031 100644 --- a/tests/Rector/FuncCall/DispatchNonShouldQueueToDispatchSyncRector/Source/SomeJob.php +++ b/tests/Rector/FuncCall/DispatchNonShouldQueueToDispatchSyncRector/Source/SomeJob.php @@ -2,6 +2,4 @@ namespace RectorLaravel\Tests\Rector\FuncCall\DispatchNonShouldQueueToDispatchSyncRector\Source; -class SomeJob -{ -} +class SomeJob {} diff --git a/tests/Rector/FuncCall/RemoveRedundantValueCallsRector/Source/HelperObject.php b/tests/Rector/FuncCall/RemoveRedundantValueCallsRector/Source/HelperObject.php index 4a024c74..61f508dc 100644 --- a/tests/Rector/FuncCall/RemoveRedundantValueCallsRector/Source/HelperObject.php +++ b/tests/Rector/FuncCall/RemoveRedundantValueCallsRector/Source/HelperObject.php @@ -4,7 +4,5 @@ class HelperObject { - public function store(): void - { - } + public function store(): void {} } diff --git a/tests/Rector/FuncCall/RemoveRedundantWithCallsRector/Source/HelperObject.php b/tests/Rector/FuncCall/RemoveRedundantWithCallsRector/Source/HelperObject.php index 7f121aed..b94db3d6 100644 --- a/tests/Rector/FuncCall/RemoveRedundantWithCallsRector/Source/HelperObject.php +++ b/tests/Rector/FuncCall/RemoveRedundantWithCallsRector/Source/HelperObject.php @@ -4,7 +4,5 @@ class HelperObject { - public function store(): void - { - } + public function store(): void {} } diff --git a/tests/Rector/FuncCall/TypeHintTappableCallRector/Source/NonTappableExample.php b/tests/Rector/FuncCall/TypeHintTappableCallRector/Source/NonTappableExample.php index 94860e79..798b007d 100644 --- a/tests/Rector/FuncCall/TypeHintTappableCallRector/Source/NonTappableExample.php +++ b/tests/Rector/FuncCall/TypeHintTappableCallRector/Source/NonTappableExample.php @@ -2,6 +2,4 @@ namespace RectorLaravel\Tests\Rector\FuncCall\TypeHintTappableCallRector\Source; -class NonTappableExample -{ -} +class NonTappableExample {} diff --git a/tests/Rector/MethodCall/ResponseHelperCallToJsonResponseRector/ResponseHelperCallToJsonResponseRectorTest.php b/tests/Rector/MethodCall/ResponseHelperCallToJsonResponseRector/ResponseHelperCallToJsonResponseRectorTest.php index 4e913706..4efb0477 100644 --- a/tests/Rector/MethodCall/ResponseHelperCallToJsonResponseRector/ResponseHelperCallToJsonResponseRectorTest.php +++ b/tests/Rector/MethodCall/ResponseHelperCallToJsonResponseRector/ResponseHelperCallToJsonResponseRectorTest.php @@ -16,6 +16,9 @@ public static function provideData(): Iterator return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); } + /** + * @test + */ #[Test] #[DataProvider('provideData')] public function test(string $filePath): void diff --git a/tests/Rector/Namespace_/FactoryDefinitionRector/Source/Model.php b/tests/Rector/Namespace_/FactoryDefinitionRector/Source/Model.php index b90ad074..d3b188ec 100644 --- a/tests/Rector/Namespace_/FactoryDefinitionRector/Source/Model.php +++ b/tests/Rector/Namespace_/FactoryDefinitionRector/Source/Model.php @@ -2,6 +2,4 @@ namespace RectorLaravel\Tests\Rector\Namespace_\FactoryDefinitionRector\Source; -class Model -{ -} +class Model {} diff --git a/tests/Rector/PropertyFetch/OptionalToNullsafeOperatorRector/Source/SomeClass.php b/tests/Rector/PropertyFetch/OptionalToNullsafeOperatorRector/Source/SomeClass.php index 2079826d..36929187 100644 --- a/tests/Rector/PropertyFetch/OptionalToNullsafeOperatorRector/Source/SomeClass.php +++ b/tests/Rector/PropertyFetch/OptionalToNullsafeOperatorRector/Source/SomeClass.php @@ -6,8 +6,5 @@ class SomeClass { public int $foo; - public function something(bool $parameter = false): void - { - - } + public function something(bool $parameter = false): void {} } diff --git a/tests/Rector/StaticCall/DispatchToHelperFunctionsRector/Source/OtherDispatchable.php b/tests/Rector/StaticCall/DispatchToHelperFunctionsRector/Source/OtherDispatchable.php index 48b2f395..9be8ae12 100644 --- a/tests/Rector/StaticCall/DispatchToHelperFunctionsRector/Source/OtherDispatchable.php +++ b/tests/Rector/StaticCall/DispatchToHelperFunctionsRector/Source/OtherDispatchable.php @@ -11,6 +11,5 @@ class OtherDispatchable public function __construct( private string $param1, private string $param2, - ) { - } + ) {} } diff --git a/tests/Rector/StaticCall/DispatchToHelperFunctionsRector/Source/TestEvent.php b/tests/Rector/StaticCall/DispatchToHelperFunctionsRector/Source/TestEvent.php index 322aeb28..aa4579e4 100644 --- a/tests/Rector/StaticCall/DispatchToHelperFunctionsRector/Source/TestEvent.php +++ b/tests/Rector/StaticCall/DispatchToHelperFunctionsRector/Source/TestEvent.php @@ -11,6 +11,5 @@ class TestEvent public function __construct( private string $param1, private string $param2, - ) { - } + ) {} } diff --git a/tests/Rector/StaticCall/DispatchToHelperFunctionsRector/Source/TestJob.php b/tests/Rector/StaticCall/DispatchToHelperFunctionsRector/Source/TestJob.php index 9846ecc4..f1f70f13 100644 --- a/tests/Rector/StaticCall/DispatchToHelperFunctionsRector/Source/TestJob.php +++ b/tests/Rector/StaticCall/DispatchToHelperFunctionsRector/Source/TestJob.php @@ -11,6 +11,5 @@ class TestJob public function __construct( private string $param1, private string $param2, - ) { - } + ) {} } diff --git a/tests/Rector/StaticCall/EloquentMagicMethodToQueryBuilderRector/EloquentMagicMethodToQueryBuilderRectorTest.php b/tests/Rector/StaticCall/EloquentMagicMethodToQueryBuilderRector/EloquentMagicMethodToQueryBuilderRectorTest.php index fefff2d2..2ba419ef 100644 --- a/tests/Rector/StaticCall/EloquentMagicMethodToQueryBuilderRector/EloquentMagicMethodToQueryBuilderRectorTest.php +++ b/tests/Rector/StaticCall/EloquentMagicMethodToQueryBuilderRector/EloquentMagicMethodToQueryBuilderRectorTest.php @@ -9,9 +9,7 @@ use PHPUnit\Framework\Attributes\DataProvider; use Rector\Testing\PHPUnit\AbstractRectorTestCase; -final class User extends Model -{ -} +final class User extends Model {} final class EloquentMagicMethodToQueryBuilderRectorTest extends AbstractRectorTestCase { diff --git a/tests/Rector/StaticCall/RouteActionCallableRector/Source/SomeController.php b/tests/Rector/StaticCall/RouteActionCallableRector/Source/SomeController.php index 406774e0..184839ac 100644 --- a/tests/Rector/StaticCall/RouteActionCallableRector/Source/SomeController.php +++ b/tests/Rector/StaticCall/RouteActionCallableRector/Source/SomeController.php @@ -4,8 +4,5 @@ class SomeController { - public function index() - { - - } + public function index() {} } diff --git a/tests/Sets/LaravelSetProviderTest.php b/tests/Sets/LaravelSetProviderTest.php index 58f8511f..d0c371c9 100644 --- a/tests/Sets/LaravelSetProviderTest.php +++ b/tests/Sets/LaravelSetProviderTest.php @@ -28,9 +28,12 @@ final class LaravelSetProviderTest extends TestCase LaravelSetList::LARAVEL_110, ]; - public function testItProvidesSets(): void + /** + * @test + */ + public function it_provides_sets(): void { - $laravelSetProvider = new LaravelSetProvider(); + $laravelSetProvider = new LaravelSetProvider; Assert::assertContainsOnlyInstancesOf( SetInterface::class, @@ -38,9 +41,12 @@ public function testItProvidesSets(): void ); } - public function testItReturnsUniqueSets(): void + /** + * @test + */ + public function it_returns_unique_sets(): void { - $laravelSetProvider = new LaravelSetProvider(); + $laravelSetProvider = new LaravelSetProvider; $sets = $laravelSetProvider->provide(); @@ -49,9 +55,12 @@ public function testItReturnsUniqueSets(): void Assert::assertCount(count($sets), $uniqueSets); } - public function testItProvidesAllLaravelVersions(): void + /** + * @test + */ + public function it_provides_all_laravel_versions(): void { - $laravelSetProvider = new LaravelSetProvider(); + $laravelSetProvider = new LaravelSetProvider; $sets = $laravelSetProvider->provide();