From c2c5228199893009ad4bf6c18c61ea507fc5de98 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 20 Jan 2021 18:41:35 +0700 Subject: [PATCH] [TypeDeclaration] Improve FlipTypeControlToUseExclusiveTypeRector : add Nullable support for Assign expr (#5254) Co-authored-by: rector-bot --- .../AnnotationReader/NodeAnnotationReader.php | 2 +- .../src/PhpDocInfo/PhpDocInfoFactory.php | 3 +- .../PhpDocManipulator/PhpDocTypeChanger.php | 3 +- .../src/PhpDocParser/BetterPhpDocParser.php | 4 +- .../Doctrine/Class_/TableTagValueNode.php | 4 +- .../Property_/JoinTableTagValueNode.php | 4 +- .../PhpDocParser/AbstractPhpDocInfoTest.php | 3 +- .../src/Collector/RectorChangeCollector.php | 4 +- .../src/NodeAnalyzer/ClassChildAnalyzer.php | 5 +- .../NodeAnalyzer/PropertyUsageAnalyzer.php | 2 +- .../src/NodeCollector/NodeRepository.php | 2 +- .../Reflection/MethodReflectionProvider.php | 4 +- .../src/ScopeNestingComparator.php | 2 +- .../src/NodeTypeResolver.php | 2 +- .../ClassMethodOrClassConstTypeResolver.php | 3 +- .../NodeTypeResolver/ParamTypeResolver.php | 3 +- .../PropertyFetchTypeResolver.php | 4 +- .../NodeTypeResolver/VariableTypeResolver.php | 4 +- .../FunctionMethodAndClassNodeVisitor.php | 2 +- .../src/NodeVisitor/StatementNodeVisitor.php | 2 +- .../src/TypeMapper/UnionTypeMapper.php | 7 ++- .../src/Collector/UseNodesToAddCollector.php | 6 +- .../src/Rector/UseAddingPostRector.php | 2 +- .../ReadWritePropertyAnalyzer.php | 6 +- .../src/Provider/RectorRecipeProvider.php | 2 +- .../ClassMethodReturnVendorLockResolver.php | 3 +- .../src/Analyzer/ClassAnalyzer.php | 5 +- .../MoveEntitiesToEntityDirectoryRector.php | 3 +- ...acesToContractNamespaceDirectoryRector.php | 3 +- .../MoveServicesBySuffixToDirectoryRector.php | 3 +- ...lueObjectsToValueObjectDirectoryRector.php | 3 +- .../MethodCall/ArrayToFluentCallRector.php | 2 +- .../Rector/MethodCall/ModalToGetSetRector.php | 2 +- ...RenameMethodCallBasedOnParameterRector.php | 2 +- .../ChangeSnakedFixtureNameToPascalRector.php | 3 +- .../VarInlineAnnotationToAssertRector.php | 8 +-- .../CallableClassMethodMatcher.php | 5 +- .../ArrayThisCallToThisMethodCallRector.php | 3 +- ...ableThisArrayToAnonymousFunctionRector.php | 3 +- .../SplitListAssignToSeparateLineRector.php | 3 +- .../SimplifyEmptyArrayCheckRector.php | 3 +- .../ThrowWithPreviousExceptionRector.php | 2 +- .../DateTimeToDateTimeInterfaceRector.php | 2 +- ...hItemsAssignToEmptyArrayToAssignRector.php | 5 +- .../Foreach_/ForeachToInArrayRector.php | 6 +- .../FuncCall/AddPregQuoteDelimiterRector.php | 2 +- .../Identical/GetClassToInstanceOfRector.php | 3 +- .../Identical/SimplifyArraySearchRector.php | 3 +- .../Identical/SimplifyConditionsRector.php | 3 +- .../Rector/If_/ExplicitBoolCompareRector.php | 2 +- .../src/Rector/If_/ShortenElseIfRector.php | 3 +- .../If_/SimplifyIfElseToTernaryRector.php | 8 +-- .../Return_/SimplifyUselessVariableRector.php | 2 +- .../SimplifyTautologyTernaryRector.php | 3 +- .../src/Node/DocAliasResolver.php | 3 +- .../coding-style/src/Node/UseManipulator.php | 4 +- ...anualJsonStringToJsonEncodeArrayRector.php | 2 +- ...itedMethodVisibilitySameAsParentRector.php | 3 +- .../ReturnArrayClassMethodToYieldRector.php | 4 +- .../ClassMethod/UnSpreadOperatorRector.php | 2 +- ...rapEncapsedVariableInCurlyBracesRector.php | 2 +- .../Throw_/AnnotateThrowablesRector.php | 4 +- .../Rector/Use_/RemoveUnusedAliasRector.php | 2 +- .../Doctrine/DoctrineEntityManipulator.php | 2 +- .../NodeCollector/UnusedParameterResolver.php | 2 +- .../RemoveUnusedAssignVariableRector.php | 2 +- .../RemoveDelegatingParentCallRector.php | 2 +- .../RemoveUnusedParameterRector.php | 5 +- ...dDoctrineEntityMethodAndPropertyRector.php | 2 +- .../SimplifyIfElseWithSameContentRector.php | 3 +- .../RemoveEmptyMethodCallRector.php | 5 +- .../RemoveDeadZeroAndOneOperationRector.php | 2 +- ...RemoveNullPropertyInitializationRector.php | 3 +- .../RemoveParentCallWithoutParentRector.php | 3 +- .../src/ValueObject/VariableNodeUse.php | 2 +- .../src/DeadParamTagValueNodeAnalyzer.php | 2 +- .../RemoveUselessReturnTagRector.php | 3 +- .../RemoveNonExistingVarAnnotationRector.php | 2 +- .../src/TagRemover/ParamTagRemover.php | 3 +- .../src/TagRemover/ReturnTagRemover.php | 3 +- .../ParentClassMethodTypeOverrideGuard.php | 2 +- .../FluentChainMethodCallNodeAnalyzer.php | 2 +- .../FluentChainMethodCallRootExtractor.php | 3 +- .../AbstractFluentChainMethodCallRector.php | 3 +- .../ClassMethod/ReturnThisRemoveRector.php | 4 +- ...hainMethodCallToNormalMethodCallRector.php | 3 +- ...MethodCallToStandaloneMethodCallRector.php | 3 +- ...tterMethodCallToStandaloneAssignRector.php | 5 +- ...FluentChainMethodCallToNonFluentRector.php | 3 +- ...hainMethodCallToNormalMethodCallRector.php | 8 ++- ...FluentChainMethodCallToNonFluentRector.php | 6 +- .../src/ValueObject/AssignAndRootExpr.php | 5 +- .../src/ValueObject/FirstAssignFluentCall.php | 3 +- ...ltiParentingToAbstractDependencyRector.php | 6 +- .../ConstructorAssignPropertyAnalyzer.php | 3 +- .../SetterClassMethodAnalyzer.php | 11 ++-- ...terNullabilityInSyncWithPropertyRector.php | 2 +- ...TimeDefaultInEntityToConstructorRector.php | 3 +- ...ParametersArrayToArrayCollectionRector.php | 3 +- ...ngeBigIntEntityPropertyToIntTypeRector.php | 3 +- ...rectDefaultTypesOnEntityPropertyRector.php | 3 +- ...octrineCollectionDocTypeInEntityRector.php | 10 ++-- ...AddUuidMirrorForRelationPropertyRector.php | 2 +- .../AlwaysInitializeUuidInEntityRector.php | 5 +- ...egistryGetManagerToEntityManagerRector.php | 4 +- ...eIdenticalUuidToEqualsMethodCallRector.php | 2 +- .../ChangeSetIdToUuidValueRector.php | 5 +- .../AddUuidAnnotationsToIdPropertyRector.php | 2 +- .../DowngradeParameterTypeWideningRector.php | 8 +-- ...DowngradeListReferenceAssignmentRector.php | 4 +- ...wngradeContravariantArgumentTypeRector.php | 2 +- .../DowngradeCovariantReturnTypeRector.php | 2 +- ...ngradeFreadFwriteFalsyToNegationRector.php | 2 +- .../DowngradePropertyPromotionRector.php | 2 +- .../src/NodeTransformer/ConditionInverter.php | 2 +- .../If_/ChangeAndIfToEarlyReturnRector.php | 4 +- .../ClassMethod/AddMethodParentCallRector.php | 3 +- ...ertyInjectToConstructorInjectionRector.php | 3 +- .../ChangePropertyVisibilityRector.php | 3 +- ...AppArrayAccessToStandaloneAssignRector.php | 3 +- ...pertyDeferToDeferrableProviderToRector.php | 2 +- ...ngeQueryWhereDateValueWithCarbonRector.php | 2 +- ...gedPassedToParameterIterableTypeRector.php | 8 ++- .../MinutesToSecondsInCacheRector.php | 3 +- .../Class_/ChangeSingletonToServiceRector.php | 5 +- .../Rector/Class_/MockeryTearDownRector.php | 2 +- .../MysqlQueryMysqlErrorWithLinkRector.php | 2 +- .../MatchParamTypeExpectedNameResolver.php | 3 +- .../MatchPropertyTypeExpectedNameResolver.php | 3 +- .../src/Naming/ExpectedNameResolver.php | 7 ++- rules/naming/src/Naming/PropertyNaming.php | 6 +- ...etterClassMethodNameStartWithGetRector.php | 2 +- ...eIsserClassMethodNameStartWithIsRector.php | 2 +- .../RenameParamToMatchTypeRector.php | 5 +- .../RenamePropertyToMatchTypeRector.php | 9 ++- ...pertyRespectIsHasWasMethodNamingRector.php | 3 +- ...nderscoreToCamelCasePropertyNameRector.php | 3 +- ...nderscoreToCamelCaseVariableNameRector.php | 5 +- .../PropertyRenameFactory.php | 3 +- .../ArrayDimFetchControlTypeResolver.php | 2 +- ...actoryInterfaceFormControlTypeResolver.php | 5 +- .../MethodCallFormControlTypeResolver.php | 3 +- .../NewFormControlTypeResolver.php | 3 +- ...InAnotherMethodFormControlTypeResolver.php | 3 +- ...ableConstructorFormControlTypeResolver.php | 3 +- .../MoveInjectToExistingConstructorRector.php | 3 +- .../nette-kdyby/src/Naming/VariableNaming.php | 6 +- .../ListeningMethodsCollector.php | 6 +- .../AbstractKdybyEventSubscriberRector.php | 3 +- ...placeMagicPropertyWithEventClassRector.php | 3 +- ...MagicPropertyEventWithEventClassRector.php | 3 +- .../NetteTesterClassToPHPUnitClassRector.php | 3 +- .../OnFormVariableMethodCallsCollector.php | 2 +- ...enameEventNamesInEventSubscriberRector.php | 12 ++-- ...outerListToControllerAnnotationsRector.php | 6 +- ...rmControlToControllerAndFormTypeRector.php | 5 +- .../NetteFormToSymfonyFormRector.php | 3 +- .../src/Route/RouteInfoFactory.php | 5 +- ...erToCheckRequirementsClassMethodRector.php | 3 +- ...tWithFunctionToNetteUtilsStringsRector.php | 2 +- ...ddNextrasDatePickerToDateControlRector.php | 2 +- .../StrposToStringsContainsRector.php | 2 +- .../Class_/OrderPrivateMethodsByUseRector.php | 2 +- .../MethodCall/IncreaseColumnIndexRector.php | 2 +- .../src/MatchersManipulator.php | 3 +- .../Rector/AbstractPhpSpecToPHPUnitRector.php | 3 +- .../PhpSpecClassToPHPUnitClassRector.php | 2 +- .../FuncCall/PregReplaceEModifierRector.php | 6 +- ...DefaultValueForUndefinedVariableRector.php | 2 +- .../ClassMethod/Php4ConstructorRector.php | 2 +- ...VariableToVariableOnFunctionCallRector.php | 3 +- ...ticCallOnNonStaticToInstanceCallRector.php | 6 +- .../Ternary/TernaryToNullCoalescingRector.php | 3 +- rules/php71/src/IsArrayAndDualCheckToAble.php | 3 +- .../FuncCall/RemoveExtraParametersRector.php | 2 +- .../FuncCall/ArrayKeyFirstLastRector.php | 2 +- ...eReflectionTypeToStringToGetNameRector.php | 3 +- .../src/NodeManipulator/TokenManipulator.php | 2 +- .../NodeResolver/PromotedPropertyResolver.php | 8 +-- .../src/NodeResolver/SwitchExprsResolver.php | 2 +- .../RemoveUnusedVariableInCatchRector.php | 2 +- ...ertyAssignToConstructorPromotionRector.php | 3 +- .../Class_/StringableForToStringRector.php | 3 +- .../Rector/Identical/StrStartsWithRector.php | 3 +- .../src/Rector/If_/NullsafeOperatorRector.php | 8 +-- .../Rector/NotIdentical/StrContainsRector.php | 2 +- .../Switch_/ChangeSwitchToMatchRector.php | 2 +- .../AddMessageToEqualsResponseCodeRector.php | 2 +- .../src/NodeAnalyzer/TestsNodeAnalyzer.php | 3 +- ...rformAssertionToNonAssertingTestRector.php | 3 +- .../TryCatchToExpectExceptionRector.php | 2 +- ...rrayArgumentInTestToDataProviderRector.php | 3 +- ...structClassMethodToSetUpTestCaseRector.php | 2 +- .../WithConsecutiveArgToArrayRector.php | 5 +- rules/polyfill/src/ConditionResolver.php | 4 +- ...wrapFutureCompatibleIfPhpVersionRector.php | 3 +- .../ClassMethodExternalCallNodeAnalyzer.php | 2 +- .../ParentClassConstantNodeFinder.php | 3 +- .../PropertyFetchWithVariableReplacer.php | 3 +- .../PrivatizeLocalClassConstantRector.php | 3 +- ...riableWithDefaultValueToConstantRector.php | 2 +- .../ReplaceStringWithClassConstantRector.php | 6 +- ...zeLocalPropertyToPrivatePropertyRector.php | 2 +- .../src/Composer/PSR4NamespaceMatcher.php | 2 +- ...llyCalledStaticMethodToNonStaticRector.php | 2 +- .../DesiredClassTypeToDynamicRector.php | 2 +- .../src/NodeManipulator/ClassRenamer.php | 2 +- .../Namespace_/RenameNamespaceRector.php | 6 +- .../InferParamFromClassMethodReturnRector.php | 4 +- .../CompleteMissingDependencyInNewRector.php | 5 +- .../Use_/RestoreFullyQualifiedNameRector.php | 6 +- rules/sensio/src/BundleClassResolver.php | 3 +- .../ReturnTypeDeclarationUpdater.php | 3 +- .../src/ConstantNameAndValueResolver.php | 2 +- ...tractAttributeRouteNameConstantsRector.php | 3 +- .../AutoInPhpSymfonyConfigRector.php | 2 +- ...tMethodCallFromTestToSetUpMethodRector.php | 3 +- .../Rector/Class_/MakeCommandLazyRector.php | 9 +-- .../src/ValueObject/ServiceMap/ServiceMap.php | 2 +- .../src/Rector/StaticCall/ParseFileRector.php | 3 +- .../FormTypeStringToTypeProvider.php | 3 +- .../Rector/ClassMethod/GetRequestRector.php | 2 +- ...ethodAnnotationToRouteAnnotationRector.php | 3 +- .../RemoveDefaultGetBlockPrefixRector.php | 2 +- ...ypeOptionNameFromTypeToEntryTypeRector.php | 2 +- ...StringCollectionOptionToConstantRector.php | 3 +- .../FormTypeInstanceToClassConstRector.php | 11 ++-- .../Rector/MethodCall/OptionNameRector.php | 3 +- .../ReadOnlyOptionToAttributeRector.php | 5 +- .../Rector/MethodCall/FormIsValidRector.php | 2 +- .../SimplifyWebTestCaseAssertionsRector.php | 3 +- .../StringToArrayArgumentProcessRector.php | 2 +- .../Rector/Assign/PropertyToMethodRector.php | 4 +- .../ArgumentFuncCallToMethodCallRector.php | 3 +- ...viceGetterToConstructorInjectionRector.php | 3 +- .../New_/NewToConstructorInjectionRector.php | 3 +- .../Return_/SimpleFunctionAndFilterRector.php | 3 +- .../ConstructorAssignDetector.php | 3 +- .../NullTypeAssignDetector.php | 3 +- .../ChildPopulator/ChildParamPopulator.php | 2 +- .../ChildPopulator/ChildReturnPopulator.php | 2 +- .../NonInformativeReturnTagRemover.php | 4 +- .../AddParamTypeDeclarationRector.php | 2 +- ...lipTypeControlToUseExclusiveTypeRector.php | 12 +++- .../TypeAnalyzer/AdvancedArrayAnalyzer.php | 2 +- .../AssignToPropertyTypeInferer.php | 5 +- .../FunctionLikeDocParamTypeInferer.php | 2 +- .../PHPUnitDataProviderParamTypeInferer.php | 2 +- .../ConstructorPropertyTypeInferer.php | 4 +- .../DoctrineColumnPropertyTypeInferer.php | 4 +- .../DoctrineRelationPropertyTypeInferer.php | 4 +- ...eMethodAssignedNodePropertyTypeInferer.php | 4 +- .../SetterNodeReturnTypeInferer.php | 3 +- .../YieldNodesReturnTypeInferer.php | 2 +- .../Fixture/nullable_type.php.inc | 55 +++++++++++++++++++ src/Comments/CommentableNodeResolver.php | 2 +- src/Console/Command/AbstractCommand.php | 3 +- src/Context/ContextAnalyzer.php | 4 +- src/Exclusion/ExclusionManager.php | 2 +- src/NodeAnalyzer/PromotedPropertyResolver.php | 3 +- ...stantArrayTypeToCallReflectionResolver.php | 2 +- .../Regex/RegexPatternArgumentManipulator.php | 6 +- src/PhpParser/Node/BetterNodeFinder.php | 2 +- .../Node/Manipulator/ArrayManipulator.php | 2 +- .../ChildAndParentClassManipulator.php | 4 +- .../Manipulator/ClassConstManipulator.php | 3 +- .../ClassMethodAssignManipulator.php | 5 +- .../Manipulator/PropertyFetchManipulator.php | 3 +- src/PhpParser/Node/Value/ValueResolver.php | 3 +- src/PhpParser/NodeTransformer.php | 2 +- src/Rector/AbstractRector.php | 4 +- .../ClassMethodReflectionFactory.php | 2 +- .../ClassMethodReflectionHelper.php | 3 +- .../ClassReflectionToAstResolver.php | 2 +- 274 files changed, 597 insertions(+), 388 deletions(-) create mode 100644 rules/type-declaration/tests/Rector/Identical/FlipTypeControlToUseExclusiveTypeRector/Fixture/nullable_type.php.inc diff --git a/packages/better-php-doc-parser/src/AnnotationReader/NodeAnnotationReader.php b/packages/better-php-doc-parser/src/AnnotationReader/NodeAnnotationReader.php index 0e6f50d69047..74d1e8c22044 100644 --- a/packages/better-php-doc-parser/src/AnnotationReader/NodeAnnotationReader.php +++ b/packages/better-php-doc-parser/src/AnnotationReader/NodeAnnotationReader.php @@ -87,7 +87,7 @@ public function readClassAnnotation(Class_ $class, string $annotationClassName): public function readPropertyAnnotation(Property $property, string $annotationClassName): ?object { $propertyReflection = $this->createPropertyReflectionFromPropertyNode($property); - if ($propertyReflection === null) { + if (! $propertyReflection instanceof ReflectionProperty) { return null; } diff --git a/packages/better-php-doc-parser/src/PhpDocInfo/PhpDocInfoFactory.php b/packages/better-php-doc-parser/src/PhpDocInfo/PhpDocInfoFactory.php index 6958ead830c6..9b58c0c0e5f6 100644 --- a/packages/better-php-doc-parser/src/PhpDocInfo/PhpDocInfoFactory.php +++ b/packages/better-php-doc-parser/src/PhpDocInfo/PhpDocInfoFactory.php @@ -4,6 +4,7 @@ namespace Rector\BetterPhpDocParser\PhpDocInfo; +use PhpParser\Comment\Doc; use PhpParser\Node; use PHPStan\PhpDocParser\Lexer\Lexer; use PHPStan\PhpDocParser\Parser\PhpDocParser; @@ -98,7 +99,7 @@ public function createFromNode(Node $node): ?PhpDocInfo $this->currentNodeProvider->setNode($node); $docComment = $node->getDocComment(); - if ($docComment === null) { + if (! $docComment instanceof Doc) { if ($node->getComments() !== []) { return null; } diff --git a/packages/better-php-doc-parser/src/PhpDocManipulator/PhpDocTypeChanger.php b/packages/better-php-doc-parser/src/PhpDocManipulator/PhpDocTypeChanger.php index 524ab6fd2011..b0234c1a71b9 100644 --- a/packages/better-php-doc-parser/src/PhpDocManipulator/PhpDocTypeChanger.php +++ b/packages/better-php-doc-parser/src/PhpDocManipulator/PhpDocTypeChanger.php @@ -4,6 +4,7 @@ namespace Rector\BetterPhpDocParser\PhpDocManipulator; +use PhpParser\Node; use PhpParser\Node\Param; use PHPStan\Type\Constant\ConstantArrayType; use PHPStan\Type\MixedType; @@ -143,7 +144,7 @@ public function changeParamType(PhpDocInfo $phpDocInfo, Type $newType, Param $pa private function notifyChange(): void { $node = $this->currentNodeProvider->getNode(); - if ($node === null) { + if (! $node instanceof Node) { throw new ShouldNotHappenException(); } diff --git a/packages/better-php-doc-parser/src/PhpDocParser/BetterPhpDocParser.php b/packages/better-php-doc-parser/src/PhpDocParser/BetterPhpDocParser.php index e3e0fa2e3afd..9dbb65d01be2 100644 --- a/packages/better-php-doc-parser/src/PhpDocParser/BetterPhpDocParser.php +++ b/packages/better-php-doc-parser/src/PhpDocParser/BetterPhpDocParser.php @@ -176,7 +176,7 @@ public function parseTagValue(TokenIterator $tokenIterator, string $tag): PhpDoc $tagValueNode = null; $currentPhpNode = $this->currentNodeProvider->getNode(); - if ($currentPhpNode === null) { + if (! $currentPhpNode instanceof \PhpParser\Node) { throw new ShouldNotHappenException(); } @@ -297,7 +297,7 @@ private function resolveTag(TokenIterator $tokenIterator): string private function matchTagToPhpDocNodeFactory(string $tag): ?PhpDocNodeFactoryInterface { $currentPhpNode = $this->currentNodeProvider->getNode(); - if ($currentPhpNode === null) { + if (! $currentPhpNode instanceof \PhpParser\Node) { throw new ShouldNotHappenException(); } diff --git a/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/Class_/TableTagValueNode.php b/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/Class_/TableTagValueNode.php index bd3a88d4eb37..7a6001213f20 100644 --- a/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/Class_/TableTagValueNode.php +++ b/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/Class_/TableTagValueNode.php @@ -102,7 +102,7 @@ public function getSilentKey(): string private function addCustomItems(array $items): array { if ($this->indexes !== []) { - if ($this->indexesAroundSpaces === null) { + if (! $this->indexesAroundSpaces instanceof AroundSpaces) { throw new ShouldNotHappenException(); } @@ -115,7 +115,7 @@ private function addCustomItems(array $items): array } if ($this->uniqueConstraints !== []) { - if ($this->uniqueConstraintsAroundSpaces === null) { + if (! $this->uniqueConstraintsAroundSpaces instanceof AroundSpaces) { throw new ShouldNotHappenException(); } diff --git a/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/Property_/JoinTableTagValueNode.php b/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/Property_/JoinTableTagValueNode.php index 65092fed33d2..a6b4940fe807 100644 --- a/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/Property_/JoinTableTagValueNode.php +++ b/packages/better-php-doc-parser/src/ValueObject/PhpDocNode/Doctrine/Property_/JoinTableTagValueNode.php @@ -155,7 +155,7 @@ private function createJoinColumnItems(string $joinColumnsKey, string $inverseJo $items = []; if ($this->joinColumns !== []) { - if ($this->joinColumnsAroundSpaces === null) { + if (! $this->joinColumnsAroundSpaces instanceof AroundSpaces) { throw new ShouldNotHappenException(); } @@ -168,7 +168,7 @@ private function createJoinColumnItems(string $joinColumnsKey, string $inverseJo } if ($this->inverseJoinColumns !== []) { - if ($this->inverseJoinColumnsAroundSpaces === null) { + if (! $this->inverseJoinColumnsAroundSpaces instanceof AroundSpaces) { throw new ShouldNotHappenException(); } diff --git a/packages/better-php-doc-parser/tests/PhpDocParser/AbstractPhpDocInfoTest.php b/packages/better-php-doc-parser/tests/PhpDocParser/AbstractPhpDocInfoTest.php index a11fbc180c6b..f24b093fa322 100644 --- a/packages/better-php-doc-parser/tests/PhpDocParser/AbstractPhpDocInfoTest.php +++ b/packages/better-php-doc-parser/tests/PhpDocParser/AbstractPhpDocInfoTest.php @@ -5,6 +5,7 @@ namespace Rector\BetterPhpDocParser\Tests\PhpDocParser; use Iterator; +use PhpParser\Comment\Doc; use PhpParser\Node; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\BetterPhpDocParser\Printer\PhpDocInfoPrinter; @@ -69,7 +70,7 @@ protected function doTestPrintedPhpDocInfo(SmartFileInfo $fileInfo, string $tagV $nodeWithPhpDocInfo = $this->parseFileAndGetFirstNodeOfType($fileInfo, $nodeType); $docComment = $nodeWithPhpDocInfo->getDocComment(); - if ($docComment === null) { + if (! $docComment instanceof Doc) { throw new ShouldNotHappenException(sprintf('Doc comments for "%s" file cannot not be empty', $fileInfo)); } diff --git a/packages/changes-reporting/src/Collector/RectorChangeCollector.php b/packages/changes-reporting/src/Collector/RectorChangeCollector.php index 44fd6ee493af..bf2cd5018d3f 100644 --- a/packages/changes-reporting/src/Collector/RectorChangeCollector.php +++ b/packages/changes-reporting/src/Collector/RectorChangeCollector.php @@ -45,14 +45,14 @@ function (RectorWithFileAndLineChange $rectorWithFileAndLineChange) use ($smartF public function notifyNodeFileInfo(Node $node): void { $fileInfo = $node->getAttribute(AttributeKey::FILE_INFO); - if ($fileInfo === null) { + if (! $fileInfo instanceof SmartFileInfo) { // this file was changed before and this is a sub-new node // array Traverse to all new nodes would have to be used, but it's not worth the performance return; } $currentRector = $this->currentRectorProvider->getCurrentRector(); - if ($currentRector === null) { + if (! $currentRector instanceof RectorInterface) { throw new ShouldNotHappenException(); } diff --git a/packages/family-tree/src/NodeAnalyzer/ClassChildAnalyzer.php b/packages/family-tree/src/NodeAnalyzer/ClassChildAnalyzer.php index 199ba5220fe6..32c3d79f2e00 100644 --- a/packages/family-tree/src/NodeAnalyzer/ClassChildAnalyzer.php +++ b/packages/family-tree/src/NodeAnalyzer/ClassChildAnalyzer.php @@ -7,6 +7,7 @@ use PhpParser\Node\Stmt\Class_; use Rector\NodeTypeResolver\Node\AttributeKey; use ReflectionClass; +use ReflectionMethod; final class ClassChildAnalyzer { @@ -21,7 +22,7 @@ public function hasChildClassConstructor(Class_ $class): bool $reflectionClass = new ReflectionClass($childClass); $constructorReflectionMethod = $reflectionClass->getConstructor(); - if ($constructorReflectionMethod === null) { + if (! $constructorReflectionMethod instanceof ReflectionMethod) { continue; } @@ -48,7 +49,7 @@ public function hasParentClassConstructor(Class_ $class): bool foreach ($classParents as $classParent) { $parentReflectionClass = new ReflectionClass($classParent); $constructMethodReflection = $parentReflectionClass->getConstructor(); - if ($constructMethodReflection === null) { + if (! $constructMethodReflection instanceof ReflectionMethod) { continue; } diff --git a/packages/family-tree/src/NodeAnalyzer/PropertyUsageAnalyzer.php b/packages/family-tree/src/NodeAnalyzer/PropertyUsageAnalyzer.php index 0626e8aa5e97..ce90d84f3fff 100644 --- a/packages/family-tree/src/NodeAnalyzer/PropertyUsageAnalyzer.php +++ b/packages/family-tree/src/NodeAnalyzer/PropertyUsageAnalyzer.php @@ -64,7 +64,7 @@ public function isPropertyFetchedInChildClass(Property $property): bool $childrenClassNames = $this->familyRelationsAnalyzer->getChildrenOfClass($className); foreach ($childrenClassNames as $childClassName) { $childClass = $this->nodeRepository->findClass($childClassName); - if ($childClass === null) { + if (! $childClass instanceof Class_) { continue; } diff --git a/packages/node-collector/src/NodeCollector/NodeRepository.php b/packages/node-collector/src/NodeCollector/NodeRepository.php index c9623df7fd0c..8305f58485dc 100644 --- a/packages/node-collector/src/NodeCollector/NodeRepository.php +++ b/packages/node-collector/src/NodeCollector/NodeRepository.php @@ -147,7 +147,7 @@ public function collect(Node $node): void // array callable - [$this, 'someCall'] if ($node instanceof Array_) { $arrayCallable = $this->arrayCallableMethodReferenceAnalyzer->match($node); - if ($arrayCallable === null) { + if (! $arrayCallable instanceof ArrayCallable) { return; } diff --git a/packages/node-collector/src/Reflection/MethodReflectionProvider.php b/packages/node-collector/src/Reflection/MethodReflectionProvider.php index 3a285f042af6..bd4b6dc35edb 100644 --- a/packages/node-collector/src/Reflection/MethodReflectionProvider.php +++ b/packages/node-collector/src/Reflection/MethodReflectionProvider.php @@ -86,7 +86,7 @@ public function provideByClassAndMethodName(string $class, string $method, Scope public function provideParameterTypesByStaticCall(StaticCall $staticCall): array { $methodReflection = $this->provideByStaticCall($staticCall); - if ($methodReflection === null) { + if (! $methodReflection instanceof MethodReflection) { return []; } @@ -120,7 +120,7 @@ public function provideByStaticCall(StaticCall $staticCall): ?MethodReflection public function provideParameterTypesByClassMethod(ClassMethod $classMethod): array { $methodReflection = $this->provideByClassMethod($classMethod); - if ($methodReflection === null) { + if (! $methodReflection instanceof MethodReflection) { return []; } diff --git a/packages/node-nesting-scope/src/ScopeNestingComparator.php b/packages/node-nesting-scope/src/ScopeNestingComparator.php index 42bca99cb7ff..59d99f9f6981 100644 --- a/packages/node-nesting-scope/src/ScopeNestingComparator.php +++ b/packages/node-nesting-scope/src/ScopeNestingComparator.php @@ -43,7 +43,7 @@ public function isNodeConditionallyScoped(Node $node): bool ControlStructure::CONDITIONAL_NODE_SCOPE_TYPES + [FunctionLike::class] ); - if ($foundParentType === null) { + if (! $foundParentType instanceof Node) { return false; } diff --git a/packages/node-type-resolver/src/NodeTypeResolver.php b/packages/node-type-resolver/src/NodeTypeResolver.php index 8c5f5004db1e..32f8dffd738d 100644 --- a/packages/node-type-resolver/src/NodeTypeResolver.php +++ b/packages/node-type-resolver/src/NodeTypeResolver.php @@ -293,7 +293,7 @@ public function isPropertyBoolean(Property $property): bool } $defaultNodeValue = $property->props[0]->default; - if ($defaultNodeValue === null) { + if (! $defaultNodeValue instanceof \PhpParser\Node\Expr) { return false; } diff --git a/packages/node-type-resolver/src/NodeTypeResolver/ClassMethodOrClassConstTypeResolver.php b/packages/node-type-resolver/src/NodeTypeResolver/ClassMethodOrClassConstTypeResolver.php index 7109465ec1ae..b63db658d675 100644 --- a/packages/node-type-resolver/src/NodeTypeResolver/ClassMethodOrClassConstTypeResolver.php +++ b/packages/node-type-resolver/src/NodeTypeResolver/ClassMethodOrClassConstTypeResolver.php @@ -7,6 +7,7 @@ use PhpParser\Node; use PhpParser\Node\Param; use PhpParser\Node\Stmt\ClassConst; +use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\ClassMethod; use PHPStan\Type\ObjectWithoutClassType; use PHPStan\Type\Type; @@ -43,7 +44,7 @@ public function getNodeClasses(): array public function resolve(Node $node): Type { $classLike = $node->getAttribute(AttributeKey::CLASS_NODE); - if ($classLike === null) { + if (! $classLike instanceof ClassLike) { // anonymous class return new ObjectWithoutClassType(); } diff --git a/packages/node-type-resolver/src/NodeTypeResolver/ParamTypeResolver.php b/packages/node-type-resolver/src/NodeTypeResolver/ParamTypeResolver.php index c4a2a62a760c..e256035e9c4b 100644 --- a/packages/node-type-resolver/src/NodeTypeResolver/ParamTypeResolver.php +++ b/packages/node-type-resolver/src/NodeTypeResolver/ParamTypeResolver.php @@ -9,6 +9,7 @@ use PhpParser\Node\FunctionLike; use PhpParser\Node\Identifier; use PhpParser\Node\Param; +use PhpParser\Node\Stmt\ClassMethod; use PhpParser\NodeTraverser; use PHPStan\Type\MixedType; use PHPStan\Type\Type; @@ -115,7 +116,7 @@ private function resolveFromParamType(Param $param): Type private function resolveFromFirstVariableUse(Param $param): Type { $classMethod = $param->getAttribute(AttributeKey::METHOD_NODE); - if ($classMethod === null) { + if (! $classMethod instanceof ClassMethod) { return new MixedType(); } diff --git a/packages/node-type-resolver/src/NodeTypeResolver/PropertyFetchTypeResolver.php b/packages/node-type-resolver/src/NodeTypeResolver/PropertyFetchTypeResolver.php index 281c22612aa1..c753200f2750 100644 --- a/packages/node-type-resolver/src/NodeTypeResolver/PropertyFetchTypeResolver.php +++ b/packages/node-type-resolver/src/NodeTypeResolver/PropertyFetchTypeResolver.php @@ -113,14 +113,14 @@ public function resolve(Node $node): Type } } - if ($scope === null) { + if (! $scope instanceof Scope) { $classNode = $node->getAttribute(AttributeKey::CLASS_NODE); // fallback to class, since property fetches are not scoped by PHPStan if ($classNode instanceof ClassLike) { $scope = $classNode->getAttribute(AttributeKey::SCOPE); } - if ($scope === null) { + if (! $scope instanceof Scope) { return new MixedType(); } } diff --git a/packages/node-type-resolver/src/NodeTypeResolver/VariableTypeResolver.php b/packages/node-type-resolver/src/NodeTypeResolver/VariableTypeResolver.php index 949253b024c1..70a127d7e5a4 100644 --- a/packages/node-type-resolver/src/NodeTypeResolver/VariableTypeResolver.php +++ b/packages/node-type-resolver/src/NodeTypeResolver/VariableTypeResolver.php @@ -103,7 +103,7 @@ private function resolveTypesFromScope(Variable $variable, string $variableName) { $nodeScope = $this->resolveNodeScope($variable); - if ($nodeScope === null) { + if (! $nodeScope instanceof Scope) { return new MixedType(); } @@ -147,7 +147,7 @@ private function resolveFromParentNodes(Variable $variable): ?Scope } $parentNodeScope = $parentNode->getAttribute(AttributeKey::SCOPE); - if ($parentNodeScope === null) { + if (! $parentNodeScope instanceof Scope) { continue; } diff --git a/packages/node-type-resolver/src/NodeVisitor/FunctionMethodAndClassNodeVisitor.php b/packages/node-type-resolver/src/NodeVisitor/FunctionMethodAndClassNodeVisitor.php index 7a119b634e1c..10b52ab243dd 100644 --- a/packages/node-type-resolver/src/NodeVisitor/FunctionMethodAndClassNodeVisitor.php +++ b/packages/node-type-resolver/src/NodeVisitor/FunctionMethodAndClassNodeVisitor.php @@ -170,7 +170,7 @@ private function processClosure(Node $node): void private function setClassNodeAndName(?ClassLike $classLike): void { $this->classLike = $classLike; - if ($classLike === null || $classLike->name === null) { + if (! $classLike instanceof ClassLike || $classLike->name === null) { $this->className = null; } elseif (property_exists($classLike, 'namespacedName')) { $this->className = $classLike->namespacedName->toString(); diff --git a/packages/node-type-resolver/src/NodeVisitor/StatementNodeVisitor.php b/packages/node-type-resolver/src/NodeVisitor/StatementNodeVisitor.php index dd4e3e70d5b7..456347b4b4d7 100644 --- a/packages/node-type-resolver/src/NodeVisitor/StatementNodeVisitor.php +++ b/packages/node-type-resolver/src/NodeVisitor/StatementNodeVisitor.php @@ -30,7 +30,7 @@ public function beforeTraverse(array $nodes): ?array public function enterNode(Node $node): ?Node { $parent = $node->getAttribute(AttributeKey::PARENT_NODE); - if ($parent === null) { + if (! $parent instanceof Node) { if (! $node instanceof Stmt) { return null; } diff --git a/packages/phpstan-static-type-mapper/src/TypeMapper/UnionTypeMapper.php b/packages/phpstan-static-type-mapper/src/TypeMapper/UnionTypeMapper.php index 530612a124f3..e7adfac98765 100644 --- a/packages/phpstan-static-type-mapper/src/TypeMapper/UnionTypeMapper.php +++ b/packages/phpstan-static-type-mapper/src/TypeMapper/UnionTypeMapper.php @@ -27,6 +27,7 @@ use Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper; use Rector\PHPStanStaticTypeMapper\TypeAnalyzer\BoolUnionTypeAnalyzer; use Rector\PHPStanStaticTypeMapper\TypeAnalyzer\UnionTypeAnalyzer; +use Rector\PHPStanStaticTypeMapper\ValueObject\UnionTypeAnalysis; final class UnionTypeMapper implements TypeMapperInterface { @@ -119,7 +120,7 @@ public function mapToPhpParserNode(Type $type, ?string $kind = null): ?Node // special case for nullable $nullabledType = $this->matchTypeForNullableUnionType($type); - if ($nullabledType === null) { + if (! $nullabledType instanceof Type) { // use first unioned type in case of unioned object types return $this->matchTypeForUnionedObjectTypes($type); } @@ -166,7 +167,7 @@ public function mapToDocString(Type $type, ?Type $parentType = null): string private function shouldSkipIterable(UnionType $unionType): bool { $unionTypeAnalysis = $this->unionTypeAnalyzer->analyseForNullableAndIterable($unionType); - if ($unionTypeAnalysis === null) { + if (! $unionTypeAnalysis instanceof UnionTypeAnalysis) { return false; } if (! $unionTypeAnalysis->hasIterable()) { @@ -181,7 +182,7 @@ private function shouldSkipIterable(UnionType $unionType): bool private function matchArrayTypes(UnionType $unionType): ?Node { $unionTypeAnalysis = $this->unionTypeAnalyzer->analyseForNullableAndIterable($unionType); - if ($unionTypeAnalysis === null) { + if (! $unionTypeAnalysis instanceof UnionTypeAnalysis) { return null; } diff --git a/packages/post-rector/src/Collector/UseNodesToAddCollector.php b/packages/post-rector/src/Collector/UseNodesToAddCollector.php index 99b86be98c89..d3ebebef2cf5 100644 --- a/packages/post-rector/src/Collector/UseNodesToAddCollector.php +++ b/packages/post-rector/src/Collector/UseNodesToAddCollector.php @@ -52,10 +52,10 @@ public function addUseImport(Node $positionNode, ObjectType $objectType): void { /** @var SmartFileInfo|null $fileInfo */ $fileInfo = $positionNode->getAttribute(AttributeKey::FILE_INFO); - if ($fileInfo === null) { + if (! $fileInfo instanceof \Symplify\SmartFileSystem\SmartFileInfo) { // fallback for freshly created Name nodes $fileInfo = $this->currentFileInfoProvider->getSmartFileInfo(); - if ($fileInfo === null) { + if (! $fileInfo instanceof \Symplify\SmartFileSystem\SmartFileInfo) { return; } } @@ -187,7 +187,7 @@ private function getRealPathFromNode(Node $node): ?string } $smartFileInfo = $this->currentFileInfoProvider->getSmartFileInfo(); - if ($smartFileInfo === null) { + if (! $smartFileInfo instanceof \Symplify\SmartFileSystem\SmartFileInfo) { return null; } diff --git a/packages/post-rector/src/Rector/UseAddingPostRector.php b/packages/post-rector/src/Rector/UseAddingPostRector.php index 2f222b05a2cf..d1eef7723e5d 100644 --- a/packages/post-rector/src/Rector/UseAddingPostRector.php +++ b/packages/post-rector/src/Rector/UseAddingPostRector.php @@ -73,7 +73,7 @@ public function beforeTraverse(array $nodes): array } $smartFileInfo = $this->getSmartFileInfo($nodes); - if ($smartFileInfo === null) { + if (! $smartFileInfo instanceof SmartFileInfo) { return $nodes; } diff --git a/packages/read-write/src/NodeAnalyzer/ReadWritePropertyAnalyzer.php b/packages/read-write/src/NodeAnalyzer/ReadWritePropertyAnalyzer.php index 0ba8edfb2949..63c2fac98ebe 100644 --- a/packages/read-write/src/NodeAnalyzer/ReadWritePropertyAnalyzer.php +++ b/packages/read-write/src/NodeAnalyzer/ReadWritePropertyAnalyzer.php @@ -64,7 +64,7 @@ public function isRead(Node $node): bool Assert::isAnyOf($node, [PropertyFetch::class, StaticPropertyFetch::class]); $parent = $node->getAttribute(AttributeKey::PARENT_NODE); - if ($parent === null) { + if (! $parent instanceof Node) { throw new MissingParentNodeException(); } @@ -93,7 +93,7 @@ private function unwrapPostPreIncDec(Node $node): Node { if ($node instanceof PreInc || $node instanceof PreDec || $node instanceof PostInc || $node instanceof PostDec) { $node = $node->getAttribute(AttributeKey::PARENT_NODE); - if ($node === null) { + if (! $node instanceof Node) { throw new MissingParentNodeException(); } } @@ -104,7 +104,7 @@ private function unwrapPostPreIncDec(Node $node): Node private function isArrayDimFetchRead(ArrayDimFetch $arrayDimFetch): bool { $parentParent = $arrayDimFetch->getAttribute(AttributeKey::PARENT_NODE); - if ($parentParent === null) { + if (! $parentParent instanceof Node) { throw new MissingParentNodeException(); } diff --git a/packages/rector-generator/src/Provider/RectorRecipeProvider.php b/packages/rector-generator/src/Provider/RectorRecipeProvider.php index e89d2075cb51..a8c4fb2f7049 100644 --- a/packages/rector-generator/src/Provider/RectorRecipeProvider.php +++ b/packages/rector-generator/src/Provider/RectorRecipeProvider.php @@ -29,7 +29,7 @@ public function __construct(?RectorRecipe $rectorRecipe = null) public function provide(): RectorRecipe { - if ($this->rectorRecipe === null) { + if (! $this->rectorRecipe instanceof RectorRecipe) { throw new ConfigurationException(self::MESSAGE); } diff --git a/packages/vendor-locker/src/NodeVendorLocker/ClassMethodReturnVendorLockResolver.php b/packages/vendor-locker/src/NodeVendorLocker/ClassMethodReturnVendorLockResolver.php index c4848fb325f2..82821b4b3872 100644 --- a/packages/vendor-locker/src/NodeVendorLocker/ClassMethodReturnVendorLockResolver.php +++ b/packages/vendor-locker/src/NodeVendorLocker/ClassMethodReturnVendorLockResolver.php @@ -5,6 +5,7 @@ namespace Rector\VendorLocker\NodeVendorLocker; use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Interface_; use Rector\NodeTypeResolver\Node\AttributeKey; @@ -14,7 +15,7 @@ final class ClassMethodReturnVendorLockResolver extends AbstractNodeVendorLockRe public function isVendorLocked(ClassMethod $classMethod): bool { $classNode = $classMethod->getAttribute(AttributeKey::CLASS_NODE); - if ($classNode === null) { + if (! $classNode instanceof ClassLike) { return false; } diff --git a/rules/autodiscovery/src/Analyzer/ClassAnalyzer.php b/rules/autodiscovery/src/Analyzer/ClassAnalyzer.php index fc3163dca8f6..c002c49388e7 100644 --- a/rules/autodiscovery/src/Analyzer/ClassAnalyzer.php +++ b/rules/autodiscovery/src/Analyzer/ClassAnalyzer.php @@ -5,6 +5,7 @@ namespace Rector\Autodiscovery\Analyzer; use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Stmt\ClassMethod; use PHPStan\Type\ObjectType; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\JMS\SerializerTypeTagValueNode; @@ -67,7 +68,7 @@ public function isValueObjectClass(Class_ $class): bool $constructClassMethod = $class->getMethod(MethodName::CONSTRUCT); - if ($constructClassMethod === null) { + if (! $constructClassMethod instanceof ClassMethod) { return $this->analyseWithoutConstructor($class, $className); } @@ -81,7 +82,7 @@ public function isValueObjectClass(Class_ $class): bool // awesome! // is it services or value object? $paramTypeClass = $this->parsedNodeCollector->findClass($paramType->getClassName()); - if ($paramTypeClass === null) { + if (! $paramTypeClass instanceof Class_) { // not sure :/ continue; } diff --git a/rules/autodiscovery/src/Rector/FileNode/MoveEntitiesToEntityDirectoryRector.php b/rules/autodiscovery/src/Rector/FileNode/MoveEntitiesToEntityDirectoryRector.php index c1f013b2a94d..83c78de84be5 100644 --- a/rules/autodiscovery/src/Rector/FileNode/MoveEntitiesToEntityDirectoryRector.php +++ b/rules/autodiscovery/src/Rector/FileNode/MoveEntitiesToEntityDirectoryRector.php @@ -9,6 +9,7 @@ use PhpParser\Node\Stmt\Class_; use Rector\Core\PhpParser\Node\CustomNode\FileNode; use Rector\Core\Rector\AbstractRector; +use Rector\FileSystemRector\ValueObject\MovedFileWithNodes; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -92,7 +93,7 @@ public function refactor(Node $node): ?Node $node->stmts, 'Entity' ); - if ($movedFileWithNodes === null) { + if (! $movedFileWithNodes instanceof MovedFileWithNodes) { return null; } diff --git a/rules/autodiscovery/src/Rector/FileNode/MoveInterfacesToContractNamespaceDirectoryRector.php b/rules/autodiscovery/src/Rector/FileNode/MoveInterfacesToContractNamespaceDirectoryRector.php index 67ab5348050c..49ade97a4f63 100644 --- a/rules/autodiscovery/src/Rector/FileNode/MoveInterfacesToContractNamespaceDirectoryRector.php +++ b/rules/autodiscovery/src/Rector/FileNode/MoveInterfacesToContractNamespaceDirectoryRector.php @@ -8,6 +8,7 @@ use PhpParser\Node\Stmt\Interface_; use Rector\Core\PhpParser\Node\CustomNode\FileNode; use Rector\Core\Rector\AbstractRector; +use Rector\FileSystemRector\ValueObject\MovedFileWithNodes; use Rector\NetteToSymfony\Analyzer\NetteControlFactoryInterfaceAnalyzer; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -85,7 +86,7 @@ public function refactor(Node $node): ?Node $node->stmts, 'Contract' ); - if ($movedFileWithNodes === null) { + if (! $movedFileWithNodes instanceof MovedFileWithNodes) { return null; } diff --git a/rules/autodiscovery/src/Rector/FileNode/MoveServicesBySuffixToDirectoryRector.php b/rules/autodiscovery/src/Rector/FileNode/MoveServicesBySuffixToDirectoryRector.php index 14fbdd1dbbd3..827686107e3a 100644 --- a/rules/autodiscovery/src/Rector/FileNode/MoveServicesBySuffixToDirectoryRector.php +++ b/rules/autodiscovery/src/Rector/FileNode/MoveServicesBySuffixToDirectoryRector.php @@ -10,6 +10,7 @@ use Rector\Core\Contract\Rector\ConfigurableRectorInterface; use Rector\Core\PhpParser\Node\CustomNode\FileNode; use Rector\Core\Rector\AbstractRector; +use Rector\FileSystemRector\ValueObject\MovedFileWithNodes; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; use Symplify\SmartFileSystem\SmartFileInfo; @@ -159,7 +160,7 @@ private function moveFileToGroupName(SmartFileInfo $fileInfo, FileNode $fileNode $fileNode->stmts, $desiredGroupName ); - if ($movedFileWithNodes === null) { + if (! $movedFileWithNodes instanceof MovedFileWithNodes) { return; } diff --git a/rules/autodiscovery/src/Rector/FileNode/MoveValueObjectsToValueObjectDirectoryRector.php b/rules/autodiscovery/src/Rector/FileNode/MoveValueObjectsToValueObjectDirectoryRector.php index b38d1d9267e9..96b67e8f3090 100644 --- a/rules/autodiscovery/src/Rector/FileNode/MoveValueObjectsToValueObjectDirectoryRector.php +++ b/rules/autodiscovery/src/Rector/FileNode/MoveValueObjectsToValueObjectDirectoryRector.php @@ -11,6 +11,7 @@ use Rector\Core\Contract\Rector\ConfigurableRectorInterface; use Rector\Core\PhpParser\Node\CustomNode\FileNode; use Rector\Core\Rector\AbstractRector; +use Rector\FileSystemRector\ValueObject\MovedFileWithNodes; use Rector\NodeTypeResolver\Node\AttributeKey; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -151,7 +152,7 @@ public function refactor(Node $node): ?Node 'ValueObject' ); - if ($movedFileWithNodes === null) { + if (! $movedFileWithNodes instanceof MovedFileWithNodes) { return null; } diff --git a/rules/cakephp/src/Rector/MethodCall/ArrayToFluentCallRector.php b/rules/cakephp/src/Rector/MethodCall/ArrayToFluentCallRector.php index 57ca55a9678f..382e01170fdd 100644 --- a/rules/cakephp/src/Rector/MethodCall/ArrayToFluentCallRector.php +++ b/rules/cakephp/src/Rector/MethodCall/ArrayToFluentCallRector.php @@ -101,7 +101,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { $factoryMethod = $this->matchTypeAndMethodName($node); - if ($factoryMethod === null) { + if (! $factoryMethod instanceof FactoryMethod) { return null; } diff --git a/rules/cakephp/src/Rector/MethodCall/ModalToGetSetRector.php b/rules/cakephp/src/Rector/MethodCall/ModalToGetSetRector.php index 41e32fe9f2b4..d740c81db3d8 100644 --- a/rules/cakephp/src/Rector/MethodCall/ModalToGetSetRector.php +++ b/rules/cakephp/src/Rector/MethodCall/ModalToGetSetRector.php @@ -82,7 +82,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { $unprefixedMethodToGetSet = $this->matchTypeAndMethodName($node); - if ($unprefixedMethodToGetSet === null) { + if (! $unprefixedMethodToGetSet instanceof ModalToGetSet) { return null; } diff --git a/rules/cakephp/src/Rector/MethodCall/RenameMethodCallBasedOnParameterRector.php b/rules/cakephp/src/Rector/MethodCall/RenameMethodCallBasedOnParameterRector.php index f9dfe007885c..48f33ad3b74a 100644 --- a/rules/cakephp/src/Rector/MethodCall/RenameMethodCallBasedOnParameterRector.php +++ b/rules/cakephp/src/Rector/MethodCall/RenameMethodCallBasedOnParameterRector.php @@ -78,7 +78,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { $callWithParamRename = $this->matchTypeAndMethodName($node); - if ($callWithParamRename === null) { + if (! $callWithParamRename instanceof RenameMethodCallBasedOnParameter) { return null; } diff --git a/rules/cakephp/src/Rector/Property/ChangeSnakedFixtureNameToPascalRector.php b/rules/cakephp/src/Rector/Property/ChangeSnakedFixtureNameToPascalRector.php index 76bd8b1cf5f7..0179b02d4537 100644 --- a/rules/cakephp/src/Rector/Property/ChangeSnakedFixtureNameToPascalRector.php +++ b/rules/cakephp/src/Rector/Property/ChangeSnakedFixtureNameToPascalRector.php @@ -8,6 +8,7 @@ use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Scalar\String_; +use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\Property; use PhpParser\Node\Stmt\PropertyProperty; use Rector\Core\Rector\AbstractRector; @@ -64,7 +65,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { $classLike = $node->getAttribute(AttributeKey::CLASS_NODE); - if ($classLike === null) { + if (! $classLike instanceof ClassLike) { return null; } diff --git a/rules/code-quality-strict/src/Rector/Stmt/VarInlineAnnotationToAssertRector.php b/rules/code-quality-strict/src/Rector/Stmt/VarInlineAnnotationToAssertRector.php index 4369e6e952d5..2ef17a482b45 100644 --- a/rules/code-quality-strict/src/Rector/Stmt/VarInlineAnnotationToAssertRector.php +++ b/rules/code-quality-strict/src/Rector/Stmt/VarInlineAnnotationToAssertRector.php @@ -111,7 +111,7 @@ public function refactor(Node $node): ?Node private function getVarDocVariableName(PhpDocInfo $phpDocInfo): ?string { $attributeAwareVarTagValueNode = $phpDocInfo->getVarTagValueNode(); - if ($attributeAwareVarTagValueNode === null) { + if (! $attributeAwareVarTagValueNode instanceof VarTagValueNode) { return null; } @@ -153,7 +153,7 @@ private function refactorFreshlyCreatedNode(Stmt $stmt, PhpDocInfo $phpDocInfo, $type = $phpDocInfo->getVarType(); $assertFuncCall = $this->createFuncCallBasedOnType($type, $variable); - if ($assertFuncCall === null) { + if (! $assertFuncCall instanceof FuncCall) { return null; } @@ -167,7 +167,7 @@ private function refactorFreshlyCreatedNode(Stmt $stmt, PhpDocInfo $phpDocInfo, private function refactorAlreadyCreatedNode(Stmt $stmt, PhpDocInfo $phpDocInfo, Variable $variable): ?Node { $varTagValue = $phpDocInfo->getVarTagValueNode(); - if ($varTagValue === null) { + if (! $varTagValue instanceof VarTagValueNode) { throw new ShouldNotHappenException(); } @@ -177,7 +177,7 @@ private function refactorAlreadyCreatedNode(Stmt $stmt, PhpDocInfo $phpDocInfo, ); $assertFuncCall = $this->createFuncCallBasedOnType($phpStanType, $variable); - if ($assertFuncCall === null) { + if (! $assertFuncCall instanceof FuncCall) { return null; } diff --git a/rules/code-quality/src/NodeAnalyzer/CallableClassMethodMatcher.php b/rules/code-quality/src/NodeAnalyzer/CallableClassMethodMatcher.php index a857bfff98b1..e6d47b09a34a 100644 --- a/rules/code-quality/src/NodeAnalyzer/CallableClassMethodMatcher.php +++ b/rules/code-quality/src/NodeAnalyzer/CallableClassMethodMatcher.php @@ -8,6 +8,7 @@ use PhpParser\Node\Expr\PropertyFetch; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Scalar\String_; +use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; @@ -68,13 +69,13 @@ public function match(Expr $objectExpr, String_ $string): ?ClassMethod if ($objectType instanceof ObjectType) { $class = $this->nodeRepository->findClass($objectType->getClassName()); - if ($class === null) { + if (! $class instanceof Class_) { return null; } $classMethod = $class->getMethod($methodName); - if ($classMethod === null) { + if (! $classMethod instanceof ClassMethod) { return null; } diff --git a/rules/code-quality/src/Rector/Array_/ArrayThisCallToThisMethodCallRector.php b/rules/code-quality/src/Rector/Array_/ArrayThisCallToThisMethodCallRector.php index b38d798b040b..7dd9f8f06aa1 100644 --- a/rules/code-quality/src/Rector/Array_/ArrayThisCallToThisMethodCallRector.php +++ b/rules/code-quality/src/Rector/Array_/ArrayThisCallToThisMethodCallRector.php @@ -15,6 +15,7 @@ use PhpParser\Node\Stmt\Property; use Rector\Core\Rector\AbstractRector; use Rector\NodeCollector\NodeAnalyzer\ArrayCallableMethodReferenceAnalyzer; +use Rector\NodeCollector\ValueObject\ArrayCallable; use Rector\NodeTypeResolver\Node\AttributeKey; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -88,7 +89,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { $arrayCallable = $this->arrayCallableMethodReferenceAnalyzer->match($node); - if ($arrayCallable === null) { + if (! $arrayCallable instanceof ArrayCallable) { return null; } if ($this->isAssignedToNetteMagicOnProperty($node)) { diff --git a/rules/code-quality/src/Rector/Array_/CallableThisArrayToAnonymousFunctionRector.php b/rules/code-quality/src/Rector/Array_/CallableThisArrayToAnonymousFunctionRector.php index f7cd210a368d..6642fbf7d0ab 100644 --- a/rules/code-quality/src/Rector/Array_/CallableThisArrayToAnonymousFunctionRector.php +++ b/rules/code-quality/src/Rector/Array_/CallableThisArrayToAnonymousFunctionRector.php @@ -13,6 +13,7 @@ use PhpParser\Node\Expr\Variable; use PhpParser\Node\Param; use PhpParser\Node\Scalar\String_; +use PhpParser\Node\Stmt\ClassMethod; use Rector\CodeQuality\NodeAnalyzer\CallableClassMethodMatcher; use Rector\CodeQuality\NodeFactory\AnonymousFunctionFactory; use Rector\Core\Rector\AbstractRector; @@ -133,7 +134,7 @@ public function refactor(Node $node): ?Node } $classMethod = $this->callableClassMethodMatcher->match($objectVariable, $methodName); - if ($classMethod === null) { + if (! $classMethod instanceof ClassMethod) { return null; } diff --git a/rules/code-quality/src/Rector/Assign/SplitListAssignToSeparateLineRector.php b/rules/code-quality/src/Rector/Assign/SplitListAssignToSeparateLineRector.php index c35070490df8..80f4555f6898 100644 --- a/rules/code-quality/src/Rector/Assign/SplitListAssignToSeparateLineRector.php +++ b/rules/code-quality/src/Rector/Assign/SplitListAssignToSeparateLineRector.php @@ -6,6 +6,7 @@ use PhpParser\Node; use PhpParser\Node\Expr\Array_; +use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\List_; use Rector\Core\Rector\AbstractRector; @@ -113,7 +114,7 @@ private function createStandaloneAssigns(Node $node, Array_ $rightArray): array $rightArrayItem = $rightArray->items[$key]; - if ($rightArrayItem === null) { + if (! $rightArrayItem instanceof ArrayItem) { continue; } diff --git a/rules/code-quality/src/Rector/BooleanAnd/SimplifyEmptyArrayCheckRector.php b/rules/code-quality/src/Rector/BooleanAnd/SimplifyEmptyArrayCheckRector.php index c9e2d0dd26a3..088920711d7c 100644 --- a/rules/code-quality/src/Rector/BooleanAnd/SimplifyEmptyArrayCheckRector.php +++ b/rules/code-quality/src/Rector/BooleanAnd/SimplifyEmptyArrayCheckRector.php @@ -11,6 +11,7 @@ use PhpParser\Node\Expr\Empty_; use Rector\Core\PhpParser\Node\Manipulator\BinaryOpManipulator; use Rector\Core\Rector\AbstractRector; +use Rector\Php71\ValueObject\TwoNodeMatch; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -61,7 +62,7 @@ function (Node $node): bool { Empty_::class ); - if ($twoNodeMatch === null) { + if (! $twoNodeMatch instanceof TwoNodeMatch) { return null; } diff --git a/rules/code-quality/src/Rector/Catch_/ThrowWithPreviousExceptionRector.php b/rules/code-quality/src/Rector/Catch_/ThrowWithPreviousExceptionRector.php index 528e8d1270b4..5c0868dd005b 100644 --- a/rules/code-quality/src/Rector/Catch_/ThrowWithPreviousExceptionRector.php +++ b/rules/code-quality/src/Rector/Catch_/ThrowWithPreviousExceptionRector.php @@ -86,7 +86,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { $caughtThrowableVariable = $node->var; - if ($caughtThrowableVariable === null) { + if (! $caughtThrowableVariable instanceof Variable) { return null; } diff --git a/rules/code-quality/src/Rector/ClassMethod/DateTimeToDateTimeInterfaceRector.php b/rules/code-quality/src/Rector/ClassMethod/DateTimeToDateTimeInterfaceRector.php index d10b7be0813f..081232254bb3 100644 --- a/rules/code-quality/src/Rector/ClassMethod/DateTimeToDateTimeInterfaceRector.php +++ b/rules/code-quality/src/Rector/ClassMethod/DateTimeToDateTimeInterfaceRector.php @@ -206,7 +206,7 @@ private function shouldSkipMethodCallRefactor(string $paramName, MethodCall $met } $parentNode = $methodCall->getAttribute(AttributeKey::PARENT_NODE); - if ($parentNode === null) { + if (! $parentNode instanceof \PhpParser\Node) { return true; } diff --git a/rules/code-quality/src/Rector/Foreach_/ForeachItemsAssignToEmptyArrayToAssignRector.php b/rules/code-quality/src/Rector/Foreach_/ForeachItemsAssignToEmptyArrayToAssignRector.php index 3a5fc45dcca8..b2eacd22e29d 100644 --- a/rules/code-quality/src/Rector/Foreach_/ForeachItemsAssignToEmptyArrayToAssignRector.php +++ b/rules/code-quality/src/Rector/Foreach_/ForeachItemsAssignToEmptyArrayToAssignRector.php @@ -5,6 +5,7 @@ namespace Rector\CodeQuality\Rector\Foreach_; use PhpParser\Node; +use PhpParser\Node\Expr; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Stmt\Foreach_; use Rector\CodeQuality\NodeAnalyzer\ForeachNodeAnalyzer; @@ -85,7 +86,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { $assignVariable = $this->foreachNodeAnalyzer->matchAssignItemsOnlyForeachArrayVariable($node); - if ($assignVariable === null) { + if (! $assignVariable instanceof Expr) { return null; } @@ -94,7 +95,7 @@ public function refactor(Node $node): ?Node } $previousDeclaration = $this->nodeUsageFinder->findPreviousForeachNodeUsage($node, $assignVariable); - if ($previousDeclaration === null) { + if (! $previousDeclaration instanceof Node) { return null; } diff --git a/rules/code-quality/src/Rector/Foreach_/ForeachToInArrayRector.php b/rules/code-quality/src/Rector/Foreach_/ForeachToInArrayRector.php index 58d03d9a8b50..7b66abe7f4f3 100644 --- a/rules/code-quality/src/Rector/Foreach_/ForeachToInArrayRector.php +++ b/rules/code-quality/src/Rector/Foreach_/ForeachToInArrayRector.php @@ -95,7 +95,7 @@ public function refactor(Node $node): ?Node $foreachValueVar = $node->valueVar; $twoNodeMatch = $this->matchNodes($ifCondition, $foreachValueVar); - if ($twoNodeMatch === null) { + if (! $twoNodeMatch instanceof TwoNodeMatch) { return null; } @@ -148,7 +148,7 @@ private function shouldSkipForeach(Foreach_ $foreach): bool } $nextNode = $foreach->getAttribute(AttributeKey::NEXT_NODE); - if ($nextNode === null) { + if (! $nextNode instanceof Node) { return true; } if (! $nextNode instanceof Return_) { @@ -157,7 +157,7 @@ private function shouldSkipForeach(Foreach_ $foreach): bool $returnExpression = $nextNode->expr; - if ($returnExpression === null) { + if (! $returnExpression instanceof Expr) { return true; } diff --git a/rules/code-quality/src/Rector/FuncCall/AddPregQuoteDelimiterRector.php b/rules/code-quality/src/Rector/FuncCall/AddPregQuoteDelimiterRector.php index 897faf69f657..7640a83c11bf 100644 --- a/rules/code-quality/src/Rector/FuncCall/AddPregQuoteDelimiterRector.php +++ b/rules/code-quality/src/Rector/FuncCall/AddPregQuoteDelimiterRector.php @@ -76,7 +76,7 @@ public function refactor(Node $node): ?Node private function determineDelimiter(FuncCall $funcCall): ?string { $concat = $this->getUppermostConcat($funcCall); - if ($concat === null) { + if (! $concat instanceof Concat) { return null; } diff --git a/rules/code-quality/src/Rector/Identical/GetClassToInstanceOfRector.php b/rules/code-quality/src/Rector/Identical/GetClassToInstanceOfRector.php index 68ebcee1adb5..e3f063522336 100644 --- a/rules/code-quality/src/Rector/Identical/GetClassToInstanceOfRector.php +++ b/rules/code-quality/src/Rector/Identical/GetClassToInstanceOfRector.php @@ -16,6 +16,7 @@ use PhpParser\Node\Scalar\String_; use Rector\Core\PhpParser\Node\Manipulator\BinaryOpManipulator; use Rector\Core\Rector\AbstractRector; +use Rector\Php71\ValueObject\TwoNodeMatch; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -75,7 +76,7 @@ function (Node $node): bool { } ); - if ($twoNodeMatch === null) { + if (! $twoNodeMatch instanceof TwoNodeMatch) { return null; } diff --git a/rules/code-quality/src/Rector/Identical/SimplifyArraySearchRector.php b/rules/code-quality/src/Rector/Identical/SimplifyArraySearchRector.php index 78a22ffe840e..0e5f1cd99bea 100644 --- a/rules/code-quality/src/Rector/Identical/SimplifyArraySearchRector.php +++ b/rules/code-quality/src/Rector/Identical/SimplifyArraySearchRector.php @@ -11,6 +11,7 @@ use PhpParser\Node\Expr\FuncCall; use Rector\Core\PhpParser\Node\Manipulator\BinaryOpManipulator; use Rector\Core\Rector\AbstractRector; +use Rector\Php71\ValueObject\TwoNodeMatch; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -66,7 +67,7 @@ function (Node $node): bool { } ); - if ($twoNodeMatch === null) { + if (! $twoNodeMatch instanceof TwoNodeMatch) { return null; } diff --git a/rules/code-quality/src/Rector/Identical/SimplifyConditionsRector.php b/rules/code-quality/src/Rector/Identical/SimplifyConditionsRector.php index 2cd296c3072c..841bfe09e36d 100644 --- a/rules/code-quality/src/Rector/Identical/SimplifyConditionsRector.php +++ b/rules/code-quality/src/Rector/Identical/SimplifyConditionsRector.php @@ -13,6 +13,7 @@ use Rector\Core\PhpParser\Node\AssignAndBinaryMap; use Rector\Core\PhpParser\Node\Manipulator\BinaryOpManipulator; use Rector\Core\Rector\AbstractRector; +use Rector\Php71\ValueObject\TwoNodeMatch; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -90,7 +91,7 @@ function (Node $binaryOp): bool { } ); - if ($twoNodeMatch === null) { + if (! $twoNodeMatch instanceof TwoNodeMatch) { return $twoNodeMatch; } diff --git a/rules/code-quality/src/Rector/If_/ExplicitBoolCompareRector.php b/rules/code-quality/src/Rector/If_/ExplicitBoolCompareRector.php index 6786e9db9f05..a7f961e80151 100644 --- a/rules/code-quality/src/Rector/If_/ExplicitBoolCompareRector.php +++ b/rules/code-quality/src/Rector/If_/ExplicitBoolCompareRector.php @@ -102,7 +102,7 @@ public function refactor(Node $node): ?Node } $newConditionNode = $this->resolveNewConditionNode($conditionNode, $isNegated); - if ($newConditionNode === null) { + if (! $newConditionNode instanceof BinaryOp) { return null; } diff --git a/rules/code-quality/src/Rector/If_/ShortenElseIfRector.php b/rules/code-quality/src/Rector/If_/ShortenElseIfRector.php index 85929f5dcef5..f1327bb293ee 100644 --- a/rules/code-quality/src/Rector/If_/ShortenElseIfRector.php +++ b/rules/code-quality/src/Rector/If_/ShortenElseIfRector.php @@ -5,6 +5,7 @@ namespace Rector\CodeQuality\Rector\If_; use PhpParser\Node; +use PhpParser\Node\Stmt\Else_; use PhpParser\Node\Stmt\ElseIf_; use PhpParser\Node\Stmt\If_; use Rector\Core\Rector\AbstractRector; @@ -71,7 +72,7 @@ public function refactor(Node $node): ?Node private function shortenElseIf(If_ $node): ?If_ { - if ($node->else === null) { + if (! $node->else instanceof Else_) { return null; } diff --git a/rules/code-quality/src/Rector/If_/SimplifyIfElseToTernaryRector.php b/rules/code-quality/src/Rector/If_/SimplifyIfElseToTernaryRector.php index 1c7d00a2cb6e..ffc18cedc329 100644 --- a/rules/code-quality/src/Rector/If_/SimplifyIfElseToTernaryRector.php +++ b/rules/code-quality/src/Rector/If_/SimplifyIfElseToTernaryRector.php @@ -82,10 +82,10 @@ public function refactor(Node $node): ?Node $ifAssignVar = $this->resolveOnlyStmtAssignVar($node->stmts); $elseAssignVar = $this->resolveOnlyStmtAssignVar($node->else->stmts); - if ($ifAssignVar === null) { + if (! $ifAssignVar instanceof Expr) { return null; } - if ($elseAssignVar === null) { + if (! $elseAssignVar instanceof Expr) { return null; } @@ -95,10 +95,10 @@ public function refactor(Node $node): ?Node $ternaryIf = $this->resolveOnlyStmtAssignExpr($node->stmts); $ternaryElse = $this->resolveOnlyStmtAssignExpr($node->else->stmts); - if ($ternaryIf === null) { + if (! $ternaryIf instanceof Expr) { return null; } - if ($ternaryElse === null) { + if (! $ternaryElse instanceof Expr) { return null; } diff --git a/rules/code-quality/src/Rector/Return_/SimplifyUselessVariableRector.php b/rules/code-quality/src/Rector/Return_/SimplifyUselessVariableRector.php index 068505882b72..47fdea81432c 100644 --- a/rules/code-quality/src/Rector/Return_/SimplifyUselessVariableRector.php +++ b/rules/code-quality/src/Rector/Return_/SimplifyUselessVariableRector.php @@ -115,7 +115,7 @@ private function shouldSkip(Return_ $return): bool $variableNode = $return->expr; $previousExpression = $return->getAttribute(AttributeKey::PREVIOUS_NODE); - if ($previousExpression === null) { + if (! $previousExpression instanceof Node) { return true; } if (! $previousExpression instanceof Expression) { diff --git a/rules/code-quality/src/Rector/Ternary/SimplifyTautologyTernaryRector.php b/rules/code-quality/src/Rector/Ternary/SimplifyTautologyTernaryRector.php index b5b6ed25ac2b..e0bd8860bd32 100644 --- a/rules/code-quality/src/Rector/Ternary/SimplifyTautologyTernaryRector.php +++ b/rules/code-quality/src/Rector/Ternary/SimplifyTautologyTernaryRector.php @@ -10,6 +10,7 @@ use PhpParser\Node\Expr\Ternary; use Rector\Core\PhpParser\Node\Manipulator\BinaryOpManipulator; use Rector\Core\Rector\AbstractRector; +use Rector\Php71\ValueObject\TwoNodeMatch; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -65,7 +66,7 @@ function (Node $leftNode) use ($node): bool { } ); - if ($twoNodeMatch === null) { + if (! $twoNodeMatch instanceof TwoNodeMatch) { return null; } diff --git a/rules/coding-style/src/Node/DocAliasResolver.php b/rules/coding-style/src/Node/DocAliasResolver.php index 3c44af3fa73b..6a7ba10de181 100644 --- a/rules/coding-style/src/Node/DocAliasResolver.php +++ b/rules/coding-style/src/Node/DocAliasResolver.php @@ -5,6 +5,7 @@ namespace Rector\CodingStyle\Node; use Nette\Utils\Strings; +use PhpParser\Comment\Doc; use PhpParser\Node; use PHPStan\Type\Type; use PHPStan\Type\UnionType; @@ -50,7 +51,7 @@ public function resolve(Node $node): array &$possibleDocAliases ): void { $docComment = $node->getDocComment(); - if ($docComment === null) { + if (! $docComment instanceof Doc) { return; } diff --git a/rules/coding-style/src/Node/UseManipulator.php b/rules/coding-style/src/Node/UseManipulator.php index 672cca54d965..384e42432701 100644 --- a/rules/coding-style/src/Node/UseManipulator.php +++ b/rules/coding-style/src/Node/UseManipulator.php @@ -65,7 +65,7 @@ private function resolveUsedNames(Node $node): void } $parentNode = $nameNode->getAttribute(AttributeKey::PARENT_NODE); - if ($parentNode === null) { + if (! $parentNode instanceof Node) { throw new ShouldNotHappenException(); } @@ -80,7 +80,7 @@ private function resolveUsedClassNames(Node $searchNode): void foreach ($classLikes as $classLike) { $classLikeName = $classLike->name; - if ($classLikeName === null) { + if (! $classLikeName instanceof Identifier) { continue; } diff --git a/rules/coding-style/src/Rector/Assign/ManualJsonStringToJsonEncodeArrayRector.php b/rules/coding-style/src/Rector/Assign/ManualJsonStringToJsonEncodeArrayRector.php index bf505ba47755..56fe71a141b0 100644 --- a/rules/coding-style/src/Rector/Assign/ManualJsonStringToJsonEncodeArrayRector.php +++ b/rules/coding-style/src/Rector/Assign/ManualJsonStringToJsonEncodeArrayRector.php @@ -231,7 +231,7 @@ private function collectContentAndPlaceholderNodesFromNextExpressions(Assign $as // jump to next one $currentNode = $this->getNextExpression($currentNode); - if ($currentNode === null) { + if (! $currentNode instanceof Node) { return $concatExpressionJoinData; } } diff --git a/rules/coding-style/src/Rector/ClassMethod/MakeInheritedMethodVisibilitySameAsParentRector.php b/rules/coding-style/src/Rector/ClassMethod/MakeInheritedMethodVisibilitySameAsParentRector.php index 2596d760a942..ae3b43369245 100644 --- a/rules/coding-style/src/Rector/ClassMethod/MakeInheritedMethodVisibilitySameAsParentRector.php +++ b/rules/coding-style/src/Rector/ClassMethod/MakeInheritedMethodVisibilitySameAsParentRector.php @@ -10,6 +10,7 @@ use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Return_; use PHPStan\Analyser\Scope; +use PHPStan\Reflection\ClassReflection; use Rector\Core\Rector\AbstractRector; use Rector\Core\ValueObject\MethodName; use Rector\Core\ValueObject\PhpVersionFeature; @@ -84,7 +85,7 @@ public function refactor(Node $node): ?Node } $classReflection = $scope->getClassReflection(); - if ($classReflection === null) { + if (! $classReflection instanceof ClassReflection) { return null; } diff --git a/rules/coding-style/src/Rector/ClassMethod/ReturnArrayClassMethodToYieldRector.php b/rules/coding-style/src/Rector/ClassMethod/ReturnArrayClassMethodToYieldRector.php index 4c07ead90662..2d07b103dab8 100644 --- a/rules/coding-style/src/Rector/ClassMethod/ReturnArrayClassMethodToYieldRector.php +++ b/rules/coding-style/src/Rector/ClassMethod/ReturnArrayClassMethodToYieldRector.php @@ -121,7 +121,7 @@ public function refactor(Node $node): ?Node } $arrayNode = $this->collectReturnArrayNodesFromClassMethod($node); - if ($arrayNode === null) { + if (! $arrayNode instanceof Array_) { continue; } @@ -173,7 +173,7 @@ private function transformArrayToYieldsOnMethodNode(ClassMethod $classMethod, Ar // remove whole return node $parentNode = $array->getAttribute(AttributeKey::PARENT_NODE); - if ($parentNode === null) { + if (! $parentNode instanceof Node) { throw new ShouldNotHappenException(); } diff --git a/rules/coding-style/src/Rector/ClassMethod/UnSpreadOperatorRector.php b/rules/coding-style/src/Rector/ClassMethod/UnSpreadOperatorRector.php index 8e3694bbc0b3..05d826a84375 100644 --- a/rules/coding-style/src/Rector/ClassMethod/UnSpreadOperatorRector.php +++ b/rules/coding-style/src/Rector/ClassMethod/UnSpreadOperatorRector.php @@ -102,7 +102,7 @@ private function processUnspreadOperatorClassMethodParams(ClassMethod $classMeth private function processUnspreadOperatorMethodCallArgs(MethodCall $methodCall): ?MethodCall { $classMethod = $this->nodeRepository->findClassMethodByMethodCall($methodCall); - if ($classMethod === null) { + if (! $classMethod instanceof ClassMethod) { return null; } diff --git a/rules/coding-style/src/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector.php b/rules/coding-style/src/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector.php index 73de9eb82b1a..6aeb6b124204 100644 --- a/rules/coding-style/src/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector.php +++ b/rules/coding-style/src/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector.php @@ -57,7 +57,7 @@ public function refactor(Node $node): ?Node foreach ($node->parts as $index => $nodePart) { if ($nodePart instanceof Variable) { $previousNode = $nodePart->getAttribute(AttributeKey::PREVIOUS_NODE); - $previousNodeEndTokenPosition = $previousNode === null ? $startTokenPos : $previousNode->getEndTokenPos(); + $previousNodeEndTokenPosition = $previousNode instanceof Node ? $previousNode->getEndTokenPos() : $startTokenPos; if ($previousNodeEndTokenPosition + 1 === $nodePart->getStartTokenPos()) { $hasVariableBeenWrapped = true; diff --git a/rules/coding-style/src/Rector/Throw_/AnnotateThrowablesRector.php b/rules/coding-style/src/Rector/Throw_/AnnotateThrowablesRector.php index a30d4e792da2..0d2ae3d42d24 100644 --- a/rules/coding-style/src/Rector/Throw_/AnnotateThrowablesRector.php +++ b/rules/coding-style/src/Rector/Throw_/AnnotateThrowablesRector.php @@ -166,7 +166,7 @@ private function hasThrowablesToAnnotate(Node $node): bool private function annotateThrowables(Node $node): void { $callee = $this->identifyCaller($node); - if ($callee === null) { + if (! $callee instanceof Node) { return; } @@ -225,7 +225,7 @@ private function identifyCaller(Node $node): ?Node private function extractAlreadyAnnotatedThrowables(Node $node): array { $callee = $this->identifyCaller($node); - if ($callee === null) { + if (! $callee instanceof Node) { return []; } diff --git a/rules/coding-style/src/Rector/Use_/RemoveUnusedAliasRector.php b/rules/coding-style/src/Rector/Use_/RemoveUnusedAliasRector.php index 85525c278dca..84b3fe06fd4b 100644 --- a/rules/coding-style/src/Rector/Use_/RemoveUnusedAliasRector.php +++ b/rules/coding-style/src/Rector/Use_/RemoveUnusedAliasRector.php @@ -115,7 +115,7 @@ public function refactor(Node $node): ?Node } $searchNode = $this->resolveSearchNode($node); - if ($searchNode === null) { + if (! $searchNode instanceof Node) { return null; } diff --git a/rules/dead-code/src/Doctrine/DoctrineEntityManipulator.php b/rules/dead-code/src/Doctrine/DoctrineEntityManipulator.php index 8497bb14c596..dd5902be1080 100644 --- a/rules/dead-code/src/Doctrine/DoctrineEntityManipulator.php +++ b/rules/dead-code/src/Doctrine/DoctrineEntityManipulator.php @@ -59,7 +59,7 @@ public function resolveOtherProperty(Property $property): ?string $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property); $relationTagValueNode = $phpDocInfo->getByType(DoctrineRelationTagValueNodeInterface::class); - if ($relationTagValueNode === null) { + if (! $relationTagValueNode instanceof DoctrineRelationTagValueNodeInterface) { return null; } diff --git a/rules/dead-code/src/NodeCollector/UnusedParameterResolver.php b/rules/dead-code/src/NodeCollector/UnusedParameterResolver.php index f9f8609d4bda..a039e43502f5 100644 --- a/rules/dead-code/src/NodeCollector/UnusedParameterResolver.php +++ b/rules/dead-code/src/NodeCollector/UnusedParameterResolver.php @@ -52,7 +52,7 @@ public function resolve(ClassMethod $classMethod, string $methodName, array $chi foreach ($childrenOfClass as $childClassNode) { $methodOfChild = $childClassNode->getMethod($methodName); - if ($methodOfChild === null) { + if (! $methodOfChild instanceof ClassMethod) { continue; } diff --git a/rules/dead-code/src/Rector/Assign/RemoveUnusedAssignVariableRector.php b/rules/dead-code/src/Rector/Assign/RemoveUnusedAssignVariableRector.php index 37abc6c7d0d6..270818fbf6b9 100644 --- a/rules/dead-code/src/Rector/Assign/RemoveUnusedAssignVariableRector.php +++ b/rules/dead-code/src/Rector/Assign/RemoveUnusedAssignVariableRector.php @@ -161,7 +161,7 @@ private function isPreviousVariablePartOfOverridingAssign(Assign $assign): bool { // is previous variable node as part of assign? $previousVariableAssign = $this->previousVariableAssignNodeFinder->find($assign); - if ($previousVariableAssign === null) { + if (! $previousVariableAssign instanceof Node) { return false; } diff --git a/rules/dead-code/src/Rector/ClassMethod/RemoveDelegatingParentCallRector.php b/rules/dead-code/src/Rector/ClassMethod/RemoveDelegatingParentCallRector.php index 6b59db3f1936..36659ee77dc0 100644 --- a/rules/dead-code/src/Rector/ClassMethod/RemoveDelegatingParentCallRector.php +++ b/rules/dead-code/src/Rector/ClassMethod/RemoveDelegatingParentCallRector.php @@ -92,7 +92,7 @@ public function refactor(Node $node): ?Node } $staticCall = $this->matchStaticCall($onlyStmt); - if ($staticCall === null) { + if (! $staticCall instanceof StaticCall) { return null; } diff --git a/rules/dead-code/src/Rector/ClassMethod/RemoveUnusedParameterRector.php b/rules/dead-code/src/Rector/ClassMethod/RemoveUnusedParameterRector.php index 75a598af30cd..54797f09b5b0 100644 --- a/rules/dead-code/src/Rector/ClassMethod/RemoveUnusedParameterRector.php +++ b/rules/dead-code/src/Rector/ClassMethod/RemoveUnusedParameterRector.php @@ -8,6 +8,7 @@ use PhpParser\Node\Param; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; +use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode; use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover; use Rector\Caching\Contract\Rector\ZeroCacheRectorInterface; use Rector\Core\PhpParser\Node\Manipulator\ClassManipulator; @@ -132,7 +133,7 @@ public function refactor(Node $node): ?Node foreach ($childrenOfClass as $childClassNode) { $methodOfChild = $childClassNode->getMethod($methodName); - if ($methodOfChild === null) { + if (! $methodOfChild instanceof \PhpParser\Node\Stmt\ClassMethod) { continue; } @@ -196,7 +197,7 @@ private function clearPhpDocInfo(ClassMethod $classMethod, array $unusedParamete } $paramTagValueNode = $phpDocInfo->getParamTagValueByName($parameterName); - if ($paramTagValueNode === null) { + if (! $paramTagValueNode instanceof ParamTagValueNode) { continue; } diff --git a/rules/dead-code/src/Rector/Class_/RemoveUnusedDoctrineEntityMethodAndPropertyRector.php b/rules/dead-code/src/Rector/Class_/RemoveUnusedDoctrineEntityMethodAndPropertyRector.php index 6e411921f67a..49313050b1cc 100644 --- a/rules/dead-code/src/Rector/Class_/RemoveUnusedDoctrineEntityMethodAndPropertyRector.php +++ b/rules/dead-code/src/Rector/Class_/RemoveUnusedDoctrineEntityMethodAndPropertyRector.php @@ -231,7 +231,7 @@ private function resolveClassUsedPropertyFetchNames(Class_ $class): array private function removeInversedByOrMappedByOnRelatedProperty(Property $property): void { $otherRelationProperty = $this->getOtherRelationProperty($property); - if ($otherRelationProperty === null) { + if (! $otherRelationProperty instanceof Property) { return; } diff --git a/rules/dead-code/src/Rector/If_/SimplifyIfElseWithSameContentRector.php b/rules/dead-code/src/Rector/If_/SimplifyIfElseWithSameContentRector.php index e6ace2ab719c..b71ab9de17ac 100644 --- a/rules/dead-code/src/Rector/If_/SimplifyIfElseWithSameContentRector.php +++ b/rules/dead-code/src/Rector/If_/SimplifyIfElseWithSameContentRector.php @@ -5,6 +5,7 @@ namespace Rector\DeadCode\Rector\If_; use PhpParser\Node; +use PhpParser\Node\Stmt\Else_; use PhpParser\Node\Stmt\If_; use Rector\Core\Exception\ShouldNotHappenException; use Rector\Core\Rector\AbstractRector; @@ -87,7 +88,7 @@ private function isIfWithConstantReturns(If_ $if): bool } $else = $if->else; - if ($else === null) { + if (! $else instanceof Else_) { throw new ShouldNotHappenException(); } diff --git a/rules/dead-code/src/Rector/MethodCall/RemoveEmptyMethodCallRector.php b/rules/dead-code/src/Rector/MethodCall/RemoveEmptyMethodCallRector.php index c928b9dc1f82..adb717155c77 100644 --- a/rules/dead-code/src/Rector/MethodCall/RemoveEmptyMethodCallRector.php +++ b/rules/dead-code/src/Rector/MethodCall/RemoveEmptyMethodCallRector.php @@ -8,6 +8,7 @@ use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\If_; use PHPStan\Analyser\Scope; use PHPStan\Type\ObjectType; @@ -91,7 +92,7 @@ public function refactor(Node $node): ?Node } $class = $this->classReflectionToAstResolver->getClassFromObjectType($type); - if ($class === null) { + if (! $class instanceof Class_) { return null; } @@ -122,7 +123,7 @@ private function shouldSkipClassMethod(Class_ $class, MethodCall $methodCall): b } $classMethod = $class->getMethod($methodName); - if ($classMethod === null) { + if (! $classMethod instanceof ClassMethod) { return true; } diff --git a/rules/dead-code/src/Rector/Plus/RemoveDeadZeroAndOneOperationRector.php b/rules/dead-code/src/Rector/Plus/RemoveDeadZeroAndOneOperationRector.php index e72164eef8ee..ad5787c73eed 100644 --- a/rules/dead-code/src/Rector/Plus/RemoveDeadZeroAndOneOperationRector.php +++ b/rules/dead-code/src/Rector/Plus/RemoveDeadZeroAndOneOperationRector.php @@ -104,7 +104,7 @@ public function refactor(Node $node): ?Node } // nothing more to change, return last node - if ($changedNode === null) { + if (! $changedNode instanceof Node) { return $previousNode; } } diff --git a/rules/dead-code/src/Rector/PropertyProperty/RemoveNullPropertyInitializationRector.php b/rules/dead-code/src/Rector/PropertyProperty/RemoveNullPropertyInitializationRector.php index b8b0fe07abd8..2ac147ac1886 100644 --- a/rules/dead-code/src/Rector/PropertyProperty/RemoveNullPropertyInitializationRector.php +++ b/rules/dead-code/src/Rector/PropertyProperty/RemoveNullPropertyInitializationRector.php @@ -5,6 +5,7 @@ namespace Rector\DeadCode\Rector\PropertyProperty; use PhpParser\Node; +use PhpParser\Node\Expr; use PhpParser\Node\Expr\ConstFetch; use PhpParser\Node\NullableType; use PhpParser\Node\Stmt\PropertyProperty; @@ -57,7 +58,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { $defaultValueNode = $node->default; - if ($defaultValueNode === null) { + if (! $defaultValueNode instanceof Expr) { return null; } diff --git a/rules/dead-code/src/Rector/StaticCall/RemoveParentCallWithoutParentRector.php b/rules/dead-code/src/Rector/StaticCall/RemoveParentCallWithoutParentRector.php index dbe5939da0f5..7407423c68e2 100644 --- a/rules/dead-code/src/Rector/StaticCall/RemoveParentCallWithoutParentRector.php +++ b/rules/dead-code/src/Rector/StaticCall/RemoveParentCallWithoutParentRector.php @@ -8,6 +8,7 @@ use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Name; use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Stmt\ClassMethod; use Rector\Core\PhpParser\Node\Manipulator\ClassMethodManipulator; use Rector\Core\Rector\AbstractRector; use Rector\NodeTypeResolver\Node\AttributeKey; @@ -91,7 +92,7 @@ public function refactor(Node $node): ?Node } $classMethod = $node->getAttribute(AttributeKey::METHOD_NODE); - if ($classMethod === null) { + if (! $classMethod instanceof ClassMethod) { return null; } diff --git a/rules/dead-code/src/ValueObject/VariableNodeUse.php b/rules/dead-code/src/ValueObject/VariableNodeUse.php index f77e73bf94fc..4aaa01fb5aaf 100644 --- a/rules/dead-code/src/ValueObject/VariableNodeUse.php +++ b/rules/dead-code/src/ValueObject/VariableNodeUse.php @@ -83,7 +83,7 @@ public function getVariableNode(): Node public function getParentNode(): Node { $parentNode = $this->variable->getAttribute(AttributeKey::PARENT_NODE); - if ($parentNode === null) { + if (! $parentNode instanceof Node) { throw new ShouldNotHappenException(); } diff --git a/rules/dead-doc-block/src/DeadParamTagValueNodeAnalyzer.php b/rules/dead-doc-block/src/DeadParamTagValueNodeAnalyzer.php index 0e9233ef800c..8dd4888f5371 100644 --- a/rules/dead-doc-block/src/DeadParamTagValueNodeAnalyzer.php +++ b/rules/dead-doc-block/src/DeadParamTagValueNodeAnalyzer.php @@ -31,7 +31,7 @@ public function __construct(NodeNameResolver $nodeNameResolver, TypeComparator $ public function isDead(ParamTagValueNode $paramTagValueNode, FunctionLike $functionLike): bool { $param = $this->matchParamByName($paramTagValueNode->parameterName, $functionLike); - if ($param === null) { + if (! $param instanceof Param) { return false; } diff --git a/rules/dead-doc-block/src/Rector/ClassMethod/RemoveUselessReturnTagRector.php b/rules/dead-doc-block/src/Rector/ClassMethod/RemoveUselessReturnTagRector.php index df45e4272559..58fea61efb0f 100644 --- a/rules/dead-doc-block/src/Rector/ClassMethod/RemoveUselessReturnTagRector.php +++ b/rules/dead-doc-block/src/Rector/ClassMethod/RemoveUselessReturnTagRector.php @@ -6,6 +6,7 @@ use PhpParser\Node; use PhpParser\Node\Stmt\ClassMethod; +use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareReturnTagValueNode; use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover; use Rector\Core\Rector\AbstractRector; use Rector\DeadDocBlock\DeadReturnTagValueNodeAnalyzer; @@ -86,7 +87,7 @@ public function refactor(Node $node): ?Node $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node); $attributeAwareReturnTagValueNode = $phpDocInfo->getReturnTagValue(); - if ($attributeAwareReturnTagValueNode === null) { + if (! $attributeAwareReturnTagValueNode instanceof AttributeAwareReturnTagValueNode) { return null; } diff --git a/rules/dead-doc-block/src/Rector/Node/RemoveNonExistingVarAnnotationRector.php b/rules/dead-doc-block/src/Rector/Node/RemoveNonExistingVarAnnotationRector.php index 2607c1264e47..06c47d3b0b25 100644 --- a/rules/dead-doc-block/src/Rector/Node/RemoveNonExistingVarAnnotationRector.php +++ b/rules/dead-doc-block/src/Rector/Node/RemoveNonExistingVarAnnotationRector.php @@ -107,7 +107,7 @@ public function refactor(Node $node): ?Node $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node); $varTagValueNode = $phpDocInfo->getVarTagValueNode(); - if ($varTagValueNode === null) { + if (! $varTagValueNode instanceof VarTagValueNode) { return null; } diff --git a/rules/dead-doc-block/src/TagRemover/ParamTagRemover.php b/rules/dead-doc-block/src/TagRemover/ParamTagRemover.php index fde6225839e9..53155c260d60 100644 --- a/rules/dead-doc-block/src/TagRemover/ParamTagRemover.php +++ b/rules/dead-doc-block/src/TagRemover/ParamTagRemover.php @@ -5,6 +5,7 @@ namespace Rector\DeadDocBlock\TagRemover; use PhpParser\Node\FunctionLike; +use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover; use Rector\DeadDocBlock\DeadParamTagValueNodeAnalyzer; @@ -37,7 +38,7 @@ public function removeParamTagsIfUseless(PhpDocInfo $phpDocInfo, FunctionLike $f // remove existing type $paramTagValueNode = $phpDocInfo->getParamTagValueByName($paramName); - if ($paramTagValueNode === null) { + if (! $paramTagValueNode instanceof ParamTagValueNode) { continue; } diff --git a/rules/dead-doc-block/src/TagRemover/ReturnTagRemover.php b/rules/dead-doc-block/src/TagRemover/ReturnTagRemover.php index f657851fcef9..0b3853258e50 100644 --- a/rules/dead-doc-block/src/TagRemover/ReturnTagRemover.php +++ b/rules/dead-doc-block/src/TagRemover/ReturnTagRemover.php @@ -6,6 +6,7 @@ use PhpParser\Node\FunctionLike; use PHPStan\Type\Type; +use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareReturnTagValueNode; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover; use Rector\DeadDocBlock\DeadReturnTagValueNodeAnalyzer; @@ -34,7 +35,7 @@ public function removeReturnTagIfUseless(PhpDocInfo $phpDocInfo, FunctionLike $f { // remove existing type $attributeAwareReturnTagValueNode = $phpDocInfo->getReturnTagValue(); - if ($attributeAwareReturnTagValueNode === null) { + if (! $attributeAwareReturnTagValueNode instanceof AttributeAwareReturnTagValueNode) { return; } diff --git a/rules/defluent/src/ConflictGuard/ParentClassMethodTypeOverrideGuard.php b/rules/defluent/src/ConflictGuard/ParentClassMethodTypeOverrideGuard.php index 12582dbe93b7..96348429ce9e 100644 --- a/rules/defluent/src/ConflictGuard/ParentClassMethodTypeOverrideGuard.php +++ b/rules/defluent/src/ConflictGuard/ParentClassMethodTypeOverrideGuard.php @@ -45,7 +45,7 @@ public function isReturnTypeChangeAllowed(ClassMethod $classMethod): bool $parentClassMethodReflection = $this->getParentClassMethod($classMethod); // nothign to check - if ($parentClassMethodReflection === null) { + if (! $parentClassMethodReflection instanceof MethodReflection) { return true; } diff --git a/rules/defluent/src/NodeAnalyzer/FluentChainMethodCallNodeAnalyzer.php b/rules/defluent/src/NodeAnalyzer/FluentChainMethodCallNodeAnalyzer.php index 3cd39766c501..dacfa699fa38 100644 --- a/rules/defluent/src/NodeAnalyzer/FluentChainMethodCallNodeAnalyzer.php +++ b/rules/defluent/src/NodeAnalyzer/FluentChainMethodCallNodeAnalyzer.php @@ -97,7 +97,7 @@ public function isLastChainMethodCall(MethodCall $methodCall): bool $nextNode = $methodCall->getAttribute(AttributeKey::NEXT_NODE); // is last chain call - return $nextNode === null; + return ! $nextNode instanceof Node; } /** diff --git a/rules/defluent/src/NodeAnalyzer/FluentChainMethodCallRootExtractor.php b/rules/defluent/src/NodeAnalyzer/FluentChainMethodCallRootExtractor.php index 5106327f7c39..e22d0b41d8f4 100644 --- a/rules/defluent/src/NodeAnalyzer/FluentChainMethodCallRootExtractor.php +++ b/rules/defluent/src/NodeAnalyzer/FluentChainMethodCallRootExtractor.php @@ -17,6 +17,7 @@ use Rector\Defluent\ValueObject\AssignAndRootExpr; use Rector\Defluent\ValueObject\FluentCallsKind; use Rector\Naming\Naming\PropertyNaming; +use Rector\Naming\ValueObject\ExpectedName; use Rector\NetteKdyby\Naming\VariableNaming; use Rector\NodeNameResolver\NodeNameResolver; use Rector\NodeTypeResolver\Node\AttributeKey; @@ -181,7 +182,7 @@ private function matchMethodCallOnNew(MethodCall $methodCall): ?AssignAndRootExp $fullyQualifiedObjectType = new FullyQualifiedObjectType($className); $expectedName = $this->propertyNaming->getExpectedNameFromType($fullyQualifiedObjectType); - if ($expectedName === null) { + if (! $expectedName instanceof ExpectedName) { return null; } diff --git a/rules/defluent/src/Rector/AbstractFluentChainMethodCallRector.php b/rules/defluent/src/Rector/AbstractFluentChainMethodCallRector.php index 481ace2c1d5d..46afdef5634e 100644 --- a/rules/defluent/src/Rector/AbstractFluentChainMethodCallRector.php +++ b/rules/defluent/src/Rector/AbstractFluentChainMethodCallRector.php @@ -16,6 +16,7 @@ use Rector\Defluent\NodeAnalyzer\SameClassMethodCallAnalyzer; use Rector\Defluent\NodeFactory\NonFluentChainMethodCallFactory; use Rector\Defluent\Skipper\FluentMethodCallSkipper; +use Rector\Defluent\ValueObject\AssignAndRootExpr; use Rector\Defluent\ValueObject\AssignAndRootExprAndNodesToAdd; use Rector\NodeTypeResolver\Node\AttributeKey; @@ -77,7 +78,7 @@ protected function createStandaloneNodesToAddFromChainMethodCalls( $kind ); - if ($assignAndRootExpr === null) { + if (! $assignAndRootExpr instanceof AssignAndRootExpr) { return null; } diff --git a/rules/defluent/src/Rector/ClassMethod/ReturnThisRemoveRector.php b/rules/defluent/src/Rector/ClassMethod/ReturnThisRemoveRector.php index 0000d2e93d1f..56725311c6b6 100644 --- a/rules/defluent/src/Rector/ClassMethod/ReturnThisRemoveRector.php +++ b/rules/defluent/src/Rector/ClassMethod/ReturnThisRemoveRector.php @@ -84,7 +84,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { $returnThis = $this->matchSingleReturnThis($node); - if ($returnThis === null) { + if (! $returnThis instanceof Return_) { return null; } @@ -95,7 +95,7 @@ public function refactor(Node $node): ?Node $this->removeNode($returnThis); $classMethod = $node->getAttribute(AttributeKey::METHOD_NODE); - if ($classMethod === null) { + if (! $classMethod instanceof \PhpParser\Node\Stmt\ClassMethod) { throw new ShouldNotHappenException(); } diff --git a/rules/defluent/src/Rector/MethodCall/FluentChainMethodCallToNormalMethodCallRector.php b/rules/defluent/src/Rector/MethodCall/FluentChainMethodCallToNormalMethodCallRector.php index 875ff3925b83..4b4a75e05bcb 100644 --- a/rules/defluent/src/Rector/MethodCall/FluentChainMethodCallToNormalMethodCallRector.php +++ b/rules/defluent/src/Rector/MethodCall/FluentChainMethodCallToNormalMethodCallRector.php @@ -10,6 +10,7 @@ use PhpParser\Node\Stmt\Return_; use Rector\Defluent\Rector\AbstractFluentChainMethodCallRector; use Rector\Defluent\Rector\Return_\DefluentReturnMethodCallRector; +use Rector\Defluent\ValueObject\AssignAndRootExprAndNodesToAdd; use Rector\Defluent\ValueObject\FluentCallsKind; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -70,7 +71,7 @@ public function refactor(Node $node): ?Node FluentCallsKind::NORMAL ); - if ($assignAndRootExprAndNodesToAdd === null) { + if (! $assignAndRootExprAndNodesToAdd instanceof AssignAndRootExprAndNodesToAdd) { return null; } diff --git a/rules/defluent/src/Rector/MethodCall/InArgFluentChainMethodCallToStandaloneMethodCallRector.php b/rules/defluent/src/Rector/MethodCall/InArgFluentChainMethodCallToStandaloneMethodCallRector.php index c568ef24baee..4fa285d0a73e 100644 --- a/rules/defluent/src/Rector/MethodCall/InArgFluentChainMethodCallToStandaloneMethodCallRector.php +++ b/rules/defluent/src/Rector/MethodCall/InArgFluentChainMethodCallToStandaloneMethodCallRector.php @@ -12,6 +12,7 @@ use Rector\Defluent\NodeAnalyzer\NewFluentChainMethodCallNodeAnalyzer; use Rector\Defluent\NodeFactory\VariableFromNewFactory; use Rector\Defluent\Rector\AbstractFluentChainMethodCallRector; +use Rector\Defluent\ValueObject\AssignAndRootExprAndNodesToAdd; use Rector\Defluent\ValueObject\FluentCallsKind; use Rector\NodeTypeResolver\Node\AttributeKey; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -121,7 +122,7 @@ public function refactor(Node $node): ?Node FluentCallsKind::IN_ARGS ); - if ($assignAndRootExprAndNodesToAdd === null) { + if (! $assignAndRootExprAndNodesToAdd instanceof AssignAndRootExprAndNodesToAdd) { return null; } diff --git a/rules/defluent/src/Rector/MethodCall/MethodCallOnSetterMethodCallToStandaloneAssignRector.php b/rules/defluent/src/Rector/MethodCall/MethodCallOnSetterMethodCallToStandaloneAssignRector.php index 4502194f72e1..65feaf39580b 100644 --- a/rules/defluent/src/Rector/MethodCall/MethodCallOnSetterMethodCallToStandaloneAssignRector.php +++ b/rules/defluent/src/Rector/MethodCall/MethodCallOnSetterMethodCallToStandaloneAssignRector.php @@ -7,6 +7,7 @@ use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr\MethodCall; +use PhpParser\Node\Expr\New_; use PhpParser\Node\Expr\Variable; use Rector\Defluent\NodeAnalyzer\NewFluentChainMethodCallNodeAnalyzer; use Rector\Defluent\NodeFactory\VariableFromNewFactory; @@ -98,12 +99,12 @@ public function refactor(Node $node): ?Node } $rootMethodCall = $this->fluentChainMethodCallNodeAnalyzer->resolveRootMethodCall($node); - if ($rootMethodCall === null) { + if (! $rootMethodCall instanceof \PhpParser\Node\Expr\MethodCall) { return null; } $new = $this->newFluentChainMethodCallNodeAnalyzer->matchNewInFluentSetterMethodCall($rootMethodCall); - if ($new === null) { + if (! $new instanceof New_) { return null; } diff --git a/rules/defluent/src/Rector/MethodCall/NewFluentChainMethodCallToNonFluentRector.php b/rules/defluent/src/Rector/MethodCall/NewFluentChainMethodCallToNonFluentRector.php index d5acbd05be98..896a33b6b296 100644 --- a/rules/defluent/src/Rector/MethodCall/NewFluentChainMethodCallToNonFluentRector.php +++ b/rules/defluent/src/Rector/MethodCall/NewFluentChainMethodCallToNonFluentRector.php @@ -9,6 +9,7 @@ use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Stmt\Return_; use Rector\Defluent\Rector\AbstractFluentChainMethodCallRector; +use Rector\Defluent\ValueObject\AssignAndRootExprAndNodesToAdd; use Rector\Defluent\ValueObject\FluentCallsKind; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -69,7 +70,7 @@ public function refactor(Node $node): ?Node $node, FluentCallsKind::NORMAL ); - if ($assignAndRootExprAndNodesToAdd === null) { + if (! $assignAndRootExprAndNodesToAdd instanceof AssignAndRootExprAndNodesToAdd) { return null; } diff --git a/rules/defluent/src/Rector/Return_/ReturnFluentChainMethodCallToNormalMethodCallRector.php b/rules/defluent/src/Rector/Return_/ReturnFluentChainMethodCallToNormalMethodCallRector.php index 5c811bff0bd1..f885741727dc 100644 --- a/rules/defluent/src/Rector/Return_/ReturnFluentChainMethodCallToNormalMethodCallRector.php +++ b/rules/defluent/src/Rector/Return_/ReturnFluentChainMethodCallToNormalMethodCallRector.php @@ -10,6 +10,8 @@ use Rector\Defluent\NodeFactory\ReturnFluentMethodCallFactory; use Rector\Defluent\NodeFactory\SeparateReturnMethodCallFactory; use Rector\Defluent\Rector\AbstractFluentChainMethodCallRector; +use Rector\Defluent\ValueObject\FirstAssignFluentCall; +use Rector\Defluent\ValueObject\FluentMethodCalls; use Rector\Defluent\ValueObjectFactory\FluentMethodCallsFactory; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -84,7 +86,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { $methodCall = $this->matchReturnMethodCall($node); - if ($methodCall === null) { + if (! $methodCall instanceof MethodCall) { return null; } @@ -109,7 +111,7 @@ public function refactor(Node $node): ?Node private function createStandaloneNodesToAddFromReturnFluentMethodCalls(MethodCall $methodCall): array { $fluentMethodCalls = $this->fluentMethodCallsFactory->createFromLastMethodCall($methodCall); - if ($fluentMethodCalls === null) { + if (! $fluentMethodCalls instanceof FluentMethodCalls) { return []; } @@ -117,7 +119,7 @@ private function createStandaloneNodesToAddFromReturnFluentMethodCalls(MethodCal $fluentMethodCalls ); - if ($firstAssignFluentCall === null) { + if (! $firstAssignFluentCall instanceof FirstAssignFluentCall) { return []; } diff --git a/rules/defluent/src/Rector/Return_/ReturnNewFluentChainMethodCallToNonFluentRector.php b/rules/defluent/src/Rector/Return_/ReturnNewFluentChainMethodCallToNonFluentRector.php index e47b002e591e..81a33609a753 100644 --- a/rules/defluent/src/Rector/Return_/ReturnNewFluentChainMethodCallToNonFluentRector.php +++ b/rules/defluent/src/Rector/Return_/ReturnNewFluentChainMethodCallToNonFluentRector.php @@ -5,8 +5,10 @@ namespace Rector\Defluent\Rector\Return_; use PhpParser\Node; +use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Stmt\Return_; use Rector\Defluent\Rector\AbstractFluentChainMethodCallRector; +use Rector\Defluent\ValueObject\AssignAndRootExprAndNodesToAdd; use Rector\Defluent\ValueObject\FluentCallsKind; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -56,7 +58,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { $methodCall = $this->matchReturnMethodCall($node); - if ($methodCall === null) { + if (! $methodCall instanceof MethodCall) { return null; } @@ -69,7 +71,7 @@ public function refactor(Node $node): ?Node FluentCallsKind::NORMAL ); - if ($assignAndRootExprAndNodesToAdd === null) { + if (! $assignAndRootExprAndNodesToAdd instanceof AssignAndRootExprAndNodesToAdd) { return null; } diff --git a/rules/defluent/src/ValueObject/AssignAndRootExpr.php b/rules/defluent/src/ValueObject/AssignAndRootExpr.php index cbd25ed6908e..e2ebe9c090bb 100644 --- a/rules/defluent/src/ValueObject/AssignAndRootExpr.php +++ b/rules/defluent/src/ValueObject/AssignAndRootExpr.php @@ -5,6 +5,7 @@ namespace Rector\Defluent\ValueObject; use PhpParser\Node\Expr; +use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Stmt\Return_; use Rector\Core\Exception\ShouldNotHappenException; @@ -47,7 +48,7 @@ public function getSilentVariable(): ?Variable public function getReturnSilentVariable(): Return_ { - if ($this->silentVariable === null) { + if (! $this->silentVariable instanceof Variable) { throw new ShouldNotHappenException(); } @@ -71,7 +72,7 @@ public function isFirstCallFactory(): bool public function getFactoryAssignVariable(): Expr { $firstAssign = $this->getFirstAssign(); - if ($firstAssign === null) { + if (! $firstAssign instanceof Assign) { return $this->getCallerExpr(); } diff --git a/rules/defluent/src/ValueObject/FirstAssignFluentCall.php b/rules/defluent/src/ValueObject/FirstAssignFluentCall.php index 9a517646a791..a949e76d9e96 100644 --- a/rules/defluent/src/ValueObject/FirstAssignFluentCall.php +++ b/rules/defluent/src/ValueObject/FirstAssignFluentCall.php @@ -5,6 +5,7 @@ namespace Rector\Defluent\ValueObject; use PhpParser\Node\Expr; +use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\MethodCall; use Rector\Defluent\Contract\ValueObject\FirstCallFactoryAwareInterface; use Rector\Defluent\Contract\ValueObject\RootExprAwareInterface; @@ -51,7 +52,7 @@ public function isFirstCallFactory(): bool public function getFactoryAssignVariable(): Expr { $firstAssign = $this->getFirstAssign(); - if ($firstAssign === null) { + if (! $firstAssign instanceof Assign) { return $this->assignExpr; } diff --git a/rules/dependency-injection/src/Rector/Class_/MultiParentingToAbstractDependencyRector.php b/rules/dependency-injection/src/Rector/Class_/MultiParentingToAbstractDependencyRector.php index 6857c8e666cf..679d7e889e01 100644 --- a/rules/dependency-injection/src/Rector/Class_/MultiParentingToAbstractDependencyRector.php +++ b/rules/dependency-injection/src/Rector/Class_/MultiParentingToAbstractDependencyRector.php @@ -162,7 +162,7 @@ public function refactor(Node $node): ?Node } $classMethod = $node->getMethod(MethodName::CONSTRUCT); - if ($classMethod === null) { + if (! $classMethod instanceof ClassMethod) { return null; } @@ -173,7 +173,7 @@ public function refactor(Node $node): ?Node foreach ($childrenClasses as $childrenClass) { $constructorClassMethod = $childrenClass->getMethod(MethodName::CONSTRUCT); - if ($constructorClassMethod === null) { + if (! $constructorClassMethod instanceof ClassMethod) { continue; } @@ -202,7 +202,7 @@ public function configure(array $configuration): void private function resolveConstructorParamClassTypes(Class_ $class): array { $constructorClassMethod = $class->getMethod(MethodName::CONSTRUCT); - if ($constructorClassMethod === null) { + if (! $constructorClassMethod instanceof ClassMethod) { return []; } diff --git a/rules/doctrine-code-quality/src/NodeAnalyzer/ConstructorAssignPropertyAnalyzer.php b/rules/doctrine-code-quality/src/NodeAnalyzer/ConstructorAssignPropertyAnalyzer.php index 747832d906d4..9f9a70cf0534 100644 --- a/rules/doctrine-code-quality/src/NodeAnalyzer/ConstructorAssignPropertyAnalyzer.php +++ b/rules/doctrine-code-quality/src/NodeAnalyzer/ConstructorAssignPropertyAnalyzer.php @@ -7,6 +7,7 @@ use PhpParser\Node; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Property; use Rector\Core\PhpParser\Node\BetterNodeFinder; use Rector\Core\ValueObject\MethodName; @@ -39,7 +40,7 @@ public function resolveConstructorAssign(Property $property): ?Node } $constructClassMethod = $classLike->getMethod(MethodName::CONSTRUCT); - if ($constructClassMethod === null) { + if (! $constructClassMethod instanceof ClassMethod) { return null; } diff --git a/rules/doctrine-code-quality/src/NodeAnalyzer/SetterClassMethodAnalyzer.php b/rules/doctrine-code-quality/src/NodeAnalyzer/SetterClassMethodAnalyzer.php index 51df81d38ed9..9aaa9e4a7d2f 100644 --- a/rules/doctrine-code-quality/src/NodeAnalyzer/SetterClassMethodAnalyzer.php +++ b/rules/doctrine-code-quality/src/NodeAnalyzer/SetterClassMethodAnalyzer.php @@ -8,6 +8,7 @@ use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\PropertyFetch; use PhpParser\Node\Expr\Variable; +use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Expression; @@ -38,7 +39,7 @@ public function __construct(NodeTypeResolver $nodeTypeResolver, NodeNameResolver public function matchNullalbeClassMethodProperty(ClassMethod $classMethod): ?Property { $propertyFetch = $this->matchNullalbeClassMethodPropertyFetch($classMethod); - if ($propertyFetch === null) { + if (! $propertyFetch instanceof PropertyFetch) { return null; } @@ -48,7 +49,7 @@ public function matchNullalbeClassMethodProperty(ClassMethod $classMethod): ?Pro public function matchDateTimeSetterProperty(ClassMethod $classMethod): ?Property { $propertyFetch = $this->matchDateTimeSetterPropertyFetch($classMethod); - if ($propertyFetch === null) { + if (! $propertyFetch instanceof PropertyFetch) { return null; } @@ -66,7 +67,7 @@ public function matchDateTimeSetterProperty(ClassMethod $classMethod): ?Property private function matchNullalbeClassMethodPropertyFetch(ClassMethod $classMethod): ?PropertyFetch { $propertyFetch = $this->matchSetterOnlyPropertyFetch($classMethod); - if ($propertyFetch === null) { + if (! $propertyFetch instanceof PropertyFetch) { return null; } @@ -97,7 +98,7 @@ private function getPropertyByPropertyFetch(ClassMethod $classMethod, PropertyFe private function matchDateTimeSetterPropertyFetch(ClassMethod $classMethod): ?PropertyFetch { $propertyFetch = $this->matchSetterOnlyPropertyFetch($classMethod); - if ($propertyFetch === null) { + if (! $propertyFetch instanceof PropertyFetch) { return null; } @@ -127,7 +128,7 @@ private function matchSetterOnlyPropertyFetch(ClassMethod $classMethod): ?Proper } $onlyStmt = $stmts[0] ?? null; - if ($onlyStmt === null) { + if (! $onlyStmt instanceof Stmt) { return null; } diff --git a/rules/doctrine-code-quality/src/Rector/ClassMethod/MakeEntitySetterNullabilityInSyncWithPropertyRector.php b/rules/doctrine-code-quality/src/Rector/ClassMethod/MakeEntitySetterNullabilityInSyncWithPropertyRector.php index 2539b813b93b..14a1bb98dd34 100644 --- a/rules/doctrine-code-quality/src/Rector/ClassMethod/MakeEntitySetterNullabilityInSyncWithPropertyRector.php +++ b/rules/doctrine-code-quality/src/Rector/ClassMethod/MakeEntitySetterNullabilityInSyncWithPropertyRector.php @@ -110,7 +110,7 @@ public function refactor(Node $node): ?Node $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property); $manyToOneTagValueNode = $phpDocInfo->getByType(ManyToOneTagValueNode::class); - if ($manyToOneTagValueNode === null) { + if (! $manyToOneTagValueNode instanceof ManyToOneTagValueNode) { return null; } diff --git a/rules/doctrine-code-quality/src/Rector/Class_/MoveCurrentDateTimeDefaultInEntityToConstructorRector.php b/rules/doctrine-code-quality/src/Rector/Class_/MoveCurrentDateTimeDefaultInEntityToConstructorRector.php index 5f2ef5941e33..4aaafbbb7a27 100644 --- a/rules/doctrine-code-quality/src/Rector/Class_/MoveCurrentDateTimeDefaultInEntityToConstructorRector.php +++ b/rules/doctrine-code-quality/src/Rector/Class_/MoveCurrentDateTimeDefaultInEntityToConstructorRector.php @@ -8,6 +8,7 @@ use PhpParser\Node\Expr; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\Property; +use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\Property_\ColumnTagValueNode; use Rector\Core\Rector\AbstractRector; use Rector\DoctrineCodeQuality\NodeAnalyzer\ColumnDatetimePropertyAnalyzer; use Rector\DoctrineCodeQuality\NodeAnalyzer\ConstructorAssignPropertyAnalyzer; @@ -141,7 +142,7 @@ private function refactorProperty(Property $property, Class_ $class): ?Property $property ); - if ($columnTagValueNode === null) { + if (! $columnTagValueNode instanceof ColumnTagValueNode) { return null; } diff --git a/rules/doctrine-code-quality/src/Rector/MethodCall/ChangeSetParametersArrayToArrayCollectionRector.php b/rules/doctrine-code-quality/src/Rector/MethodCall/ChangeSetParametersArrayToArrayCollectionRector.php index 4453c2cdd8bf..fbaeb1732eed 100644 --- a/rules/doctrine-code-quality/src/Rector/MethodCall/ChangeSetParametersArrayToArrayCollectionRector.php +++ b/rules/doctrine-code-quality/src/Rector/MethodCall/ChangeSetParametersArrayToArrayCollectionRector.php @@ -12,6 +12,7 @@ use PhpParser\Node\Expr\New_; use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Scalar\String_; +use PhpParser\Node\Stmt\ClassLike; use Rector\Core\Exception\ShouldNotHappenException; use Rector\Core\Rector\AbstractRector; use Rector\NodeTypeResolver\Node\AttributeKey; @@ -115,7 +116,7 @@ public function getSomething() private function shouldSkipMethodCall(MethodCall $methodCall): bool { $classLike = $methodCall->getAttribute(AttributeKey::CLASS_NODE); - if ($classLike === null) { + if (! $classLike instanceof ClassLike) { return true; } diff --git a/rules/doctrine-code-quality/src/Rector/Property/ChangeBigIntEntityPropertyToIntTypeRector.php b/rules/doctrine-code-quality/src/Rector/Property/ChangeBigIntEntityPropertyToIntTypeRector.php index f81edde60abb..24bdc608129c 100644 --- a/rules/doctrine-code-quality/src/Rector/Property/ChangeBigIntEntityPropertyToIntTypeRector.php +++ b/rules/doctrine-code-quality/src/Rector/Property/ChangeBigIntEntityPropertyToIntTypeRector.php @@ -6,6 +6,7 @@ use PhpParser\Node; use PhpParser\Node\Stmt\Property; +use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode; use PHPStan\Type\BooleanType; use PHPStan\Type\FloatType; use PHPStan\Type\IntegerType; @@ -102,7 +103,7 @@ public function refactor(Node $node): ?Node } $attributeAwareVarTagValueNode = $phpDocInfo->getVarTagValueNode(); - if ($attributeAwareVarTagValueNode === null) { + if (! $attributeAwareVarTagValueNode instanceof VarTagValueNode) { return null; } diff --git a/rules/doctrine-code-quality/src/Rector/Property/CorrectDefaultTypesOnEntityPropertyRector.php b/rules/doctrine-code-quality/src/Rector/Property/CorrectDefaultTypesOnEntityPropertyRector.php index 2c2fa9139487..db410bcd5c98 100644 --- a/rules/doctrine-code-quality/src/Rector/Property/CorrectDefaultTypesOnEntityPropertyRector.php +++ b/rules/doctrine-code-quality/src/Rector/Property/CorrectDefaultTypesOnEntityPropertyRector.php @@ -5,6 +5,7 @@ namespace Rector\DoctrineCodeQuality\Rector\Property; use PhpParser\Node; +use PhpParser\Node\Expr; use PhpParser\Node\Expr\ConstFetch; use PhpParser\Node\Scalar\LNumber; use PhpParser\Node\Scalar\String_; @@ -86,7 +87,7 @@ public function refactor(Node $node): ?Node $onlyProperty = $node->props[0]; $defaultValue = $onlyProperty->default; - if ($defaultValue === null) { + if (! $defaultValue instanceof Expr) { return null; } diff --git a/rules/doctrine-code-quality/src/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector.php b/rules/doctrine-code-quality/src/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector.php index ede1a1287be8..c5635207a641 100644 --- a/rules/doctrine-code-quality/src/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector.php +++ b/rules/doctrine-code-quality/src/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector.php @@ -9,6 +9,7 @@ use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Property; +use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode; use PHPStan\Type\Type; use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger; use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\Property_\OneToManyTagValueNode; @@ -18,6 +19,7 @@ use Rector\DoctrineCodeQuality\PhpDoc\CollectionTypeResolver; use Rector\DoctrineCodeQuality\PhpDoc\CollectionVarTagValueNodeResolver; use Rector\NodeTypeResolver\Node\AttributeKey; +use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -143,7 +145,7 @@ private function refactorProperty(Property $property): ?Property $property ); - if ($collectionObjectType === null) { + if (! $collectionObjectType instanceof FullyQualifiedObjectType) { return null; } @@ -151,7 +153,7 @@ private function refactorProperty(Property $property): ?Property $this->phpDocTypeChanger->changeVarType($phpDocInfo, $newVarType); } else { $collectionObjectType = $this->collectionTypeResolver->resolveFromOneToManyProperty($property); - if ($collectionObjectType === null) { + if (! $collectionObjectType instanceof FullyQualifiedObjectType) { return null; } @@ -173,7 +175,7 @@ private function refactorClassMethod(ClassMethod $classMethod): ?ClassMethod } $collectionObjectType = $this->resolveCollectionSetterAssignType($classMethod); - if ($collectionObjectType === null) { + if (! $collectionObjectType instanceof Type) { return null; } @@ -208,7 +210,7 @@ private function resolveCollectionSetterAssignType(ClassMethod $classMethod): ?T } $varTagValueNode = $this->collectionVarTagValueNodeResolver->resolve($property); - if ($varTagValueNode === null) { + if (! $varTagValueNode instanceof VarTagValueNode) { return null; } diff --git a/rules/doctrine/src/Rector/Class_/AddUuidMirrorForRelationPropertyRector.php b/rules/doctrine/src/Rector/Class_/AddUuidMirrorForRelationPropertyRector.php index d2a29da5d3d8..03d8465632a6 100644 --- a/rules/doctrine/src/Rector/Class_/AddUuidMirrorForRelationPropertyRector.php +++ b/rules/doctrine/src/Rector/Class_/AddUuidMirrorForRelationPropertyRector.php @@ -189,7 +189,7 @@ private function shouldSkipProperty(Class_ $class, Property $property): bool $oneToOneTagValueNode = $propertyPhpDocInfo->getByType(OneToOneTagValueNode::class); // skip mappedBy oneToOne, as the column doesn't really exist - if ($oneToOneTagValueNode === null) { + if (! $oneToOneTagValueNode instanceof OneToOneTagValueNode) { return false; } return (bool) $oneToOneTagValueNode->getMappedBy(); diff --git a/rules/doctrine/src/Rector/Class_/AlwaysInitializeUuidInEntityRector.php b/rules/doctrine/src/Rector/Class_/AlwaysInitializeUuidInEntityRector.php index 9c36a26260dc..a6d3da085b45 100644 --- a/rules/doctrine/src/Rector/Class_/AlwaysInitializeUuidInEntityRector.php +++ b/rules/doctrine/src/Rector/Class_/AlwaysInitializeUuidInEntityRector.php @@ -8,6 +8,7 @@ use PhpParser\Node; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Property; use PHPStan\Type\ObjectType; use Rector\Core\PhpParser\Node\Manipulator\ClassDependencyManipulator; @@ -106,7 +107,7 @@ public function refactor(Node $node): ?Node } $uuidProperty = $this->resolveUuidPropertyFromClass($node); - if ($uuidProperty === null) { + if (! $uuidProperty instanceof Property) { return null; } @@ -146,7 +147,7 @@ private function resolveUuidPropertyFromClass(Class_ $class): ?Property private function hasUuidInitAlreadyAdded(Class_ $class, string $uuidPropertyName): bool { $constructClassMethod = $class->getMethod(MethodName::CONSTRUCT); - if ($constructClassMethod === null) { + if (! $constructClassMethod instanceof ClassMethod) { return false; } diff --git a/rules/doctrine/src/Rector/Class_/ManagerRegistryGetManagerToEntityManagerRector.php b/rules/doctrine/src/Rector/Class_/ManagerRegistryGetManagerToEntityManagerRector.php index 41e19288a66c..81fc7aa25521 100644 --- a/rules/doctrine/src/Rector/Class_/ManagerRegistryGetManagerToEntityManagerRector.php +++ b/rules/doctrine/src/Rector/Class_/ManagerRegistryGetManagerToEntityManagerRector.php @@ -124,7 +124,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { $constructorClassMethod = $node->getMethod(MethodName::CONSTRUCT); - if ($constructorClassMethod === null) { + if (! $constructorClassMethod instanceof ClassMethod) { return null; } @@ -140,7 +140,7 @@ public function refactor(Node $node): ?Node $managerRegistryParam = $this->resolveManagerRegistryParam($constructorClassMethod); // no registry manager in the constructor - if ($managerRegistryParam === null) { + if (! $managerRegistryParam instanceof Param) { return null; } diff --git a/rules/doctrine/src/Rector/Identical/ChangeIdenticalUuidToEqualsMethodCallRector.php b/rules/doctrine/src/Rector/Identical/ChangeIdenticalUuidToEqualsMethodCallRector.php index 806e43cfd5c2..2244403403ae 100644 --- a/rules/doctrine/src/Rector/Identical/ChangeIdenticalUuidToEqualsMethodCallRector.php +++ b/rules/doctrine/src/Rector/Identical/ChangeIdenticalUuidToEqualsMethodCallRector.php @@ -79,7 +79,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { $twoNodeMatch = $this->matchEntityCallAndComparedVariable($node); - if ($twoNodeMatch === null) { + if (! $twoNodeMatch instanceof TwoNodeMatch) { return null; } diff --git a/rules/doctrine/src/Rector/MethodCall/ChangeSetIdToUuidValueRector.php b/rules/doctrine/src/Rector/MethodCall/ChangeSetIdToUuidValueRector.php index 66843ff7902f..83b23dd9611d 100644 --- a/rules/doctrine/src/Rector/MethodCall/ChangeSetIdToUuidValueRector.php +++ b/rules/doctrine/src/Rector/MethodCall/ChangeSetIdToUuidValueRector.php @@ -9,6 +9,7 @@ use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Scalar\String_; +use PhpParser\Node\Stmt\ClassConst; use PhpParser\Node\Stmt\Expression; use PHPStan\Type\ObjectType; use PHPStan\Type\StringType; @@ -115,7 +116,7 @@ public function refactor(Node $node): ?Node $argumentValue = $node->args[0]->value; if ($argumentValue instanceof ClassConstFetch) { $classConst = $this->nodeRepository->findClassConstByClassConstFetch($argumentValue); - if ($classConst === null) { + if (! $classConst instanceof ClassConst) { return null; } @@ -162,7 +163,7 @@ private function getSetUuidMethodCallOnSameVariable(MethodCall $methodCall): ?Me $parentNode = $parentNode->getAttribute(AttributeKey::PARENT_NODE); } - if ($parentNode === null) { + if (! $parentNode instanceof Node) { return null; } diff --git a/rules/doctrine/src/Rector/Property/AddUuidAnnotationsToIdPropertyRector.php b/rules/doctrine/src/Rector/Property/AddUuidAnnotationsToIdPropertyRector.php index 45929e25346c..0cf6211ad5f4 100644 --- a/rules/doctrine/src/Rector/Property/AddUuidAnnotationsToIdPropertyRector.php +++ b/rules/doctrine/src/Rector/Property/AddUuidAnnotationsToIdPropertyRector.php @@ -115,7 +115,7 @@ public function refactor(Node $node): ?Node private function changeColumnTypeToUuidBinary(PhpDocInfo $phpDocInfo): void { $columnTagValueNode = $phpDocInfo->getByType(ColumnTagValueNode::class); - if ($columnTagValueNode === null) { + if (! $columnTagValueNode instanceof ColumnTagValueNode) { return; } diff --git a/rules/downgrade-php72/src/Rector/ClassMethod/DowngradeParameterTypeWideningRector.php b/rules/downgrade-php72/src/Rector/ClassMethod/DowngradeParameterTypeWideningRector.php index b000e18600f6..4494d4adb060 100644 --- a/rules/downgrade-php72/src/Rector/ClassMethod/DowngradeParameterTypeWideningRector.php +++ b/rules/downgrade-php72/src/Rector/ClassMethod/DowngradeParameterTypeWideningRector.php @@ -135,7 +135,7 @@ private function refactorParamForAncestorsAndSiblings(Param $param, FunctionLike } $classReflection = $scope->getClassReflection(); - if ($classReflection === null) { + if (! $classReflection instanceof ClassReflection) { return; } @@ -168,7 +168,7 @@ private function refactorParamForAncestorsAndSiblings(Param $param, FunctionLike * The interface is also retrieve though, so that method * will eventually be refactored. */ - if ($classMethod === null) { + if (! $classMethod instanceof ClassMethod) { continue; } $this->removeParamTypeFromMethod($ancestorClassOrInterface, $position, $classMethod); @@ -236,7 +236,7 @@ private function removeParamTypeFromMethod( ): void { $classMethodName = $this->getName($classMethod); $currentClassMethod = $classLike->getMethod($classMethodName); - if ($currentClassMethod === null) { + if (! $currentClassMethod instanceof ClassMethod) { return; } @@ -272,7 +272,7 @@ private function removeParamTypeFromMethodForChildren( continue; } $childClassMethod = $this->nodeRepository->findClassMethod($childClassName, $methodName); - if ($childClassMethod === null) { + if (! $childClassMethod instanceof ClassMethod) { continue; } $this->removeParamTypeFromMethod($childClassLike, $position, $childClassMethod); diff --git a/rules/downgrade-php73/src/Rector/List_/DowngradeListReferenceAssignmentRector.php b/rules/downgrade-php73/src/Rector/List_/DowngradeListReferenceAssignmentRector.php index b7ba30c6ff25..6861c9b3bc3d 100644 --- a/rules/downgrade-php73/src/Rector/List_/DowngradeListReferenceAssignmentRector.php +++ b/rules/downgrade-php73/src/Rector/List_/DowngradeListReferenceAssignmentRector.php @@ -167,7 +167,7 @@ private function countRightSideMostParamsByRefOrEmpty(array $listItems): int for ($i = $listItemsCount - 1; $i >= 0; --$i) { $listItem = $listItems[$i]; // Also include null items, since they can be removed - if ($listItem === null || $listItem->byRef) { + if (! $listItem instanceof ArrayItem || $listItem->byRef) { ++$count; continue; } @@ -200,7 +200,7 @@ private function createAssignRefArrayFromListReferences( // After filtering, their original position is kept in the array $newNodes = []; foreach ($listItems as $position => $listItem) { - if ($listItem === null) { + if (! $listItem instanceof ArrayItem) { continue; } if ($listItem->value instanceof Variable && ! $listItem->byRef) { diff --git a/rules/downgrade-php74/src/Rector/ClassMethod/DowngradeContravariantArgumentTypeRector.php b/rules/downgrade-php74/src/Rector/ClassMethod/DowngradeContravariantArgumentTypeRector.php index 1ce8f516aff2..0affa4c3b3a7 100644 --- a/rules/downgrade-php74/src/Rector/ClassMethod/DowngradeContravariantArgumentTypeRector.php +++ b/rules/downgrade-php74/src/Rector/ClassMethod/DowngradeContravariantArgumentTypeRector.php @@ -104,7 +104,7 @@ private function getDifferentParamTypeFromAncestorClass(Param $param, FunctionLi } $classReflection = $scope->getClassReflection(); - if ($classReflection === null) { + if (! $classReflection instanceof ClassReflection) { return null; } diff --git a/rules/downgrade-php74/src/Rector/ClassMethod/DowngradeCovariantReturnTypeRector.php b/rules/downgrade-php74/src/Rector/ClassMethod/DowngradeCovariantReturnTypeRector.php index 2b6230a65eb8..55856bef1764 100644 --- a/rules/downgrade-php74/src/Rector/ClassMethod/DowngradeCovariantReturnTypeRector.php +++ b/rules/downgrade-php74/src/Rector/ClassMethod/DowngradeCovariantReturnTypeRector.php @@ -135,7 +135,7 @@ private function getDifferentReturnTypeNameFromAncestorClass(ClassMethod $classM } $classReflection = $scope->getClassReflection(); - if ($classReflection === null) { + if (! $classReflection instanceof ClassReflection) { return null; } diff --git a/rules/downgrade-php74/src/Rector/Identical/DowngradeFreadFwriteFalsyToNegationRector.php b/rules/downgrade-php74/src/Rector/Identical/DowngradeFreadFwriteFalsyToNegationRector.php index 7799c70ae2ff..06c3aed9f257 100644 --- a/rules/downgrade-php74/src/Rector/Identical/DowngradeFreadFwriteFalsyToNegationRector.php +++ b/rules/downgrade-php74/src/Rector/Identical/DowngradeFreadFwriteFalsyToNegationRector.php @@ -57,7 +57,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { $compareValue = $this->getCompareValue($node); - if ($compareValue === null) { + if (! $compareValue instanceof Expr) { return null; } diff --git a/rules/downgrade-php80/src/Rector/Class_/DowngradePropertyPromotionRector.php b/rules/downgrade-php80/src/Rector/Class_/DowngradePropertyPromotionRector.php index 85faa41e5643..3f05fa84f498 100644 --- a/rules/downgrade-php80/src/Rector/Class_/DowngradePropertyPromotionRector.php +++ b/rules/downgrade-php80/src/Rector/Class_/DowngradePropertyPromotionRector.php @@ -98,7 +98,7 @@ public function refactor(Node $node): ?Node private function resolvePromotedParams(Class_ $class): array { $constructorClassMethod = $class->getMethod(MethodName::CONSTRUCT); - if ($constructorClassMethod === null) { + if (! $constructorClassMethod instanceof \PhpParser\Node\Stmt\ClassMethod) { return []; } diff --git a/rules/early-return/src/NodeTransformer/ConditionInverter.php b/rules/early-return/src/NodeTransformer/ConditionInverter.php index 48774e7ea305..9d6c7be1cb9a 100644 --- a/rules/early-return/src/NodeTransformer/ConditionInverter.php +++ b/rules/early-return/src/NodeTransformer/ConditionInverter.php @@ -27,7 +27,7 @@ public function createInvertedCondition(Expr $expr): Expr // inverse condition if ($expr instanceof BinaryOp) { $inversedCondition = $this->binaryOpManipulator->invertCondition($expr); - if ($inversedCondition === null) { + if (! $inversedCondition instanceof BinaryOp) { return new BooleanNot($expr); } if ($inversedCondition instanceof BooleanAnd) { diff --git a/rules/early-return/src/Rector/If_/ChangeAndIfToEarlyReturnRector.php b/rules/early-return/src/Rector/If_/ChangeAndIfToEarlyReturnRector.php index b210f9cc3f84..64331806e380 100644 --- a/rules/early-return/src/Rector/If_/ChangeAndIfToEarlyReturnRector.php +++ b/rules/early-return/src/Rector/If_/ChangeAndIfToEarlyReturnRector.php @@ -118,7 +118,7 @@ public function refactor(Node $node): ?Node } $ifReturn = $this->getIfReturn($node); - if ($ifReturn === null) { + if (! $ifReturn instanceof Stmt) { return null; } @@ -303,7 +303,7 @@ private function isNestedIfInLoop(If_ $if): bool private function isLastIfOrBeforeLastReturn(If_ $if): bool { $nextNode = $if->getAttribute(AttributeKey::NEXT_NODE); - if ($nextNode === null) { + if (! $nextNode instanceof Node) { return true; } return $nextNode instanceof Return_; diff --git a/rules/generic/src/Rector/ClassMethod/AddMethodParentCallRector.php b/rules/generic/src/Rector/ClassMethod/AddMethodParentCallRector.php index c4f7491379df..06b1bdbf6c3a 100644 --- a/rules/generic/src/Rector/ClassMethod/AddMethodParentCallRector.php +++ b/rules/generic/src/Rector/ClassMethod/AddMethodParentCallRector.php @@ -5,6 +5,7 @@ namespace Rector\Generic\Rector\ClassMethod; use PhpParser\Node; +use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Expression; use Rector\Core\Contract\Rector\ConfigurableRectorInterface; @@ -80,7 +81,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { $classLike = $node->getAttribute(AttributeKey::CLASS_NODE); - if ($classLike === null) { + if (! $classLike instanceof ClassLike) { return null; } diff --git a/rules/generic/src/Rector/Property/AnnotatedPropertyInjectToConstructorInjectionRector.php b/rules/generic/src/Rector/Property/AnnotatedPropertyInjectToConstructorInjectionRector.php index 4035faa4d59f..2270ca33e933 100644 --- a/rules/generic/src/Rector/Property/AnnotatedPropertyInjectToConstructorInjectionRector.php +++ b/rules/generic/src/Rector/Property/AnnotatedPropertyInjectToConstructorInjectionRector.php @@ -6,6 +6,7 @@ use PhpParser\Node; use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\Property; use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover; use Rector\Core\Rector\AbstractRector; @@ -127,7 +128,7 @@ private function shouldSkipProperty(Property $property): bool } $classLike = $property->getAttribute(AttributeKey::CLASS_NODE); - if ($classLike === null) { + if (! $classLike instanceof ClassLike) { return true; } diff --git a/rules/generic/src/Rector/Property/ChangePropertyVisibilityRector.php b/rules/generic/src/Rector/Property/ChangePropertyVisibilityRector.php index 2152a70dc538..35311f42e848 100644 --- a/rules/generic/src/Rector/Property/ChangePropertyVisibilityRector.php +++ b/rules/generic/src/Rector/Property/ChangePropertyVisibilityRector.php @@ -5,6 +5,7 @@ namespace Rector\Generic\Rector\Property; use PhpParser\Node; +use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\Property; use Rector\Core\Contract\Rector\ConfigurableRectorInterface; use Rector\Core\Rector\AbstractRector; @@ -85,7 +86,7 @@ public function refactor(Node $node): ?Node { foreach ($this->propertyToVisibilityByClass as $type => $propertyToVisibility) { $classNode = $node->getAttribute(AttributeKey::CLASS_NODE); - if ($classNode === null) { + if (! $classNode instanceof ClassLike) { continue; } diff --git a/rules/laravel/src/Rector/Assign/CallOnAppArrayAccessToStandaloneAssignRector.php b/rules/laravel/src/Rector/Assign/CallOnAppArrayAccessToStandaloneAssignRector.php index 4e8752d944ad..47ba83f486ef 100644 --- a/rules/laravel/src/Rector/Assign/CallOnAppArrayAccessToStandaloneAssignRector.php +++ b/rules/laravel/src/Rector/Assign/CallOnAppArrayAccessToStandaloneAssignRector.php @@ -5,6 +5,7 @@ namespace Rector\Laravel\Rector\Assign; use PhpParser\Node; +use PhpParser\Node\Expr; use PhpParser\Node\Expr\ArrayDimFetch; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\MethodCall; @@ -68,7 +69,7 @@ public function refactor(Node $node): ?Node } $arrayDimFetchDim = $methodCall->var->dim; - if ($arrayDimFetchDim === null) { + if (! $arrayDimFetchDim instanceof Expr) { return null; } diff --git a/rules/laravel/src/Rector/Class_/PropertyDeferToDeferrableProviderToRector.php b/rules/laravel/src/Rector/Class_/PropertyDeferToDeferrableProviderToRector.php index effeefaf38d6..8ac470033436 100644 --- a/rules/laravel/src/Rector/Class_/PropertyDeferToDeferrableProviderToRector.php +++ b/rules/laravel/src/Rector/Class_/PropertyDeferToDeferrableProviderToRector.php @@ -68,7 +68,7 @@ public function refactor(Node $node): ?Node } $deferProperty = $this->matchDeferWithFalseProperty($node); - if ($deferProperty === null) { + if (! $deferProperty instanceof Property) { return null; } diff --git a/rules/laravel/src/Rector/MethodCall/ChangeQueryWhereDateValueWithCarbonRector.php b/rules/laravel/src/Rector/MethodCall/ChangeQueryWhereDateValueWithCarbonRector.php index 64f175886540..d08d0287a97b 100644 --- a/rules/laravel/src/Rector/MethodCall/ChangeQueryWhereDateValueWithCarbonRector.php +++ b/rules/laravel/src/Rector/MethodCall/ChangeQueryWhereDateValueWithCarbonRector.php @@ -75,7 +75,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { $argValue = $this->matchWhereDateThirdArgValue($node); - if ($argValue === null) { + if (! $argValue instanceof Expr) { return null; } diff --git a/rules/laravel/src/Rector/New_/MakeTaggedPassedToParameterIterableTypeRector.php b/rules/laravel/src/Rector/New_/MakeTaggedPassedToParameterIterableTypeRector.php index b9c6ba8d49fd..d84765dd3649 100644 --- a/rules/laravel/src/Rector/New_/MakeTaggedPassedToParameterIterableTypeRector.php +++ b/rules/laravel/src/Rector/New_/MakeTaggedPassedToParameterIterableTypeRector.php @@ -7,7 +7,9 @@ use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr\New_; +use PhpParser\Node\Param; use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Stmt\ClassMethod; use Rector\Core\Rector\AbstractRector; use Rector\Core\ValueObject\MethodName; use Rector\NodeTypeResolver\Node\AttributeKey; @@ -95,7 +97,7 @@ public function refactor(Node $node): ?Node } $class = $this->nodeRepository->findClass($className); - if ($class === null) { + if (! $class instanceof Class_) { return null; } @@ -113,12 +115,12 @@ private function refactorClassWithArgType(Class_ $class, Arg $arg): void $constructClassMethod = $class->getMethod(MethodName::CONSTRUCT); $argumentPosition = (int) $arg->getAttribute(AttributeKey::ARGUMENT_POSITION); - if ($constructClassMethod === null) { + if (! $constructClassMethod instanceof ClassMethod) { return; } $param = $constructClassMethod->params[$argumentPosition] ?? null; - if ($param === null) { + if (! $param instanceof Param) { return; } diff --git a/rules/laravel/src/Rector/StaticCall/MinutesToSecondsInCacheRector.php b/rules/laravel/src/Rector/StaticCall/MinutesToSecondsInCacheRector.php index c00490bd1db1..8f179793af26 100644 --- a/rules/laravel/src/Rector/StaticCall/MinutesToSecondsInCacheRector.php +++ b/rules/laravel/src/Rector/StaticCall/MinutesToSecondsInCacheRector.php @@ -12,6 +12,7 @@ use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Scalar\LNumber; +use PhpParser\Node\Stmt\ClassConst; use Rector\Core\Rector\AbstractRector; use Rector\Laravel\ValueObject\TypeToTimeMethodAndPosition; use Rector\NodeCollector\NodeCollector\ParsedNodeCollector; @@ -160,7 +161,7 @@ private function processArgumentOnPosition(Node $node, Expr $argExpr, int $argum private function refactorClassConstFetch(ClassConstFetch $classConstFetch): void { $classConst = $this->nodeRepository->findClassConstByClassConstFetch($classConstFetch); - if ($classConst === null) { + if (! $classConst instanceof ClassConst) { return; } diff --git a/rules/legacy/src/Rector/Class_/ChangeSingletonToServiceRector.php b/rules/legacy/src/Rector/Class_/ChangeSingletonToServiceRector.php index b8246fc9c09f..51e55b6f08ac 100644 --- a/rules/legacy/src/Rector/Class_/ChangeSingletonToServiceRector.php +++ b/rules/legacy/src/Rector/Class_/ChangeSingletonToServiceRector.php @@ -5,6 +5,7 @@ namespace Rector\Legacy\Rector\Class_; use PhpParser\Node; +use PhpParser\Node\Expr\StaticPropertyFetch; use PhpParser\Node\Stmt\Class_; use Rector\Core\Rector\AbstractRector; use Rector\Core\ValueObject\MethodName; @@ -88,7 +89,7 @@ public function refactor(Node $node): ?Node } $propertyAndClassMethodName = $this->matchStaticPropertyFetchAndGetSingletonMethodName($node); - if ($propertyAndClassMethodName === null) { + if (! $propertyAndClassMethodName instanceof PropertyAndClassMethodName) { return null; } @@ -103,7 +104,7 @@ private function matchStaticPropertyFetchAndGetSingletonMethodName(Class_ $class } $staticPropertyFetch = $this->singletonClassMethodAnalyzer->matchStaticPropertyFetch($classMethod); - if ($staticPropertyFetch === null) { + if (! $staticPropertyFetch instanceof StaticPropertyFetch) { return null; } diff --git a/rules/mockista-to-mockery/src/Rector/Class_/MockeryTearDownRector.php b/rules/mockista-to-mockery/src/Rector/Class_/MockeryTearDownRector.php index d65d95b4b219..367034dc2049 100644 --- a/rules/mockista-to-mockery/src/Rector/Class_/MockeryTearDownRector.php +++ b/rules/mockista-to-mockery/src/Rector/Class_/MockeryTearDownRector.php @@ -88,7 +88,7 @@ public function refactor(Node $node): ?Node } $tearDownClassMethod = $node->getMethod(MethodName::TEAR_DOWN); - if ($tearDownClassMethod === null) { + if (! $tearDownClassMethod instanceof ClassMethod) { $node->stmts[] = $this->createTearDownMethodWithMockeryClose(); } elseif (! $this->containsMockeryClose($tearDownClassMethod)) { $tearDownClassMethod->stmts[] = $this->createMockeryClose(); diff --git a/rules/mysql-to-mysqli/src/Rector/FuncCall/MysqlQueryMysqlErrorWithLinkRector.php b/rules/mysql-to-mysqli/src/Rector/FuncCall/MysqlQueryMysqlErrorWithLinkRector.php index afed8dcf29d6..7c1e99295d78 100644 --- a/rules/mysql-to-mysqli/src/Rector/FuncCall/MysqlQueryMysqlErrorWithLinkRector.php +++ b/rules/mysql-to-mysqli/src/Rector/FuncCall/MysqlQueryMysqlErrorWithLinkRector.php @@ -139,7 +139,7 @@ public function refactor(Node $node): ?Node $this->removeExistingConnectionParameter($node); - if ($connectionVariable === null) { + if (! $connectionVariable instanceof Expr) { return null; } diff --git a/rules/naming/src/ExpectedNameResolver/MatchParamTypeExpectedNameResolver.php b/rules/naming/src/ExpectedNameResolver/MatchParamTypeExpectedNameResolver.php index 3a71b35a23ab..ed4692cb5e01 100644 --- a/rules/naming/src/ExpectedNameResolver/MatchParamTypeExpectedNameResolver.php +++ b/rules/naming/src/ExpectedNameResolver/MatchParamTypeExpectedNameResolver.php @@ -7,6 +7,7 @@ use PhpParser\Node; use PhpParser\Node\Param; use Rector\Naming\Naming\PropertyNaming; +use Rector\Naming\ValueObject\ExpectedName; use Rector\StaticTypeMapper\StaticTypeMapper; final class MatchParamTypeExpectedNameResolver extends AbstractExpectedNameResolver @@ -44,7 +45,7 @@ public function resolve(Node $node): ?string $staticType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($node->type); $expectedName = $this->propertyNaming->getExpectedNameFromType($staticType); - if ($expectedName === null) { + if (! $expectedName instanceof ExpectedName) { return null; } diff --git a/rules/naming/src/ExpectedNameResolver/MatchPropertyTypeExpectedNameResolver.php b/rules/naming/src/ExpectedNameResolver/MatchPropertyTypeExpectedNameResolver.php index 281705ebeda9..ee5bdfb239b9 100644 --- a/rules/naming/src/ExpectedNameResolver/MatchPropertyTypeExpectedNameResolver.php +++ b/rules/naming/src/ExpectedNameResolver/MatchPropertyTypeExpectedNameResolver.php @@ -8,6 +8,7 @@ use PhpParser\Node\Stmt\Property; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\Naming\Naming\PropertyNaming; +use Rector\Naming\ValueObject\ExpectedName; final class MatchPropertyTypeExpectedNameResolver extends AbstractExpectedNameResolver { @@ -35,7 +36,7 @@ public function resolve(Node $node): ?string $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node); $expectedName = $this->propertyNaming->getExpectedNameFromType($phpDocInfo->getVarType()); - if ($expectedName === null) { + if (! $expectedName instanceof ExpectedName) { return null; } diff --git a/rules/naming/src/Naming/ExpectedNameResolver.php b/rules/naming/src/Naming/ExpectedNameResolver.php index 4087d4e154e4..7ee0200e8f65 100644 --- a/rules/naming/src/Naming/ExpectedNameResolver.php +++ b/rules/naming/src/Naming/ExpectedNameResolver.php @@ -20,6 +20,7 @@ use PHPStan\Type\ObjectType; use PHPStan\Type\Type; use Rector\Naming\ExpectedNameResolver\MatchParamTypeExpectedNameResolver; +use Rector\Naming\ValueObject\ExpectedName; use Rector\NodeNameResolver\NodeNameResolver; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\NodeTypeResolver\NodeTypeResolver; @@ -119,7 +120,7 @@ public function resolveForAssignNew(Assign $assign): ?string $fullyQualifiedObjectType = new FullyQualifiedObjectType($className); $expectedName = $this->propertyNaming->getExpectedNameFromType($fullyQualifiedObjectType); - if ($expectedName === null) { + if (! $expectedName instanceof ExpectedName) { return null; } @@ -190,7 +191,7 @@ public function resolveForForeach(Expr $expr): ?string if ($returnedType instanceof ArrayType) { $returnedType = $this->resolveReturnTypeFromArrayType($expr, $returnedType); - if ($returnedType === null) { + if (! $returnedType instanceof Type) { return null; } } @@ -202,7 +203,7 @@ public function resolveForForeach(Expr $expr): ?string } $expectedNameFromMethodName = $this->propertyNaming->getExpectedNameFromMethodName($name); - if ($expectedNameFromMethodName === null) { + if (! $expectedNameFromMethodName instanceof ExpectedName) { return null; } diff --git a/rules/naming/src/Naming/PropertyNaming.php b/rules/naming/src/Naming/PropertyNaming.php index 25a24e1729ef..0d26f10c2592 100644 --- a/rules/naming/src/Naming/PropertyNaming.php +++ b/rules/naming/src/Naming/PropertyNaming.php @@ -5,6 +5,8 @@ namespace Rector\Naming\Naming; use Nette\Utils\Strings; +use PhpParser\Node\Expr; +use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Property; use PhpParser\Node\Stmt\Return_; @@ -296,7 +298,7 @@ private function removeInterfaceSuffixPrefix(string $className, string $shortNam private function getPrefixedClassMethods(Property $property): array { $classLike = $property->getAttribute(AttributeKey::CLASS_NODE); - if ($classLike === null) { + if (! $classLike instanceof ClassLike) { return []; } @@ -333,7 +335,7 @@ private function filterClassMethodsWithPropertyFetchReturnOnly( } $node = $return->expr; - if ($node === null) { + if (! $node instanceof Expr) { return false; } diff --git a/rules/naming/src/Rector/ClassMethod/MakeGetterClassMethodNameStartWithGetRector.php b/rules/naming/src/Rector/ClassMethod/MakeGetterClassMethodNameStartWithGetRector.php index 147b8d6cd0eb..3bf99613720f 100644 --- a/rules/naming/src/Rector/ClassMethod/MakeGetterClassMethodNameStartWithGetRector.php +++ b/rules/naming/src/Rector/ClassMethod/MakeGetterClassMethodNameStartWithGetRector.php @@ -103,7 +103,7 @@ public function refactor(Node $node): ?Node } $getterClassMethodReturnedExpr = $this->matchGetterClassMethodReturnedExpr($node); - if ($getterClassMethodReturnedExpr === null) { + if (! $getterClassMethodReturnedExpr instanceof Expr) { return null; } diff --git a/rules/naming/src/Rector/ClassMethod/MakeIsserClassMethodNameStartWithIsRector.php b/rules/naming/src/Rector/ClassMethod/MakeIsserClassMethodNameStartWithIsRector.php index 3ebe864baacb..5558d2e66aff 100644 --- a/rules/naming/src/Rector/ClassMethod/MakeIsserClassMethodNameStartWithIsRector.php +++ b/rules/naming/src/Rector/ClassMethod/MakeIsserClassMethodNameStartWithIsRector.php @@ -104,7 +104,7 @@ public function refactor(Node $node): ?Node } $getterClassMethodReturnedExpr = $this->matchIsserClassMethodReturnedExpr($node); - if ($getterClassMethodReturnedExpr === null) { + if (! $getterClassMethodReturnedExpr instanceof Expr) { return null; } diff --git a/rules/naming/src/Rector/ClassMethod/RenameParamToMatchTypeRector.php b/rules/naming/src/Rector/ClassMethod/RenameParamToMatchTypeRector.php index 3874eb0bac93..e6f645e36be0 100644 --- a/rules/naming/src/Rector/ClassMethod/RenameParamToMatchTypeRector.php +++ b/rules/naming/src/Rector/ClassMethod/RenameParamToMatchTypeRector.php @@ -13,6 +13,7 @@ use Rector\Naming\Guard\BreakingVariableRenameGuard; use Rector\Naming\Naming\ExpectedNameResolver; use Rector\Naming\ParamRenamer\ParamRenamer; +use Rector\Naming\ValueObject\ParamRename; use Rector\Naming\ValueObjectFactory\ParamRenameFactory; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -119,12 +120,12 @@ public function refactor(Node $node): ?Node } $paramRename = $this->paramRenameFactory->create($param, $this->matchParamTypeExpectedNameResolver); - if ($paramRename === null) { + if (! $paramRename instanceof ParamRename) { continue; } $matchTypeParamRenamerRename = $this->paramRenamer->rename($paramRename); - if ($matchTypeParamRenamerRename === null) { + if (! $matchTypeParamRenamerRename instanceof Param) { continue; } diff --git a/rules/naming/src/Rector/Class_/RenamePropertyToMatchTypeRector.php b/rules/naming/src/Rector/Class_/RenamePropertyToMatchTypeRector.php index 6a1aa6fc331a..26e553052f09 100644 --- a/rules/naming/src/Rector/Class_/RenamePropertyToMatchTypeRector.php +++ b/rules/naming/src/Rector/Class_/RenamePropertyToMatchTypeRector.php @@ -7,7 +7,9 @@ use PhpParser\Node; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassLike; +use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Interface_; +use PhpParser\Node\Stmt\Property; use Rector\Core\Rector\AbstractRector; use Rector\Core\ValueObject\MethodName; use Rector\Core\ValueObject\PhpVersionFeature; @@ -15,6 +17,7 @@ use Rector\Naming\ExpectedNameResolver\MatchPropertyTypeExpectedNameResolver; use Rector\Naming\PropertyRenamer\MatchTypePropertyRenamer; use Rector\Naming\PropertyRenamer\PropertyFetchRenamer; +use Rector\Naming\ValueObject\PropertyRename; use Rector\Naming\ValueObjectFactory\PropertyRenameFactory; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -138,12 +141,12 @@ private function refactorClassProperties(ClassLike $classLike): void $property, $this->matchPropertyTypeExpectedNameResolver ); - if ($propertyRename === null) { + if (! $propertyRename instanceof PropertyRename) { continue; } $renameProperty = $this->matchTypePropertyRenamer->rename($propertyRename); - if ($renameProperty === null) { + if (! $renameProperty instanceof Property) { continue; } @@ -158,7 +161,7 @@ private function renamePropertyPromotion(ClassLike $classLike): void } $constructClassMethod = $classLike->getMethod(MethodName::CONSTRUCT); - if ($constructClassMethod === null) { + if (! $constructClassMethod instanceof ClassMethod) { return; } diff --git a/rules/naming/src/Rector/Property/MakeBoolPropertyRespectIsHasWasMethodNamingRector.php b/rules/naming/src/Rector/Property/MakeBoolPropertyRespectIsHasWasMethodNamingRector.php index 6fb68d64439c..2f01ae26cd80 100644 --- a/rules/naming/src/Rector/Property/MakeBoolPropertyRespectIsHasWasMethodNamingRector.php +++ b/rules/naming/src/Rector/Property/MakeBoolPropertyRespectIsHasWasMethodNamingRector.php @@ -9,6 +9,7 @@ use Rector\Core\Rector\AbstractRector; use Rector\Naming\ExpectedNameResolver\BoolPropertyExpectedNameResolver; use Rector\Naming\PropertyRenamer\BoolPropertyRenamer; +use Rector\Naming\ValueObject\PropertyRename; use Rector\Naming\ValueObjectFactory\PropertyRenameFactory; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -99,7 +100,7 @@ public function refactor(Node $node): ?Node } $propertyRename = $this->propertyRenameFactory->create($node, $this->boolPropertyExpectedNameResolver); - if ($propertyRename === null) { + if (! $propertyRename instanceof PropertyRename) { return null; } diff --git a/rules/naming/src/Rector/Property/UnderscoreToCamelCasePropertyNameRector.php b/rules/naming/src/Rector/Property/UnderscoreToCamelCasePropertyNameRector.php index ee74070d64de..75b16fa36254 100644 --- a/rules/naming/src/Rector/Property/UnderscoreToCamelCasePropertyNameRector.php +++ b/rules/naming/src/Rector/Property/UnderscoreToCamelCasePropertyNameRector.php @@ -10,6 +10,7 @@ use Rector\Core\Rector\AbstractRector; use Rector\Naming\ExpectedNameResolver\UnderscoreCamelCaseExpectedNameResolver; use Rector\Naming\PropertyRenamer\UnderscoreCamelCasePropertyRenamer; +use Rector\Naming\ValueObject\PropertyRename; use Rector\Naming\ValueObjectFactory\PropertyRenameFactory; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -94,7 +95,7 @@ public function refactor(Node $node): ?Node } $propertyRename = $this->propertyRenameFactory->create($node, $this->underscoreCamelCaseExpectedNameResolver); - if ($propertyRename === null) { + if (! $propertyRename instanceof PropertyRename) { return null; } $property = $this->underscoreCamelCasePropertyRenamer->rename($propertyRename); diff --git a/rules/naming/src/Rector/Variable/UnderscoreToCamelCaseVariableNameRector.php b/rules/naming/src/Rector/Variable/UnderscoreToCamelCaseVariableNameRector.php index 6fca00fc0048..899f2012dc06 100644 --- a/rules/naming/src/Rector/Variable/UnderscoreToCamelCaseVariableNameRector.php +++ b/rules/naming/src/Rector/Variable/UnderscoreToCamelCaseVariableNameRector.php @@ -13,6 +13,7 @@ use Rector\Core\Util\StaticRectorStrings; use Rector\Naming\ExpectedNameResolver\UnderscoreCamelCaseExpectedNameResolver; use Rector\Naming\ParamRenamer\ParamRenamer; +use Rector\Naming\ValueObject\ParamRename; use Rector\Naming\ValueObjectFactory\ParamRenameFactory; use Rector\NodeTypeResolver\Node\AttributeKey; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -132,12 +133,12 @@ public function refactor(Node $node): ?Node private function renameParam(Param $param): ?Variable { $paramRename = $this->paramRenameFactory->create($param, $this->underscoreCamelCaseExpectedNameResolver); - if ($paramRename === null) { + if (! $paramRename instanceof ParamRename) { return null; } $renamedParam = $this->paramRenamer->rename($paramRename); - if ($renamedParam === null) { + if (! $renamedParam instanceof Param) { return null; } diff --git a/rules/naming/src/ValueObjectFactory/PropertyRenameFactory.php b/rules/naming/src/ValueObjectFactory/PropertyRenameFactory.php index 8ffbafa81932..143ea762c9da 100644 --- a/rules/naming/src/ValueObjectFactory/PropertyRenameFactory.php +++ b/rules/naming/src/ValueObjectFactory/PropertyRenameFactory.php @@ -4,6 +4,7 @@ namespace Rector\Naming\ValueObjectFactory; +use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\Property; use Rector\Naming\Contract\ExpectedNameResolver\ExpectedNameResolverInterface; use Rector\Naming\ValueObject\PropertyRename; @@ -39,7 +40,7 @@ public function create(Property $property, ExpectedNameResolverInterface $expect $currentName = $this->nodeNameResolver->getName($property); $propertyClassLike = $property->getAttribute(AttributeKey::CLASS_NODE); - if ($propertyClassLike === null) { + if (! $propertyClassLike instanceof ClassLike) { return null; } diff --git a/rules/nette-code-quality/src/FormControlTypeResolver/ArrayDimFetchControlTypeResolver.php b/rules/nette-code-quality/src/FormControlTypeResolver/ArrayDimFetchControlTypeResolver.php index 3fd62d69ee8e..3dca8107844a 100644 --- a/rules/nette-code-quality/src/FormControlTypeResolver/ArrayDimFetchControlTypeResolver.php +++ b/rules/nette-code-quality/src/FormControlTypeResolver/ArrayDimFetchControlTypeResolver.php @@ -71,7 +71,7 @@ public function resolve(Node $node): array } $createComponentClassMethod = $this->matchCreateComponentClassMethod($node, $controlShortName); - if ($createComponentClassMethod === null) { + if (! $createComponentClassMethod instanceof ClassMethod) { return []; } diff --git a/rules/nette-code-quality/src/FormControlTypeResolver/MagicNetteFactoryInterfaceFormControlTypeResolver.php b/rules/nette-code-quality/src/FormControlTypeResolver/MagicNetteFactoryInterfaceFormControlTypeResolver.php index 204d4ab41eac..dc7af652b858 100644 --- a/rules/nette-code-quality/src/FormControlTypeResolver/MagicNetteFactoryInterfaceFormControlTypeResolver.php +++ b/rules/nette-code-quality/src/FormControlTypeResolver/MagicNetteFactoryInterfaceFormControlTypeResolver.php @@ -6,6 +6,7 @@ use PhpParser\Node; use PhpParser\Node\Expr\MethodCall; +use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Interface_; use PHPStan\Type\TypeWithClassName; use Rector\Core\ValueObject\MethodName; @@ -64,7 +65,7 @@ public function resolve(Node $node): array } $classMethod = $this->nodeRepository->findClassMethodByMethodCall($node); - if ($classMethod === null) { + if (! $classMethod instanceof ClassMethod) { return []; } @@ -85,7 +86,7 @@ public function resolve(Node $node): array MethodName::CONSTRUCT ); - if ($constructorClassMethod === null) { + if (! $constructorClassMethod instanceof ClassMethod) { return []; } diff --git a/rules/nette-code-quality/src/FormControlTypeResolver/MethodCallFormControlTypeResolver.php b/rules/nette-code-quality/src/FormControlTypeResolver/MethodCallFormControlTypeResolver.php index eb7419a1ace8..04507a8eacc8 100644 --- a/rules/nette-code-quality/src/FormControlTypeResolver/MethodCallFormControlTypeResolver.php +++ b/rules/nette-code-quality/src/FormControlTypeResolver/MethodCallFormControlTypeResolver.php @@ -6,6 +6,7 @@ use PhpParser\Node; use PhpParser\Node\Expr\MethodCall; +use PhpParser\Node\Stmt\ClassMethod; use Rector\NetteCodeQuality\Contract\FormControlTypeResolverInterface; use Rector\NetteCodeQuality\Contract\MethodNamesByInputNamesResolverAwareInterface; use Rector\NetteCodeQuality\NodeResolver\MethodNamesByInputNamesResolver; @@ -49,7 +50,7 @@ public function resolve(Node $node): array } $classMethod = $this->nodeRepository->findClassMethodByMethodCall($node); - if ($classMethod === null) { + if (! $classMethod instanceof ClassMethod) { return []; } diff --git a/rules/nette-code-quality/src/FormControlTypeResolver/NewFormControlTypeResolver.php b/rules/nette-code-quality/src/FormControlTypeResolver/NewFormControlTypeResolver.php index e78fca4a8df8..e811608aaf41 100644 --- a/rules/nette-code-quality/src/FormControlTypeResolver/NewFormControlTypeResolver.php +++ b/rules/nette-code-quality/src/FormControlTypeResolver/NewFormControlTypeResolver.php @@ -6,6 +6,7 @@ use PhpParser\Node; use PhpParser\Node\Expr\New_; +use PhpParser\Node\Stmt\ClassMethod; use Rector\Core\ValueObject\MethodName; use Rector\NetteCodeQuality\Contract\FormControlTypeResolverInterface; use Rector\NetteCodeQuality\Contract\MethodNamesByInputNamesResolverAwareInterface; @@ -51,7 +52,7 @@ public function resolve(Node $node): array } $constructorClassMethod = $this->nodeRepository->findClassMethod($className, MethodName::CONSTRUCT); - if ($constructorClassMethod === null) { + if (! $constructorClassMethod instanceof ClassMethod) { return []; } diff --git a/rules/nette-code-quality/src/FormControlTypeResolver/ThisVariableInAnotherMethodFormControlTypeResolver.php b/rules/nette-code-quality/src/FormControlTypeResolver/ThisVariableInAnotherMethodFormControlTypeResolver.php index b9eda330bf4c..f7c51f287dbb 100644 --- a/rules/nette-code-quality/src/FormControlTypeResolver/ThisVariableInAnotherMethodFormControlTypeResolver.php +++ b/rules/nette-code-quality/src/FormControlTypeResolver/ThisVariableInAnotherMethodFormControlTypeResolver.php @@ -7,6 +7,7 @@ use PhpParser\Node; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Stmt\ClassMethod; use Rector\Core\ValueObject\MethodName; use Rector\NetteCodeQuality\Contract\FormControlTypeResolverInterface; use Rector\NetteCodeQuality\Contract\MethodNamesByInputNamesResolverAwareInterface; @@ -42,7 +43,7 @@ public function resolve(Node $node): array } $constructClassMethod = $classLike->getMethod(MethodName::CONSTRUCT); - if ($constructClassMethod === null) { + if (! $constructClassMethod instanceof ClassMethod) { return []; } diff --git a/rules/nette-code-quality/src/FormControlTypeResolver/VariableConstructorFormControlTypeResolver.php b/rules/nette-code-quality/src/FormControlTypeResolver/VariableConstructorFormControlTypeResolver.php index 18fba2a513d1..402557ea01de 100644 --- a/rules/nette-code-quality/src/FormControlTypeResolver/VariableConstructorFormControlTypeResolver.php +++ b/rules/nette-code-quality/src/FormControlTypeResolver/VariableConstructorFormControlTypeResolver.php @@ -6,6 +6,7 @@ use PhpParser\Node; use PhpParser\Node\Expr\Variable; +use PhpParser\Node\Stmt\ClassMethod; use PHPStan\Type\TypeWithClassName; use Rector\Core\ValueObject\MethodName; use Rector\NetteCodeQuality\Contract\FormControlTypeResolverInterface; @@ -74,7 +75,7 @@ public function resolve(Node $node): array $formType->getClassName(), MethodName::CONSTRUCT ); - if ($constructorClassMethod === null) { + if (! $constructorClassMethod instanceof ClassMethod) { return []; } diff --git a/rules/nette-code-quality/src/Rector/Class_/MoveInjectToExistingConstructorRector.php b/rules/nette-code-quality/src/Rector/Class_/MoveInjectToExistingConstructorRector.php index 7e62ab4150be..e19bf90b7a07 100644 --- a/rules/nette-code-quality/src/Rector/Class_/MoveInjectToExistingConstructorRector.php +++ b/rules/nette-code-quality/src/Rector/Class_/MoveInjectToExistingConstructorRector.php @@ -6,6 +6,7 @@ use PhpParser\Node; use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Property; use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover; use Rector\Core\Rector\AbstractRector; @@ -110,7 +111,7 @@ public function refactor(Node $node): ?Node } $constructClassMethod = $node->getMethod(MethodName::CONSTRUCT); - if ($constructClassMethod === null) { + if (! $constructClassMethod instanceof ClassMethod) { return null; } diff --git a/rules/nette-kdyby/src/Naming/VariableNaming.php b/rules/nette-kdyby/src/Naming/VariableNaming.php index 44f2279a201b..0a55b85beb92 100644 --- a/rules/nette-kdyby/src/Naming/VariableNaming.php +++ b/rules/nette-kdyby/src/Naming/VariableNaming.php @@ -165,7 +165,7 @@ private function resolveBareFromNode(Node $node): ?string return $this->resolveFromNode($node->name); } - if ($node === null) { + if (! $node instanceof Node) { throw new NotImplementedException(); } @@ -253,7 +253,7 @@ private function resolveFromPropertyFetch(PropertyFetch $propertyFetch): string private function isCall(?Node $node): bool { - if ($node === null) { + if (! $node instanceof Node) { return false; } @@ -262,7 +262,7 @@ private function isCall(?Node $node): bool private function resolveFromMethodCall(?Node $node): ?string { - if ($node === null) { + if (! $node instanceof Node) { return null; } diff --git a/rules/nette-kdyby/src/NodeResolver/ListeningMethodsCollector.php b/rules/nette-kdyby/src/NodeResolver/ListeningMethodsCollector.php index 0ee0bdc22b4a..1c16a4817df6 100644 --- a/rules/nette-kdyby/src/NodeResolver/ListeningMethodsCollector.php +++ b/rules/nette-kdyby/src/NodeResolver/ListeningMethodsCollector.php @@ -76,7 +76,7 @@ public function collectFromClassAndGetSubscribedEventClassMethod( (array) $getSubscribedEventsClassMethod->stmts, function (Node $node) use ($classLike, $type) { $classMethod = $this->matchClassMethodByArrayItem($node, $classLike); - if ($classMethod === null) { + if (! $classMethod instanceof ClassMethod) { return null; } @@ -106,7 +106,7 @@ function (Node $node) use ($classLike, $type) { $eventClass ); - if ($eventClassAndClassMethod === null) { + if (! $eventClassAndClassMethod instanceof EventClassAndClassMethod) { return null; } @@ -186,7 +186,7 @@ private function resolveCustomClassMethodAndEventClass( ); } - if ($classMethod === null) { + if (! $classMethod instanceof ClassMethod) { return null; } diff --git a/rules/nette-kdyby/src/Rector/ClassMethod/AbstractKdybyEventSubscriberRector.php b/rules/nette-kdyby/src/Rector/ClassMethod/AbstractKdybyEventSubscriberRector.php index 616ff1822b5a..127976dacfcd 100644 --- a/rules/nette-kdyby/src/Rector/ClassMethod/AbstractKdybyEventSubscriberRector.php +++ b/rules/nette-kdyby/src/Rector/ClassMethod/AbstractKdybyEventSubscriberRector.php @@ -4,6 +4,7 @@ namespace Rector\NetteKdyby\Rector\ClassMethod; +use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\ClassMethod; use Rector\Core\Rector\AbstractRector; use Rector\NodeTypeResolver\Node\AttributeKey; @@ -13,7 +14,7 @@ abstract class AbstractKdybyEventSubscriberRector extends AbstractRector protected function shouldSkipClassMethod(ClassMethod $classMethod): bool { $classLike = $classMethod->getAttribute(AttributeKey::CLASS_NODE); - if ($classLike === null) { + if (! $classLike instanceof ClassLike) { return true; } diff --git a/rules/nette-kdyby/src/Rector/ClassMethod/ReplaceMagicPropertyWithEventClassRector.php b/rules/nette-kdyby/src/Rector/ClassMethod/ReplaceMagicPropertyWithEventClassRector.php index 74b07b21d1b5..51d7437db03e 100644 --- a/rules/nette-kdyby/src/Rector/ClassMethod/ReplaceMagicPropertyWithEventClassRector.php +++ b/rules/nette-kdyby/src/Rector/ClassMethod/ReplaceMagicPropertyWithEventClassRector.php @@ -6,6 +6,7 @@ use Nette\Utils\Strings; use PhpParser\Node; +use PhpParser\Node\Expr; use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Stmt\ClassMethod; use Rector\NetteKdyby\DataProvider\EventAndListenerTreeProvider; @@ -138,7 +139,7 @@ private function replaceEventPropertyReferenceWithEventClassReference(ClassMetho } $arrayKey = $node->key; - if ($arrayKey === null) { + if (! $arrayKey instanceof Expr) { return null; } diff --git a/rules/nette-kdyby/src/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector.php b/rules/nette-kdyby/src/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector.php index fe264f9338db..5010dc1d954f 100644 --- a/rules/nette-kdyby/src/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector.php +++ b/rules/nette-kdyby/src/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector.php @@ -14,6 +14,7 @@ use Rector\CodingStyle\Naming\ClassNaming; use Rector\Core\Rector\AbstractRector; use Rector\NetteKdyby\DataProvider\EventAndListenerTreeProvider; +use Rector\NetteKdyby\ValueObject\EventAndListenerTree; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; @@ -100,7 +101,7 @@ public function refactor(Node $node): ?Node { // 1. is onProperty? call $eventAndListenerTree = $this->eventAndListenerTreeProvider->matchMethodCall($node); - if ($eventAndListenerTree === null) { + if (! $eventAndListenerTree instanceof EventAndListenerTree) { return null; } diff --git a/rules/nette-tester-to-phpunit/src/Rector/Class_/NetteTesterClassToPHPUnitClassRector.php b/rules/nette-tester-to-phpunit/src/Rector/Class_/NetteTesterClassToPHPUnitClassRector.php index 78d0aeced187..221869412e94 100644 --- a/rules/nette-tester-to-phpunit/src/Rector/Class_/NetteTesterClassToPHPUnitClassRector.php +++ b/rules/nette-tester-to-phpunit/src/Rector/Class_/NetteTesterClassToPHPUnitClassRector.php @@ -9,6 +9,7 @@ use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Stmt\ClassLike; use Rector\Core\Rector\AbstractRector; use Rector\Core\ValueObject\MethodName; use Rector\NodeTypeResolver\Node\AttributeKey; @@ -101,7 +102,7 @@ public function refactor(Node $node): ?Node private function processAboveTestInclude(Include_ $include): void { $classLike = $include->getAttribute(AttributeKey::CLASS_NODE); - if ($classLike === null) { + if (! $classLike instanceof ClassLike) { $this->removeNode($include); } } diff --git a/rules/nette-to-symfony/src/Collector/OnFormVariableMethodCallsCollector.php b/rules/nette-to-symfony/src/Collector/OnFormVariableMethodCallsCollector.php index e8711881c7eb..e0b9b60969e9 100644 --- a/rules/nette-to-symfony/src/Collector/OnFormVariableMethodCallsCollector.php +++ b/rules/nette-to-symfony/src/Collector/OnFormVariableMethodCallsCollector.php @@ -47,7 +47,7 @@ public function __construct( public function collectFromClassMethod(ClassMethod $classMethod): array { $newFormVariable = $this->resolveNewFormVariable($classMethod); - if ($newFormVariable === null) { + if (! $newFormVariable instanceof Expr) { return []; } diff --git a/rules/nette-to-symfony/src/Rector/ClassMethod/RenameEventNamesInEventSubscriberRector.php b/rules/nette-to-symfony/src/Rector/ClassMethod/RenameEventNamesInEventSubscriberRector.php index 402a630a3164..9325f99dd035 100644 --- a/rules/nette-to-symfony/src/Rector/ClassMethod/RenameEventNamesInEventSubscriberRector.php +++ b/rules/nette-to-symfony/src/Rector/ClassMethod/RenameEventNamesInEventSubscriberRector.php @@ -6,11 +6,13 @@ use Composer\Script\Event; use PhpParser\Node; +use PhpParser\Node\Expr; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Scalar\String_; +use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Return_; use Rector\Core\Rector\AbstractRector; @@ -87,7 +89,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { $classLike = $node->getAttribute(AttributeKey::CLASS_NODE); - if ($classLike === null) { + if (! $classLike instanceof ClassLike) { return null; } @@ -125,11 +127,11 @@ private function renameArrayKeys(Return_ $return): void } $eventInfo = $this->matchStringKeys($arrayItem); - if ($eventInfo === null) { + if (! $eventInfo instanceof EventInfo) { $eventInfo = $this->matchClassConstKeys($arrayItem); } - if ($eventInfo === null) { + if (! $eventInfo instanceof EventInfo) { continue; } @@ -180,7 +182,7 @@ private function matchClassConstKeys(ArrayItem $arrayItem): ?EventInfo private function processMethodArgument(string $class, string $method, EventInfo $eventInfo): void { $classMethodNode = $this->nodeRepository->findClassMethod($class, $method); - if ($classMethodNode === null) { + if (! $classMethodNode instanceof \PhpParser\Node\Stmt\ClassMethod) { return; } @@ -195,7 +197,7 @@ private function resolveClassConstAliasMatch(ArrayItem $arrayItem, EventInfo $ev { foreach ($eventInfo->getOldClassConstAliases() as $netteClassConst) { $classConstFetchNode = $arrayItem->key; - if ($classConstFetchNode === null) { + if (! $classConstFetchNode instanceof Expr) { continue; } diff --git a/rules/nette-to-symfony/src/Rector/ClassMethod/RouterListToControllerAnnotationsRector.php b/rules/nette-to-symfony/src/Rector/ClassMethod/RouterListToControllerAnnotationsRector.php index 547aa4d15151..49ea323968b8 100644 --- a/rules/nette-to-symfony/src/Rector/ClassMethod/RouterListToControllerAnnotationsRector.php +++ b/rules/nette-to-symfony/src/Rector/ClassMethod/RouterListToControllerAnnotationsRector.php @@ -163,7 +163,7 @@ public function refactor(Node $node): ?Node /** @var RouteInfo $routeInfo */ foreach ($routeInfos as $routeInfo) { $classMethod = $this->resolveControllerClassMethod($routeInfo); - if ($classMethod === null) { + if (! $classMethod instanceof \PhpParser\Node\Stmt\ClassMethod) { continue; } @@ -225,7 +225,7 @@ private function createRouteInfosFromAssignNodes(array $assignNodes): array // collect annotations and target controllers foreach ($assignNodes as $assignNode) { $routeNameToControllerMethod = $this->routeInfoFactory->createFromNode($assignNode->expr); - if ($routeNameToControllerMethod === null) { + if (! $routeNameToControllerMethod instanceof \Rector\NetteToSymfony\ValueObject\RouteInfo) { continue; } @@ -238,7 +238,7 @@ private function createRouteInfosFromAssignNodes(array $assignNodes): array private function resolveControllerClassMethod(RouteInfo $routeInfo): ?ClassMethod { $classNode = $this->nodeRepository->findClass($routeInfo->getClass()); - if ($classNode === null) { + if (! $classNode instanceof Class_) { return null; } diff --git a/rules/nette-to-symfony/src/Rector/Class_/FormControlToControllerAndFormTypeRector.php b/rules/nette-to-symfony/src/Rector/Class_/FormControlToControllerAndFormTypeRector.php index 4421bb5a5dcd..4977aac6597f 100644 --- a/rules/nette-to-symfony/src/Rector/Class_/FormControlToControllerAndFormTypeRector.php +++ b/rules/nette-to-symfony/src/Rector/Class_/FormControlToControllerAndFormTypeRector.php @@ -10,6 +10,7 @@ use PhpParser\Node\Param; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; +use PhpParser\Node\Stmt\Namespace_; use Rector\Core\Rector\AbstractRector; use Rector\NetteToSymfony\Collector\OnFormVariableMethodCallsCollector; use Rector\NetteToSymfony\NodeFactory\BuildFormClassMethodFactory; @@ -146,12 +147,12 @@ public function refactor(Node $node): ?Node } $formTypeClass = $this->collectFormMethodCallsAndCreateFormTypeClass($classMethod); - if ($formTypeClass === null) { + if (! $formTypeClass instanceof \PhpParser\Node\Stmt\Class_) { continue; } $symfonyControllerNamespace = $this->symfonyControllerFactory->createNamespace($node, $formTypeClass); - if ($symfonyControllerNamespace === null) { + if (! $symfonyControllerNamespace instanceof Namespace_) { continue; } diff --git a/rules/nette-to-symfony/src/Rector/MethodCall/NetteFormToSymfonyFormRector.php b/rules/nette-to-symfony/src/Rector/MethodCall/NetteFormToSymfonyFormRector.php index 7832e2ee74fa..8b6e8f591410 100644 --- a/rules/nette-to-symfony/src/Rector/MethodCall/NetteFormToSymfonyFormRector.php +++ b/rules/nette-to-symfony/src/Rector/MethodCall/NetteFormToSymfonyFormRector.php @@ -12,6 +12,7 @@ use PhpParser\Node\Expr\New_; use PhpParser\Node\Identifier; use PhpParser\Node\Scalar\String_; +use PhpParser\Node\Stmt\ClassLike; use Rector\Core\Rector\AbstractRector; use Rector\NodeTypeResolver\Node\AttributeKey; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -113,7 +114,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { $classLike = $node->getAttribute(AttributeKey::CLASS_NODE); - if ($classLike === null) { + if (! $classLike instanceof ClassLike) { return null; } diff --git a/rules/nette-to-symfony/src/Route/RouteInfoFactory.php b/rules/nette-to-symfony/src/Route/RouteInfoFactory.php index 7dc7b29b15a0..248efc4f8898 100644 --- a/rules/nette-to-symfony/src/Route/RouteInfoFactory.php +++ b/rules/nette-to-symfony/src/Route/RouteInfoFactory.php @@ -10,6 +10,7 @@ use PhpParser\Node\Expr\New_; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Scalar\String_; +use PhpParser\Node\Stmt\Class_; use Rector\Core\PhpParser\Node\Value\ValueResolver; use Rector\NetteToSymfony\ValueObject\RouteInfo; use Rector\NodeCollector\NodeCollector\ParsedNodeCollector; @@ -163,12 +164,12 @@ private function createForString(String_ $string, string $routePath): ?RouteInfo // foreach all instance and try to match a name $controller . 'Presenter/Controller' $classNode = $this->parsedNodeCollector->findByShortName($controller . 'Presenter'); - if ($classNode === null) { + if (! $classNode instanceof Class_) { $classNode = $this->parsedNodeCollector->findByShortName($controller . 'Controller'); } // unable to find here - if ($classNode === null) { + if (! $classNode instanceof Class_) { return null; } diff --git a/rules/nette/src/Rector/Class_/MoveFinalGetUserToCheckRequirementsClassMethodRector.php b/rules/nette/src/Rector/Class_/MoveFinalGetUserToCheckRequirementsClassMethodRector.php index a126ccda64ff..8aad29c73a04 100644 --- a/rules/nette/src/Rector/Class_/MoveFinalGetUserToCheckRequirementsClassMethodRector.php +++ b/rules/nette/src/Rector/Class_/MoveFinalGetUserToCheckRequirementsClassMethodRector.php @@ -6,6 +6,7 @@ use PhpParser\Node; use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Stmt\ClassMethod; use Rector\Core\Exception\NotImplementedYetException; use Rector\Core\PhpParser\Node\Manipulator\ClassInsertManipulator; use Rector\Core\Rector\AbstractRector; @@ -95,7 +96,7 @@ public function refactor(Node $node): ?Node } $getUserClassMethod = $node->getMethod('getUser'); - if ($getUserClassMethod === null) { + if (! $getUserClassMethod instanceof ClassMethod) { return null; } diff --git a/rules/nette/src/Rector/Identical/AbstractWithFunctionToNetteUtilsStringsRector.php b/rules/nette/src/Rector/Identical/AbstractWithFunctionToNetteUtilsStringsRector.php index d16b200afbc2..b49bae1dea46 100644 --- a/rules/nette/src/Rector/Identical/AbstractWithFunctionToNetteUtilsStringsRector.php +++ b/rules/nette/src/Rector/Identical/AbstractWithFunctionToNetteUtilsStringsRector.php @@ -29,7 +29,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { $contentExprAndNeedleExpr = $this->resolveContentExprAndNeedleExpr($node); - if ($contentExprAndNeedleExpr === null) { + if (! $contentExprAndNeedleExpr instanceof ContentExprAndNeedleExpr) { return null; } diff --git a/rules/nette/src/Rector/MethodCall/AddNextrasDatePickerToDateControlRector.php b/rules/nette/src/Rector/MethodCall/AddNextrasDatePickerToDateControlRector.php index d0e882ba7cc5..154173581115 100644 --- a/rules/nette/src/Rector/MethodCall/AddNextrasDatePickerToDateControlRector.php +++ b/rules/nette/src/Rector/MethodCall/AddNextrasDatePickerToDateControlRector.php @@ -81,7 +81,7 @@ public function refactor(Node $node): ?Node } $assign = $this->createAssign($node->var); - if ($assign === null) { + if (! $assign instanceof Node) { return null; } diff --git a/rules/nette/src/Rector/NotIdentical/StrposToStringsContainsRector.php b/rules/nette/src/Rector/NotIdentical/StrposToStringsContainsRector.php index 5b2ab6dc4f65..dc4fc0aa68a7 100644 --- a/rules/nette/src/Rector/NotIdentical/StrposToStringsContainsRector.php +++ b/rules/nette/src/Rector/NotIdentical/StrposToStringsContainsRector.php @@ -68,7 +68,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { $funcCall = $this->matchStrposInComparisonToFalse($node); - if ($funcCall === null) { + if (! $funcCall instanceof FuncCall) { return null; } diff --git a/rules/order/src/Rector/Class_/OrderPrivateMethodsByUseRector.php b/rules/order/src/Rector/Class_/OrderPrivateMethodsByUseRector.php index eaa270a3b162..77dfd4632b13 100644 --- a/rules/order/src/Rector/Class_/OrderPrivateMethodsByUseRector.php +++ b/rules/order/src/Rector/Class_/OrderPrivateMethodsByUseRector.php @@ -157,7 +157,7 @@ private function getLocalPrivateMethodCallOrder(ClassLike $classLike): array } $classMethod = $classLike->getMethod($methodName); - if ($classMethod === null) { + if (! $classMethod instanceof ClassMethod) { return null; } diff --git a/rules/php-office/src/Rector/MethodCall/IncreaseColumnIndexRector.php b/rules/php-office/src/Rector/MethodCall/IncreaseColumnIndexRector.php index 2bf278010b94..adb9ef97da96 100644 --- a/rules/php-office/src/Rector/MethodCall/IncreaseColumnIndexRector.php +++ b/rules/php-office/src/Rector/MethodCall/IncreaseColumnIndexRector.php @@ -89,7 +89,7 @@ public function refactor(Node $node): ?Node if ($firstArgumentValue instanceof Variable) { // check if for() value, rather update that $lNumber = $this->findPreviousForWithVariable($firstArgumentValue); - if ($lNumber === null) { + if (! $lNumber instanceof LNumber) { $node->args[0]->value = new Plus($firstArgumentValue, new LNumber(1)); return null; } diff --git a/rules/php-spec-to-phpunit/src/MatchersManipulator.php b/rules/php-spec-to-phpunit/src/MatchersManipulator.php index 15f8f0401994..8c38fa6feafc 100644 --- a/rules/php-spec-to-phpunit/src/MatchersManipulator.php +++ b/rules/php-spec-to-phpunit/src/MatchersManipulator.php @@ -7,6 +7,7 @@ use PhpParser\Node\Expr\Array_; use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Return_; final class MatchersManipulator @@ -17,7 +18,7 @@ final class MatchersManipulator public function resolveMatcherNamesFromClass(Class_ $class): array { $classMethod = $class->getMethod('getMatchers'); - if ($classMethod === null) { + if (! $classMethod instanceof ClassMethod) { return []; } diff --git a/rules/php-spec-to-phpunit/src/Rector/AbstractPhpSpecToPHPUnitRector.php b/rules/php-spec-to-phpunit/src/Rector/AbstractPhpSpecToPHPUnitRector.php index ad329f58ab72..6fd8b9c4caac 100644 --- a/rules/php-spec-to-phpunit/src/Rector/AbstractPhpSpecToPHPUnitRector.php +++ b/rules/php-spec-to-phpunit/src/Rector/AbstractPhpSpecToPHPUnitRector.php @@ -5,6 +5,7 @@ namespace Rector\PhpSpecToPHPUnit\Rector; use PhpParser\Node; +use PhpParser\Node\Stmt\ClassLike; use Rector\Core\Rector\AbstractRector; use Rector\NodeTypeResolver\Node\AttributeKey; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -63,7 +64,7 @@ protected function setUp() public function isInPhpSpecBehavior(Node $node): bool { $classLike = $node->getAttribute(AttributeKey::CLASS_NODE); - if ($classLike === null) { + if (! $classLike instanceof ClassLike) { return false; } diff --git a/rules/php-spec-to-phpunit/src/Rector/Class_/PhpSpecClassToPHPUnitClassRector.php b/rules/php-spec-to-phpunit/src/Rector/Class_/PhpSpecClassToPHPUnitClassRector.php index 52a490d4fac2..e608ff81764c 100644 --- a/rules/php-spec-to-phpunit/src/Rector/Class_/PhpSpecClassToPHPUnitClassRector.php +++ b/rules/php-spec-to-phpunit/src/Rector/Class_/PhpSpecClassToPHPUnitClassRector.php @@ -97,7 +97,7 @@ public function refactor(Node $node): ?Node $classMethod = $node->getMethod('let'); // add let if missing - if ($classMethod === null) { + if (! $classMethod instanceof ClassMethod) { if (! $this->letManipulator->isLetNeededInClass($node)) { return null; } diff --git a/rules/php55/src/Rector/FuncCall/PregReplaceEModifierRector.php b/rules/php55/src/Rector/FuncCall/PregReplaceEModifierRector.php index 65fff535f005..57cbd8bd501a 100644 --- a/rules/php55/src/Rector/FuncCall/PregReplaceEModifierRector.php +++ b/rules/php55/src/Rector/FuncCall/PregReplaceEModifierRector.php @@ -5,6 +5,8 @@ namespace Rector\Php55\Rector\FuncCall; use PhpParser\Node; +use PhpParser\Node\Expr; +use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Name; use Rector\Core\Rector\AbstractRector; @@ -88,7 +90,7 @@ public function refactor(Node $node): ?Node $firstArgumentValue = $node->args[0]->value; $patternWithoutE = $this->regexMatcher->resolvePatternExpressionWithoutEIfFound($firstArgumentValue); - if ($patternWithoutE === null) { + if (! $patternWithoutE instanceof Expr) { return null; } @@ -96,7 +98,7 @@ public function refactor(Node $node): ?Node $anonymousFunction = $this->anonymousFunctionNodeFactory->createAnonymousFunctionFromString( $secondArgumentValue ); - if ($anonymousFunction === null) { + if (! $anonymousFunction instanceof Closure) { return null; } diff --git a/rules/php56/src/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector.php b/rules/php56/src/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector.php index 6c78ca2a2ee0..83d5ee3c5492 100644 --- a/rules/php56/src/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector.php +++ b/rules/php56/src/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector.php @@ -178,7 +178,7 @@ private function collectDefinedVariablesFromForeach(Foreach_ $foreach): void private function shouldSkipVariable(Variable $variable): bool { $parentNode = $variable->getAttribute(AttributeKey::PARENT_NODE); - if ($parentNode === null) { + if (! $parentNode instanceof Node) { return true; } diff --git a/rules/php70/src/Rector/ClassMethod/Php4ConstructorRector.php b/rules/php70/src/Rector/ClassMethod/Php4ConstructorRector.php index e5ec48febe87..29c7d279c01f 100644 --- a/rules/php70/src/Rector/ClassMethod/Php4ConstructorRector.php +++ b/rules/php70/src/Rector/ClassMethod/Php4ConstructorRector.php @@ -83,7 +83,7 @@ public function refactor(Node $node): ?Node $classMethod = $classLike->getMethod(MethodName::CONSTRUCT); // does it already have a __construct method? - if ($classMethod === null) { + if (! $classMethod instanceof \PhpParser\Node\Stmt\ClassMethod) { $node->name = new Identifier(MethodName::CONSTRUCT); } diff --git a/rules/php70/src/Rector/FuncCall/NonVariableToVariableOnFunctionCallRector.php b/rules/php70/src/Rector/FuncCall/NonVariableToVariableOnFunctionCallRector.php index 4102e30f83bd..4ce68372f4db 100644 --- a/rules/php70/src/Rector/FuncCall/NonVariableToVariableOnFunctionCallRector.php +++ b/rules/php70/src/Rector/FuncCall/NonVariableToVariableOnFunctionCallRector.php @@ -20,6 +20,7 @@ use PHPStan\Analyser\MutatingScope; use PHPStan\Analyser\Scope; use PHPStan\Reflection\ParameterReflection; +use PHPStan\Reflection\ParametersAcceptor; use PHPStan\Type\MixedType; use Rector\Core\PHPStan\Reflection\CallReflectionResolver; use Rector\Core\Rector\AbstractRector; @@ -137,7 +138,7 @@ private function getNonVariableArguments(Node $node): array $node ); - if ($parametersAcceptor === null) { + if (! $parametersAcceptor instanceof ParametersAcceptor) { return []; } diff --git a/rules/php70/src/Rector/StaticCall/StaticCallOnNonStaticToInstanceCallRector.php b/rules/php70/src/Rector/StaticCall/StaticCallOnNonStaticToInstanceCallRector.php index 470eb9b32401..09b1c21047e4 100644 --- a/rules/php70/src/Rector/StaticCall/StaticCallOnNonStaticToInstanceCallRector.php +++ b/rules/php70/src/Rector/StaticCall/StaticCallOnNonStaticToInstanceCallRector.php @@ -10,12 +10,14 @@ use PhpParser\Node\Expr\New_; use PhpParser\Node\Expr\PropertyFetch; use PhpParser\Node\Expr\StaticCall; +use PhpParser\Node\Stmt\ClassMethod; use PHPStan\Type\ObjectType; use Rector\Core\PhpParser\Node\Manipulator\ClassMethodManipulator; use Rector\Core\Rector\AbstractRector; use Rector\NodeCollector\StaticAnalyzer; use Rector\NodeTypeResolver\Node\AttributeKey; use ReflectionClass; +use ReflectionMethod; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -128,7 +130,7 @@ public function refactor(Node $node): ?Node // can we add static to method? $classMethodNode = $this->nodeRepository->findClassMethod($className, $methodName); - if ($classMethodNode === null) { + if (! $classMethodNode instanceof ClassMethod) { return null; } @@ -177,7 +179,7 @@ private function isInstantiable(string $className): bool $reflectionClass = new ReflectionClass($className); $classConstructorReflection = $reflectionClass->getConstructor(); - if ($classConstructorReflection === null) { + if (! $classConstructorReflection instanceof ReflectionMethod) { return true; } diff --git a/rules/php70/src/Rector/Ternary/TernaryToNullCoalescingRector.php b/rules/php70/src/Rector/Ternary/TernaryToNullCoalescingRector.php index eab62352a343..863e971732cc 100644 --- a/rules/php70/src/Rector/Ternary/TernaryToNullCoalescingRector.php +++ b/rules/php70/src/Rector/Ternary/TernaryToNullCoalescingRector.php @@ -5,6 +5,7 @@ namespace Rector\Php70\Rector\Ternary; use PhpParser\Node; +use PhpParser\Node\Expr; use PhpParser\Node\Expr\BinaryOp\Coalesce; use PhpParser\Node\Expr\BinaryOp\Identical; use PhpParser\Node\Expr\BinaryOp\NotIdentical; @@ -65,7 +66,7 @@ public function refactor(Node $node): ?Node if ($checkedNode === null) { return null; } - if ($fallbackNode === null) { + if (! $fallbackNode instanceof Expr) { return null; } diff --git a/rules/php71/src/IsArrayAndDualCheckToAble.php b/rules/php71/src/IsArrayAndDualCheckToAble.php index 3d12a857e924..0aa0b244fb97 100644 --- a/rules/php71/src/IsArrayAndDualCheckToAble.php +++ b/rules/php71/src/IsArrayAndDualCheckToAble.php @@ -13,6 +13,7 @@ use PhpParser\Node\Name; use Rector\Core\PhpParser\Node\Manipulator\BinaryOpManipulator; use Rector\NodeNameResolver\NodeNameResolver; +use Rector\Php71\ValueObject\TwoNodeMatch; final class IsArrayAndDualCheckToAble { @@ -40,7 +41,7 @@ public function processBooleanOr(BooleanOr $booleanOr, string $type, string $new FuncCall::class ); - if ($twoNodeMatch === null) { + if (! $twoNodeMatch instanceof TwoNodeMatch) { return null; } diff --git a/rules/php71/src/Rector/FuncCall/RemoveExtraParametersRector.php b/rules/php71/src/Rector/FuncCall/RemoveExtraParametersRector.php index f783a7f28c8d..0daa2641e668 100644 --- a/rules/php71/src/Rector/FuncCall/RemoveExtraParametersRector.php +++ b/rules/php71/src/Rector/FuncCall/RemoveExtraParametersRector.php @@ -104,7 +104,7 @@ private function shouldSkip(Node $node): bool $this->callReflectionResolver->resolveCall($node), $node ); - if ($parametersAcceptor === null) { + if (! $parametersAcceptor instanceof \PHPStan\Reflection\ParametersAcceptor) { return true; } diff --git a/rules/php73/src/Rector/FuncCall/ArrayKeyFirstLastRector.php b/rules/php73/src/Rector/FuncCall/ArrayKeyFirstLastRector.php index a86ddd451898..8d39087b3523 100644 --- a/rules/php73/src/Rector/FuncCall/ArrayKeyFirstLastRector.php +++ b/rules/php73/src/Rector/FuncCall/ArrayKeyFirstLastRector.php @@ -87,7 +87,7 @@ public function refactor(Node $node): ?Node } $nextExpression = $this->getNextExpression($node); - if ($nextExpression === null) { + if (! $nextExpression instanceof Node) { return null; } diff --git a/rules/php74/src/Rector/MethodCall/ChangeReflectionTypeToStringToGetNameRector.php b/rules/php74/src/Rector/MethodCall/ChangeReflectionTypeToStringToGetNameRector.php index b66111fe2102..6837b7189645 100644 --- a/rules/php74/src/Rector/MethodCall/ChangeReflectionTypeToStringToGetNameRector.php +++ b/rules/php74/src/Rector/MethodCall/ChangeReflectionTypeToStringToGetNameRector.php @@ -10,6 +10,7 @@ use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\Ternary; use PhpParser\Node\Expr\Variable; +use PHPStan\Analyser\Scope; use Rector\Core\Rector\AbstractRector; use Rector\NodeTypeResolver\Node\AttributeKey; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -164,7 +165,7 @@ private function shouldSkipMethodCall(MethodCall $methodCall): bool { $scope = $methodCall->getAttribute(AttributeKey::SCOPE); // just added node → skip it - if ($scope === null) { + if (! $scope instanceof Scope) { return true; } diff --git a/rules/php80/src/NodeManipulator/TokenManipulator.php b/rules/php80/src/NodeManipulator/TokenManipulator.php index f8f14126a940..feaec58a03d1 100644 --- a/rules/php80/src/NodeManipulator/TokenManipulator.php +++ b/rules/php80/src/NodeManipulator/TokenManipulator.php @@ -176,7 +176,7 @@ public function refactorTokenIsKind(array $nodes, Expr $singleTokenExpr): void } $arrayDimFetchAndConstFetch = $this->matchArrayDimFetchAndConstFetch($node); - if ($arrayDimFetchAndConstFetch === null) { + if (! $arrayDimFetchAndConstFetch instanceof ArrayDimFetchAndConstFetch) { return null; } diff --git a/rules/php80/src/NodeResolver/PromotedPropertyResolver.php b/rules/php80/src/NodeResolver/PromotedPropertyResolver.php index 23d5189dc07b..306f5f767fb5 100644 --- a/rules/php80/src/NodeResolver/PromotedPropertyResolver.php +++ b/rules/php80/src/NodeResolver/PromotedPropertyResolver.php @@ -51,7 +51,7 @@ public function __construct( public function resolveFromClass(Class_ $class): array { $constructClassMethod = $class->getMethod(MethodName::CONSTRUCT); - if ($constructClassMethod === null) { + if (! $constructClassMethod instanceof ClassMethod) { return []; } @@ -62,7 +62,7 @@ public function resolveFromClass(Class_ $class): array } $propertyPromotionCandidate = $this->matchPropertyPromotionCandidate($property, $constructClassMethod); - if ($propertyPromotionCandidate === null) { + if (! $propertyPromotionCandidate instanceof PropertyPromotionCandidate) { continue; } @@ -106,7 +106,7 @@ private function matchPropertyPromotionCandidate( } $matchedParam = $this->matchClassMethodParamByAssignedVariable($constructClassMethod, $assignedExpr); - if ($matchedParam === null) { + if (! $matchedParam instanceof Param) { continue; } @@ -155,7 +155,7 @@ private function resolveFirstParamUses(ClassMethod $classMethod): array return $this->nodeNameResolver->isName($node, $paramName); }); - if ($firstParamVariable === null) { + if (! $firstParamVariable instanceof Node) { continue; } diff --git a/rules/php80/src/NodeResolver/SwitchExprsResolver.php b/rules/php80/src/NodeResolver/SwitchExprsResolver.php index 8c089a843bb7..9baf9cb4a9f4 100644 --- a/rules/php80/src/NodeResolver/SwitchExprsResolver.php +++ b/rules/php80/src/NodeResolver/SwitchExprsResolver.php @@ -32,7 +32,7 @@ public function resolve(Switch_ $switch): array if ($expr instanceof Return_) { $returnedExpr = $expr->expr; - if ($returnedExpr === null) { + if (! $returnedExpr instanceof Expr) { return []; } $condAndExpr[] = new CondAndExpr($case->cond, $returnedExpr, CondAndExpr::TYPE_RETURN); diff --git a/rules/php80/src/Rector/Catch_/RemoveUnusedVariableInCatchRector.php b/rules/php80/src/Rector/Catch_/RemoveUnusedVariableInCatchRector.php index 2b4ddafb1ce5..b1dc99a7604a 100644 --- a/rules/php80/src/Rector/Catch_/RemoveUnusedVariableInCatchRector.php +++ b/rules/php80/src/Rector/Catch_/RemoveUnusedVariableInCatchRector.php @@ -63,7 +63,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { $caughtVar = $node->var; - if ($caughtVar === null) { + if (! $caughtVar instanceof Variable) { return null; } diff --git a/rules/php80/src/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php b/rules/php80/src/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php index 7cdcb2d3ca2a..0d043c0db1d7 100644 --- a/rules/php80/src/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php +++ b/rules/php80/src/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php @@ -9,6 +9,7 @@ use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Property; +use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode; use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover; use Rector\Core\Rector\AbstractRector; use Rector\Core\ValueObject\MethodName; @@ -162,7 +163,7 @@ private function removeClassMethodParam(ClassMethod $classMethod, string $paramN $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod); $attributeAwareParamTagValueNode = $phpDocInfo->getParamTagValueByName($paramName); - if ($attributeAwareParamTagValueNode === null) { + if (! $attributeAwareParamTagValueNode instanceof ParamTagValueNode) { return; } diff --git a/rules/php80/src/Rector/Class_/StringableForToStringRector.php b/rules/php80/src/Rector/Class_/StringableForToStringRector.php index dead5c3397c4..1e6750b64ef4 100644 --- a/rules/php80/src/Rector/Class_/StringableForToStringRector.php +++ b/rules/php80/src/Rector/Class_/StringableForToStringRector.php @@ -8,6 +8,7 @@ use PhpParser\Node\Name; use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Stmt\ClassMethod; use Rector\Core\PhpParser\Node\Manipulator\ClassManipulator; use Rector\Core\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -79,7 +80,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { $toStringClassMethod = $node->getMethod('__toString'); - if ($toStringClassMethod === null) { + if (! $toStringClassMethod instanceof ClassMethod) { return null; } diff --git a/rules/php80/src/Rector/Identical/StrStartsWithRector.php b/rules/php80/src/Rector/Identical/StrStartsWithRector.php index 9d85befbb0ad..0f90d5a18f97 100644 --- a/rules/php80/src/Rector/Identical/StrStartsWithRector.php +++ b/rules/php80/src/Rector/Identical/StrStartsWithRector.php @@ -9,6 +9,7 @@ use PhpParser\Node\Expr\BinaryOp\NotIdentical; use Rector\Core\Rector\AbstractRector; use Rector\Php80\Contract\StrStartWithMatchAndRefactorInterface; +use Rector\Php80\ValueObject\StrStartsWith; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -84,7 +85,7 @@ public function refactor(Node $node): ?Node { foreach ($this->strStartWithMatchAndRefactors as $strStartWithMatchAndRefactor) { $strStartsWithValueObject = $strStartWithMatchAndRefactor->match($node); - if ($strStartsWithValueObject === null) { + if (! $strStartsWithValueObject instanceof StrStartsWith) { continue; } diff --git a/rules/php80/src/Rector/If_/NullsafeOperatorRector.php b/rules/php80/src/Rector/If_/NullsafeOperatorRector.php index 6f97b96a9dd7..7726d233f372 100644 --- a/rules/php80/src/Rector/If_/NullsafeOperatorRector.php +++ b/rules/php80/src/Rector/If_/NullsafeOperatorRector.php @@ -111,18 +111,18 @@ public function refactor(Node $node): ?Node private function processNullSafeOperatorIdentical(If_ $if, bool $isStartIf = true): ?Node { $comparedNode = $this->ifManipulator->matchIfValueReturnValue($if); - if ($comparedNode === null) { + if (! $comparedNode instanceof \PhpParser\Node\Expr) { return null; } $prevNode = $if->getAttribute(AttributeKey::PREVIOUS_NODE); $nextNode = $if->getAttribute(AttributeKey::NEXT_NODE); - if ($prevNode === null) { + if (! $prevNode instanceof \PhpParser\Node) { return null; } - if ($nextNode === null) { + if (! $nextNode instanceof \PhpParser\Node) { return null; } @@ -145,7 +145,7 @@ private function processNullSafeOperatorIdentical(If_ $if, bool $isStartIf = tru private function processNullSafeOperatorNotIdentical(If_ $if, ?Expr $expr = null): ?Node { $assign = $this->ifManipulator->matchIfNotNullNextAssignment($if); - if ($assign === null) { + if (! $assign instanceof Assign) { return null; } diff --git a/rules/php80/src/Rector/NotIdentical/StrContainsRector.php b/rules/php80/src/Rector/NotIdentical/StrContainsRector.php index afa90a1283c6..e318a832609b 100644 --- a/rules/php80/src/Rector/NotIdentical/StrContainsRector.php +++ b/rules/php80/src/Rector/NotIdentical/StrContainsRector.php @@ -70,7 +70,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { $funcCall = $this->matchNotIdenticalToFalse($node); - if ($funcCall === null) { + if (! $funcCall instanceof FuncCall) { return null; } diff --git a/rules/php80/src/Rector/Switch_/ChangeSwitchToMatchRector.php b/rules/php80/src/Rector/Switch_/ChangeSwitchToMatchRector.php index 1502a6ca3417..ef0aca73c529 100644 --- a/rules/php80/src/Rector/Switch_/ChangeSwitchToMatchRector.php +++ b/rules/php80/src/Rector/Switch_/ChangeSwitchToMatchRector.php @@ -191,7 +191,7 @@ private function createMatchArmsFromCases(array $condAndExprs): array $condExpr = $condAndExpr->getCondExpr(); - $condList = $condExpr === null ? null : [$condExpr]; + $condList = $condExpr instanceof Expr ? [$condExpr] : null; $matchArms[] = new MatchArm($condList, $expr); } diff --git a/rules/phpunit-symfony/src/Rector/StaticCall/AddMessageToEqualsResponseCodeRector.php b/rules/phpunit-symfony/src/Rector/StaticCall/AddMessageToEqualsResponseCodeRector.php index 14cc38391cec..78738ccb1968 100644 --- a/rules/phpunit-symfony/src/Rector/StaticCall/AddMessageToEqualsResponseCodeRector.php +++ b/rules/phpunit-symfony/src/Rector/StaticCall/AddMessageToEqualsResponseCodeRector.php @@ -90,7 +90,7 @@ public function refactor(Node $node): ?Node } $parentVariable = $this->getParentOfGetStatusCode($node->args[1]->value); - if ($parentVariable === null) { + if (! $parentVariable instanceof Expr) { return null; } diff --git a/rules/phpunit/src/NodeAnalyzer/TestsNodeAnalyzer.php b/rules/phpunit/src/NodeAnalyzer/TestsNodeAnalyzer.php index f81418299e0b..cd1b3808de08 100644 --- a/rules/phpunit/src/NodeAnalyzer/TestsNodeAnalyzer.php +++ b/rules/phpunit/src/NodeAnalyzer/TestsNodeAnalyzer.php @@ -5,6 +5,7 @@ namespace Rector\PHPUnit\NodeAnalyzer; use PhpParser\Node; +use PhpParser\Node\Stmt\ClassLike; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\NodeTypeResolver\NodeTypeResolver; @@ -23,7 +24,7 @@ public function __construct(NodeTypeResolver $nodeTypeResolver) public function isInTestClass(Node $node): bool { $classLike = $node->getAttribute(AttributeKey::CLASS_NODE); - if ($classLike === null) { + if (! $classLike instanceof ClassLike) { return false; } diff --git a/rules/phpunit/src/Rector/ClassMethod/AddDoesNotPerformAssertionToNonAssertingTestRector.php b/rules/phpunit/src/Rector/ClassMethod/AddDoesNotPerformAssertionToNonAssertingTestRector.php index 245162ed3ae7..808d358efd2e 100644 --- a/rules/phpunit/src/Rector/ClassMethod/AddDoesNotPerformAssertionToNonAssertingTestRector.php +++ b/rules/phpunit/src/Rector/ClassMethod/AddDoesNotPerformAssertionToNonAssertingTestRector.php @@ -12,6 +12,7 @@ use Rector\Core\Reflection\ClassMethodReflectionFactory; use Rector\FileSystemRector\Parser\FileInfoParser; use Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\DocBlockManipulator; +use ReflectionMethod; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; use Symplify\SmartFileSystem\SmartFileInfo; @@ -279,7 +280,7 @@ private function findClassMethodByParsingReflection(Node $node): ?ClassMethod $methodName ); - if ($reflectionMethod === null) { + if (! $reflectionMethod instanceof ReflectionMethod) { return null; } diff --git a/rules/phpunit/src/Rector/ClassMethod/TryCatchToExpectExceptionRector.php b/rules/phpunit/src/Rector/ClassMethod/TryCatchToExpectExceptionRector.php index abff74dc9524..da1703aef0bf 100644 --- a/rules/phpunit/src/Rector/ClassMethod/TryCatchToExpectExceptionRector.php +++ b/rules/phpunit/src/Rector/ClassMethod/TryCatchToExpectExceptionRector.php @@ -101,7 +101,7 @@ private function processTryCatch(TryCatch $tryCatch): ?array $this->newExpressions = []; $exceptionVariable = $tryCatch->catches[0]->var; - if ($exceptionVariable === null) { + if (! $exceptionVariable instanceof Variable) { return null; } diff --git a/rules/phpunit/src/Rector/Class_/ArrayArgumentInTestToDataProviderRector.php b/rules/phpunit/src/Rector/Class_/ArrayArgumentInTestToDataProviderRector.php index 8c1bbccf222a..40a325be0add 100644 --- a/rules/phpunit/src/Rector/Class_/ArrayArgumentInTestToDataProviderRector.php +++ b/rules/phpunit/src/Rector/Class_/ArrayArgumentInTestToDataProviderRector.php @@ -15,6 +15,7 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; use PHPStan\PhpDocParser\Ast\Type\TypeNode; +use PHPStan\Type\Type; use PHPStan\Type\UnionType; use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareParamTagValueNode; use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwarePhpDocTagNode; @@ -320,7 +321,7 @@ private function createParamTagNode(string $name, TypeNode $typeNode): Attribute private function setTypeIfNotNull(ParamAndArg $paramAndArg, Param $param): void { $staticType = $paramAndArg->getType(); - if ($staticType === null) { + if (! $staticType instanceof Type) { return; } diff --git a/rules/phpunit/src/Rector/Class_/ConstructClassMethodToSetUpTestCaseRector.php b/rules/phpunit/src/Rector/Class_/ConstructClassMethodToSetUpTestCaseRector.php index 120c9e83411e..56c9dd83a176 100644 --- a/rules/phpunit/src/Rector/Class_/ConstructClassMethodToSetUpTestCaseRector.php +++ b/rules/phpunit/src/Rector/Class_/ConstructClassMethodToSetUpTestCaseRector.php @@ -102,7 +102,7 @@ public function refactor(Node $node): ?Node } $constructClassMethod = $node->getMethod(MethodName::CONSTRUCT); - if ($constructClassMethod === null) { + if (! $constructClassMethod instanceof ClassMethod) { return null; } diff --git a/rules/phpunit/src/Rector/MethodCall/WithConsecutiveArgToArrayRector.php b/rules/phpunit/src/Rector/MethodCall/WithConsecutiveArgToArrayRector.php index 8bbbdbcfd4c0..ceea2f61a2bb 100644 --- a/rules/phpunit/src/Rector/MethodCall/WithConsecutiveArgToArrayRector.php +++ b/rules/phpunit/src/Rector/MethodCall/WithConsecutiveArgToArrayRector.php @@ -6,6 +6,7 @@ use PhpParser\Node; use PhpParser\Node\Arg; +use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Scalar\String_; @@ -158,13 +159,13 @@ private function areAllArgArrayTypes(MethodCall $methodCall): bool private function inferMockedClassName(MethodCall $methodCall): ?string { $variable = $this->findRootVariableOfChainCall($methodCall); - if ($variable === null) { + if (! $variable instanceof Variable) { return null; } // look for "$this->createMock(X)" $assignToVariable = $this->methodCallManipulator->findAssignToVariable($variable); - if ($assignToVariable === null) { + if (! $assignToVariable instanceof Assign) { return null; } diff --git a/rules/polyfill/src/ConditionResolver.php b/rules/polyfill/src/ConditionResolver.php index 51abb6b07f76..2ab64769de22 100644 --- a/rules/polyfill/src/ConditionResolver.php +++ b/rules/polyfill/src/ConditionResolver.php @@ -77,7 +77,7 @@ public function resolveFromExpr(Expr $expr): ?ConditionInterface $funcCall = $expr->right; $versionCompareCondition = $this->resolveVersionCompareConditionForFuncCall($funcCall); - if ($versionCompareCondition === null) { + if (! $versionCompareCondition instanceof VersionCompareCondition) { return null; } @@ -125,7 +125,7 @@ private function resolveFuncCall( string $binaryClass ): ?BinaryToVersionCompareCondition { $versionCompareCondition = $this->resolveVersionCompareConditionForFuncCall($funcCall); - if ($versionCompareCondition === null) { + if (! $versionCompareCondition instanceof VersionCompareCondition) { return null; } diff --git a/rules/polyfill/src/Rector/If_/UnwrapFutureCompatibleIfPhpVersionRector.php b/rules/polyfill/src/Rector/If_/UnwrapFutureCompatibleIfPhpVersionRector.php index 68701e674c9b..2abc1045d02b 100644 --- a/rules/polyfill/src/Rector/If_/UnwrapFutureCompatibleIfPhpVersionRector.php +++ b/rules/polyfill/src/Rector/If_/UnwrapFutureCompatibleIfPhpVersionRector.php @@ -9,6 +9,7 @@ use Rector\Core\Rector\AbstractRector; use Rector\Polyfill\ConditionEvaluator; use Rector\Polyfill\ConditionResolver; +use Rector\Polyfill\Contract\ConditionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -77,7 +78,7 @@ public function refactor(Node $node): ?Node } $condition = $this->conditionResolver->resolveFromExpr($node->cond); - if ($condition === null) { + if (! $condition instanceof ConditionInterface) { return null; } diff --git a/rules/privatization/src/NodeAnalyzer/ClassMethodExternalCallNodeAnalyzer.php b/rules/privatization/src/NodeAnalyzer/ClassMethodExternalCallNodeAnalyzer.php index 0b0d388f7ab0..75f76dc4f532 100644 --- a/rules/privatization/src/NodeAnalyzer/ClassMethodExternalCallNodeAnalyzer.php +++ b/rules/privatization/src/NodeAnalyzer/ClassMethodExternalCallNodeAnalyzer.php @@ -131,7 +131,7 @@ private function isEventSubscriberMethod(ClassMethod $classMethod, string $metho } $getSubscribedEventsClassMethod = $classLike->getMethod('getSubscribedEvents'); - if ($getSubscribedEventsClassMethod === null) { + if (! $getSubscribedEventsClassMethod instanceof ClassMethod) { return false; } diff --git a/rules/privatization/src/NodeFinder/ParentClassConstantNodeFinder.php b/rules/privatization/src/NodeFinder/ParentClassConstantNodeFinder.php index ff46497d8be3..f38b2401d38e 100644 --- a/rules/privatization/src/NodeFinder/ParentClassConstantNodeFinder.php +++ b/rules/privatization/src/NodeFinder/ParentClassConstantNodeFinder.php @@ -4,6 +4,7 @@ namespace Rector\Privatization\NodeFinder; +use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassConst; use Rector\NodeCollector\NodeCollector\ParsedNodeCollector; use Rector\NodeTypeResolver\Node\AttributeKey; @@ -23,7 +24,7 @@ public function __construct(ParsedNodeCollector $parsedNodeCollector) public function find(string $class, string $constant): ?ClassConst { $classNode = $this->parsedNodeCollector->findClass($class); - if ($classNode === null) { + if (! $classNode instanceof Class_) { return null; } diff --git a/rules/privatization/src/NodeReplacer/PropertyFetchWithVariableReplacer.php b/rules/privatization/src/NodeReplacer/PropertyFetchWithVariableReplacer.php index 94454703d47e..dd46023aab63 100644 --- a/rules/privatization/src/NodeReplacer/PropertyFetchWithVariableReplacer.php +++ b/rules/privatization/src/NodeReplacer/PropertyFetchWithVariableReplacer.php @@ -8,6 +8,7 @@ use PhpParser\Node\Expr\PropertyFetch; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Stmt\ClassMethod; use Rector\NodeNameResolver\NodeNameResolver; use Symplify\Astral\NodeTraverser\SimpleCallableNodeTraverser; @@ -39,7 +40,7 @@ public function replacePropertyFetchesByVariable(Class_ $class, array $methodsBy foreach ($methodsByPropertyName as $propertyName => $methodNames) { $methodName = $methodNames[0]; $classMethod = $class->getMethod($methodName); - if ($classMethod === null) { + if (! $classMethod instanceof ClassMethod) { continue; } diff --git a/rules/privatization/src/Rector/ClassConst/PrivatizeLocalClassConstantRector.php b/rules/privatization/src/Rector/ClassConst/PrivatizeLocalClassConstantRector.php index eb1caedeb2ee..ac6e0d1a7653 100644 --- a/rules/privatization/src/Rector/ClassConst/PrivatizeLocalClassConstantRector.php +++ b/rules/privatization/src/Rector/ClassConst/PrivatizeLocalClassConstantRector.php @@ -14,6 +14,7 @@ use Rector\Privatization\NodeFinder\ParentClassConstantNodeFinder; use Rector\Privatization\Reflection\ParentConstantReflectionResolver; use Rector\Privatization\ValueObject\ConstantVisibility; +use ReflectionClassConstant; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -176,7 +177,7 @@ private function findParentClassConstantAndRefactorIfPossible(string $class, str } $parentClassConstantReflection = $this->parentConstantReflectionResolver->resolve($class, $constant); - if ($parentClassConstantReflection === null) { + if (! $parentClassConstantReflection instanceof ReflectionClassConstant) { return null; } diff --git a/rules/privatization/src/Rector/Class_/ChangeReadOnlyVariableWithDefaultValueToConstantRector.php b/rules/privatization/src/Rector/Class_/ChangeReadOnlyVariableWithDefaultValueToConstantRector.php index 10553257b08c..8a7624974a8f 100644 --- a/rules/privatization/src/Rector/Class_/ChangeReadOnlyVariableWithDefaultValueToConstantRector.php +++ b/rules/privatization/src/Rector/Class_/ChangeReadOnlyVariableWithDefaultValueToConstantRector.php @@ -119,7 +119,7 @@ public function refactor(Node $node): ?Node } $classMethod = $node->getMethod($methodName); - if ($classMethod === null) { + if (! $classMethod instanceof ClassMethod) { throw new ShouldNotHappenException(); } diff --git a/rules/privatization/src/Rector/MethodCall/ReplaceStringWithClassConstantRector.php b/rules/privatization/src/Rector/MethodCall/ReplaceStringWithClassConstantRector.php index 04b144dcad98..58c366349f66 100644 --- a/rules/privatization/src/Rector/MethodCall/ReplaceStringWithClassConstantRector.php +++ b/rules/privatization/src/Rector/MethodCall/ReplaceStringWithClassConstantRector.php @@ -94,7 +94,7 @@ public function refactor(Node $node): ?Node foreach ($this->replaceStringWithClassConstants as $replaceStringWithClassConstant) { $desiredArg = $this->matchArg($node, $replaceStringWithClassConstant); - if ($desiredArg === null) { + if (! $desiredArg instanceof Arg) { continue; } @@ -103,7 +103,7 @@ public function refactor(Node $node): ?Node $replaceStringWithClassConstant->getClassWithConstants() ); - if ($classConstFetch === null) { + if (! $classConstFetch instanceof ClassConstFetch) { continue; } @@ -139,7 +139,7 @@ private function matchArg( } $desiredArg = $methodCall->args[$replaceStringWithClassConstant->getArgPosition()] ?? null; - if ($desiredArg === null) { + if (! $desiredArg instanceof Arg) { return null; } diff --git a/rules/privatization/src/Rector/Property/PrivatizeLocalPropertyToPrivatePropertyRector.php b/rules/privatization/src/Rector/Property/PrivatizeLocalPropertyToPrivatePropertyRector.php index 7610b92bd18c..07ea7966b932 100644 --- a/rules/privatization/src/Rector/Property/PrivatizeLocalPropertyToPrivatePropertyRector.php +++ b/rules/privatization/src/Rector/Property/PrivatizeLocalPropertyToPrivatePropertyRector.php @@ -116,7 +116,7 @@ public function refactor(Node $node): ?Node private function shouldSkip(Property $property): bool { $classLike = $property->getAttribute(AttributeKey::CLASS_NODE); - if ($classLike === null) { + if (! $classLike instanceof ClassLike) { return true; } diff --git a/rules/psr4/src/Composer/PSR4NamespaceMatcher.php b/rules/psr4/src/Composer/PSR4NamespaceMatcher.php index c00cbfe28a95..729192a00595 100644 --- a/rules/psr4/src/Composer/PSR4NamespaceMatcher.php +++ b/rules/psr4/src/Composer/PSR4NamespaceMatcher.php @@ -34,7 +34,7 @@ public function __construct( public function getExpectedNamespace(Node $node): ?string { $smartFileInfo = $this->currentFileInfoProvider->getSmartFileInfo(); - if ($smartFileInfo === null) { + if (! $smartFileInfo instanceof SmartFileInfo) { throw new ShouldNotHappenException(); } diff --git a/rules/removing-static/src/Rector/ClassMethod/LocallyCalledStaticMethodToNonStaticRector.php b/rules/removing-static/src/Rector/ClassMethod/LocallyCalledStaticMethodToNonStaticRector.php index 51566d2fae4f..c9bedce13d81 100644 --- a/rules/removing-static/src/Rector/ClassMethod/LocallyCalledStaticMethodToNonStaticRector.php +++ b/rules/removing-static/src/Rector/ClassMethod/LocallyCalledStaticMethodToNonStaticRector.php @@ -98,7 +98,7 @@ private function refactorClassMethod(ClassMethod $classMethod): ?ClassMethod private function refactorStaticCall(StaticCall $staticCall): ?MethodCall { $classMethod = $this->nodeRepository->findClassMethodByStaticCall($staticCall); - if ($classMethod === null) { + if (! $classMethod instanceof ClassMethod) { return null; } diff --git a/rules/removing-static/src/Rector/Class_/DesiredClassTypeToDynamicRector.php b/rules/removing-static/src/Rector/Class_/DesiredClassTypeToDynamicRector.php index 3e1029fcfe35..95abf50c1866 100644 --- a/rules/removing-static/src/Rector/Class_/DesiredClassTypeToDynamicRector.php +++ b/rules/removing-static/src/Rector/Class_/DesiredClassTypeToDynamicRector.php @@ -150,7 +150,7 @@ public function refactor(Node $node): ?Node private function completeDependencyToConstructorOnly(Class_ $class, string $classType): void { $constructClassMethod = $class->getMethod(MethodName::CONSTRUCT); - if ($constructClassMethod === null) { + if (! $constructClassMethod instanceof ClassMethod) { return; } diff --git a/rules/renaming/src/NodeManipulator/ClassRenamer.php b/rules/renaming/src/NodeManipulator/ClassRenamer.php index 481788ff39cf..73519d642101 100644 --- a/rules/renaming/src/NodeManipulator/ClassRenamer.php +++ b/rules/renaming/src/NodeManipulator/ClassRenamer.php @@ -172,7 +172,7 @@ private function refactorNamespace(Namespace_ $namespace, array $oldToNewClasses } $classLike = $this->getClassOfNamespaceToRefactor($namespace, $oldToNewClasses); - if ($classLike === null) { + if (! $classLike instanceof ClassLike) { return null; } diff --git a/rules/renaming/src/Rector/Namespace_/RenameNamespaceRector.php b/rules/renaming/src/Rector/Namespace_/RenameNamespaceRector.php index aa5993a79df8..0e6e6b07432d 100644 --- a/rules/renaming/src/Rector/Namespace_/RenameNamespaceRector.php +++ b/rules/renaming/src/Rector/Namespace_/RenameNamespaceRector.php @@ -78,7 +78,7 @@ public function refactor(Node $node): ?Node } $renamedNamespaceValueObject = $this->namespaceMatcher->matchRenamedNamespace($name, $this->oldToNewNamespaces); - if ($renamedNamespaceValueObject === null) { + if (! $renamedNamespaceValueObject instanceof RenamedNamespace) { return null; } @@ -123,7 +123,7 @@ public function configure(array $configuration): void private function isClassFullyQualifiedName(Node $node): bool { $parentNode = $node->getAttribute(AttributeKey::PARENT_NODE); - if ($parentNode === null) { + if (! $parentNode instanceof Node) { return false; } @@ -142,7 +142,7 @@ private function isClassFullyQualifiedName(Node $node): bool private function isPartialNamespace(Name $name): bool { $resolvedName = $name->getAttribute(AttributeKey::RESOLVED_NAME); - if ($resolvedName === null) { + if (! $resolvedName instanceof Name) { return false; } diff --git a/rules/restoration/src/Rector/ClassMethod/InferParamFromClassMethodReturnRector.php b/rules/restoration/src/Rector/ClassMethod/InferParamFromClassMethodReturnRector.php index 538e02555e61..5d32f1043112 100644 --- a/rules/restoration/src/Rector/ClassMethod/InferParamFromClassMethodReturnRector.php +++ b/rules/restoration/src/Rector/ClassMethod/InferParamFromClassMethodReturnRector.php @@ -130,7 +130,7 @@ public function refactor(Node $node): ?Node foreach ($this->inferParamFromClassMethodReturn as $inferParamFromClassMethodReturn) { $returnClassMethod = $this->matchReturnClassMethod($node, $inferParamFromClassMethodReturn); - if ($returnClassMethod === null) { + if (! $returnClassMethod instanceof \PhpParser\Node\Stmt\ClassMethod) { continue; } @@ -139,7 +139,7 @@ public function refactor(Node $node): ?Node $currentPhpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node); $paramType = $this->constantReturnToParamTypeConverter->convert($returnType); - if ($paramType === null) { + if (! $paramType instanceof Type) { continue; } diff --git a/rules/restoration/src/Rector/New_/CompleteMissingDependencyInNewRector.php b/rules/restoration/src/Rector/New_/CompleteMissingDependencyInNewRector.php index bb63d0a88bf2..bb8d9d24eec7 100644 --- a/rules/restoration/src/Rector/New_/CompleteMissingDependencyInNewRector.php +++ b/rules/restoration/src/Rector/New_/CompleteMissingDependencyInNewRector.php @@ -13,6 +13,7 @@ use ReflectionClass; use ReflectionMethod; use ReflectionParameter; +use ReflectionType; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -126,7 +127,7 @@ public function configure(array $configuration): void private function shouldSkipNew(New_ $new): bool { $constructorMethodReflection = $this->getNewNodeClassConstructorMethodReflection($new); - if ($constructorMethodReflection === null) { + if (! $constructorMethodReflection instanceof ReflectionMethod) { return true; } @@ -152,7 +153,7 @@ private function getNewNodeClassConstructorMethodReflection(New_ $new): ?Reflect private function resolveClassToInstantiateByParameterReflection(ReflectionParameter $reflectionParameter): ?string { $parameterType = $reflectionParameter->getType(); - if ($parameterType === null) { + if (! $parameterType instanceof ReflectionType) { return null; } diff --git a/rules/restoration/src/Rector/Use_/RestoreFullyQualifiedNameRector.php b/rules/restoration/src/Rector/Use_/RestoreFullyQualifiedNameRector.php index 784a956f5a4a..9c978f7255a9 100644 --- a/rules/restoration/src/Rector/Use_/RestoreFullyQualifiedNameRector.php +++ b/rules/restoration/src/Rector/Use_/RestoreFullyQualifiedNameRector.php @@ -11,7 +11,9 @@ use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Use_; use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; +use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Type\MixedType; +use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareReturnTagValueNode; use Rector\Core\Rector\AbstractRector; use Rector\Restoration\NameMatcher\FullyQualifiedNameMatcher; use Rector\Restoration\NameMatcher\PhpDocTypeNodeNameMatcher; @@ -148,7 +150,7 @@ private function refactorReturnTagValueNode(ClassMethod $classMethod): void { $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod); $attributeAwareReturnTagValueNode = $phpDocInfo->getReturnTagValue(); - if ($attributeAwareReturnTagValueNode === null) { + if (! $attributeAwareReturnTagValueNode instanceof AttributeAwareReturnTagValueNode) { return; } if (! $phpDocInfo->getReturnType() instanceof MixedType) { @@ -159,7 +161,7 @@ private function refactorReturnTagValueNode(ClassMethod $classMethod): void $fullyQualifiedTypeNode = $this->phpDocTypeNodeNameMatcher->matchIdentifier( $attributeAwareReturnTagValueNode->type->name ); - if ($fullyQualifiedTypeNode === null) { + if (! $fullyQualifiedTypeNode instanceof TypeNode) { return; } diff --git a/rules/sensio/src/BundleClassResolver.php b/rules/sensio/src/BundleClassResolver.php index 163fd25161c5..85e468d05038 100644 --- a/rules/sensio/src/BundleClassResolver.php +++ b/rules/sensio/src/BundleClassResolver.php @@ -5,6 +5,7 @@ namespace Rector\Sensio; use PhpParser\Node; +use PhpParser\Node\Stmt\ClassLike; use PhpParser\NodeTraverser; use PhpParser\NodeVisitor\NameResolver; use Rector\CodingStyle\Naming\ClassNaming; @@ -92,7 +93,7 @@ private function resolveClassNameFromFilePath(string $filePath): ?string $this->addFullyQualifiedNamesToNodes($nodes); $classLike = $this->betterNodeFinder->findFirstNonAnonymousClass($nodes); - if ($classLike === null) { + if (! $classLike instanceof ClassLike) { return null; } diff --git a/rules/sensio/src/TypeDeclaration/ReturnTypeDeclarationUpdater.php b/rules/sensio/src/TypeDeclaration/ReturnTypeDeclarationUpdater.php index 7629d921a57d..66714426eb90 100644 --- a/rules/sensio/src/TypeDeclaration/ReturnTypeDeclarationUpdater.php +++ b/rules/sensio/src/TypeDeclaration/ReturnTypeDeclarationUpdater.php @@ -8,6 +8,7 @@ use PhpParser\Node\Stmt\ClassMethod; use PHPStan\Type\ArrayType; use PHPStan\Type\UnionType; +use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareReturnTagValueNode; use Rector\AttributeAwarePhpDoc\Ast\Type\FullyQualifiedIdentifierTypeNode; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\Core\Php\PhpVersionProvider; @@ -60,7 +61,7 @@ private function updatePhpDoc(ClassMethod $classMethod, string $className): void $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod); $attributeAwareReturnTagValueNode = $phpDocInfo->getReturnTagValue(); - if ($attributeAwareReturnTagValueNode === null) { + if (! $attributeAwareReturnTagValueNode instanceof AttributeAwareReturnTagValueNode) { return; } diff --git a/rules/symfony-code-quality/src/ConstantNameAndValueResolver.php b/rules/symfony-code-quality/src/ConstantNameAndValueResolver.php index fcbc1828855a..3cc93c61d997 100644 --- a/rules/symfony-code-quality/src/ConstantNameAndValueResolver.php +++ b/rules/symfony-code-quality/src/ConstantNameAndValueResolver.php @@ -43,7 +43,7 @@ public function resolveFromAttributes(array $routeAttributes, string $prefixForN } $constantNameAndValue = $this->constantNameAndValueMatcher->matchFromArg($arg, $prefixForNumeric); - if ($constantNameAndValue === null) { + if (! $constantNameAndValue instanceof ConstantNameAndValue) { continue; } diff --git a/rules/symfony-code-quality/src/Rector/Attribute/ExtractAttributeRouteNameConstantsRector.php b/rules/symfony-code-quality/src/Rector/Attribute/ExtractAttributeRouteNameConstantsRector.php index 8b26f17f88f8..529262d5e094 100644 --- a/rules/symfony-code-quality/src/Rector/Attribute/ExtractAttributeRouteNameConstantsRector.php +++ b/rules/symfony-code-quality/src/Rector/Attribute/ExtractAttributeRouteNameConstantsRector.php @@ -11,6 +11,7 @@ use Rector\SymfonyCodeQuality\ConstantNameAndValueResolver; use Rector\SymfonyCodeQuality\NodeFactory\RouteNameClassFactory; use Rector\SymfonyCodeQuality\ValueObject\ClassName; +use Rector\SymfonyCodeQuality\ValueObject\ConstantNameAndValue; use Symfony\Component\Routing\Annotation\Route; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ExtraFileCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -132,7 +133,7 @@ public function refactor(Node $node): ?Node } $constantNameAndValue = $this->constantNameAndValueMatcher->matchFromArg($arg, 'ROUTE_'); - if ($constantNameAndValue === null) { + if (! $constantNameAndValue instanceof ConstantNameAndValue) { continue; } diff --git a/rules/symfony-php-config/src/Rector/MethodCall/AutoInPhpSymfonyConfigRector.php b/rules/symfony-php-config/src/Rector/MethodCall/AutoInPhpSymfonyConfigRector.php index c808d4ed8302..3b3c6169ca9e 100644 --- a/rules/symfony-php-config/src/Rector/MethodCall/AutoInPhpSymfonyConfigRector.php +++ b/rules/symfony-php-config/src/Rector/MethodCall/AutoInPhpSymfonyConfigRector.php @@ -129,7 +129,7 @@ private function shouldSkipMethodCall(MethodCall $methodCall): bool } $rootMethodCall = $this->fluentChainMethodCallNodeAnalyzer->resolveRootMethodCall($methodCall); - if ($rootMethodCall === null) { + if (! $rootMethodCall instanceof \PhpParser\Node\Expr\MethodCall) { return true; } diff --git a/rules/symfony-phpunit/src/Rector/Class_/SelfContainerGetMethodCallFromTestToSetUpMethodRector.php b/rules/symfony-phpunit/src/Rector/Class_/SelfContainerGetMethodCallFromTestToSetUpMethodRector.php index 84d1b3923b65..09e2bae2d2d7 100644 --- a/rules/symfony-phpunit/src/Rector/Class_/SelfContainerGetMethodCallFromTestToSetUpMethodRector.php +++ b/rules/symfony-phpunit/src/Rector/Class_/SelfContainerGetMethodCallFromTestToSetUpMethodRector.php @@ -6,6 +6,7 @@ use PhpParser\Node; use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Stmt\ClassMethod; use Rector\Core\Rector\AbstractPHPUnitRector; use Rector\Core\ValueObject\MethodName; use Rector\PHPUnit\Manipulator\OnContainerGetCallManipulator; @@ -128,7 +129,7 @@ public function refactor(Node $node): ?Node // 2. put them to setUp() method $setUpClassMethod = $node->getMethod(MethodName::SET_UP); - if ($setUpClassMethod === null) { + if (! $setUpClassMethod instanceof ClassMethod) { $setUpClassMethod = $this->kernelTestCaseNodeFactory->createSetUpClassMethodWithGetTypes( $node, $serviceTypes diff --git a/rules/symfony/src/Rector/Class_/MakeCommandLazyRector.php b/rules/symfony/src/Rector/Class_/MakeCommandLazyRector.php index 68c1c792c6b7..6bfa7c817811 100644 --- a/rules/symfony/src/Rector/Class_/MakeCommandLazyRector.php +++ b/rules/symfony/src/Rector/Class_/MakeCommandLazyRector.php @@ -9,6 +9,7 @@ use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Expression; use PHPStan\Type\StringType; use Rector\Core\Rector\AbstractRector; @@ -73,7 +74,7 @@ public function refactor(Node $node): ?Node } $commandName = $this->resolveCommandNameAndRemove($node); - if ($commandName === null) { + if (! $commandName instanceof Node) { return null; } @@ -90,7 +91,7 @@ public function refactor(Node $node): ?Node private function resolveCommandNameAndRemove(Class_ $class): ?Node { $commandName = $this->resolveCommandNameFromConstructor($class); - if ($commandName === null) { + if (! $commandName instanceof Node) { $commandName = $this->resolveCommandNameFromSetName($class); } @@ -112,7 +113,7 @@ private function resolveCommandNameFromConstructor(Class_ $class): ?Node } $commandName = $this->matchCommandNameNodeInConstruct($node); - if ($commandName === null) { + if (! $commandName instanceof Expr) { return null; } @@ -158,7 +159,7 @@ private function resolveCommandNameFromSetName(Class_ $class): ?Node private function removeConstructorIfHasOnlySetNameMethodCall(Class_ $class): void { $constructClassMethod = $class->getMethod(MethodName::CONSTRUCT); - if ($constructClassMethod === null) { + if (! $constructClassMethod instanceof ClassMethod) { return; } diff --git a/rules/symfony/src/ValueObject/ServiceMap/ServiceMap.php b/rules/symfony/src/ValueObject/ServiceMap/ServiceMap.php index 4f0dd56fc158..af79dd8fd65e 100644 --- a/rules/symfony/src/ValueObject/ServiceMap/ServiceMap.php +++ b/rules/symfony/src/ValueObject/ServiceMap/ServiceMap.php @@ -31,7 +31,7 @@ public function hasService(string $id): bool public function getServiceType(string $id): ?Type { $serviceDefinition = $this->getService($id); - if ($serviceDefinition === null) { + if (! $serviceDefinition instanceof ServiceDefinition) { return null; } diff --git a/rules/symfony2/src/Rector/StaticCall/ParseFileRector.php b/rules/symfony2/src/Rector/StaticCall/ParseFileRector.php index 64abf040e6ec..f529005d97a9 100644 --- a/rules/symfony2/src/Rector/StaticCall/ParseFileRector.php +++ b/rules/symfony2/src/Rector/StaticCall/ParseFileRector.php @@ -8,6 +8,7 @@ use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\Expr\StaticCall; +use PHPStan\Analyser\Scope; use PHPStan\Type\Constant\ConstantStringType; use Rector\Core\Exception\ShouldNotHappenException; use Rector\Core\Rector\AbstractRector; @@ -96,7 +97,7 @@ private function isArgumentYamlFile(StaticCall $staticCall): bool // try to detect current value $nodeScope = $possibleFileNode->getAttribute(AttributeKey::SCOPE); - if ($nodeScope === null) { + if (! $nodeScope instanceof Scope) { throw new ShouldNotHappenException(); } diff --git a/rules/symfony3/src/FormHelper/FormTypeStringToTypeProvider.php b/rules/symfony3/src/FormHelper/FormTypeStringToTypeProvider.php index f47a322e10ae..5e9ede757433 100644 --- a/rules/symfony3/src/FormHelper/FormTypeStringToTypeProvider.php +++ b/rules/symfony3/src/FormHelper/FormTypeStringToTypeProvider.php @@ -5,6 +5,7 @@ namespace Rector\Symfony3\FormHelper; use Nette\Utils\Strings; +use Rector\Symfony\Contract\Tag\TagInterface; use Rector\Symfony\ServiceMapProvider; final class FormTypeStringToTypeProvider @@ -97,7 +98,7 @@ private function provideCustomServiceFormTypeByAliasFromContainerXml(): array $formTypeServiceDefinitions = $serviceMap->getServicesByTag('form.type'); foreach ($formTypeServiceDefinitions as $formTypeServiceDefinition) { $formTypeTag = $formTypeServiceDefinition->getTag('form.type'); - if ($formTypeTag === null) { + if (! $formTypeTag instanceof TagInterface) { continue; } diff --git a/rules/symfony3/src/Rector/ClassMethod/GetRequestRector.php b/rules/symfony3/src/Rector/ClassMethod/GetRequestRector.php index 4065e3a6d81b..f1b32d9734ec 100644 --- a/rules/symfony3/src/Rector/ClassMethod/GetRequestRector.php +++ b/rules/symfony3/src/Rector/ClassMethod/GetRequestRector.php @@ -166,7 +166,7 @@ private function isGetRequestInAction(Node $node): bool } $classMethod = $node->getAttribute(AttributeKey::METHOD_NODE); - if ($classMethod === null) { + if (! $classMethod instanceof ClassMethod) { return false; } diff --git a/rules/symfony3/src/Rector/ClassMethod/MergeMethodAnnotationToRouteAnnotationRector.php b/rules/symfony3/src/Rector/ClassMethod/MergeMethodAnnotationToRouteAnnotationRector.php index 81e83f582ad9..026ddb5d88b7 100644 --- a/rules/symfony3/src/Rector/ClassMethod/MergeMethodAnnotationToRouteAnnotationRector.php +++ b/rules/symfony3/src/Rector/ClassMethod/MergeMethodAnnotationToRouteAnnotationRector.php @@ -5,6 +5,7 @@ namespace Rector\Symfony3\Rector\ClassMethod; use PhpParser\Node; +use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\ClassMethod; use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover; use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Sensio\SensioMethodTagValueNode; @@ -86,7 +87,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { $classLike = $node->getAttribute(AttributeKey::CLASS_NODE); - if ($classLike === null) { + if (! $classLike instanceof ClassLike) { return null; } diff --git a/rules/symfony3/src/Rector/ClassMethod/RemoveDefaultGetBlockPrefixRector.php b/rules/symfony3/src/Rector/ClassMethod/RemoveDefaultGetBlockPrefixRector.php index 6c0729ea6a6f..c00504469253 100644 --- a/rules/symfony3/src/Rector/ClassMethod/RemoveDefaultGetBlockPrefixRector.php +++ b/rules/symfony3/src/Rector/ClassMethod/RemoveDefaultGetBlockPrefixRector.php @@ -71,7 +71,7 @@ public function refactor(Node $node): ?Node } $returnedExpr = $this->resolveOnlyStmtReturnExpr($node); - if ($returnedExpr === null) { + if (! $returnedExpr instanceof Expr) { return null; } diff --git a/rules/symfony3/src/Rector/MethodCall/ChangeCollectionTypeOptionNameFromTypeToEntryTypeRector.php b/rules/symfony3/src/Rector/MethodCall/ChangeCollectionTypeOptionNameFromTypeToEntryTypeRector.php index 78a1a83f6db2..2fefc922d4f1 100644 --- a/rules/symfony3/src/Rector/MethodCall/ChangeCollectionTypeOptionNameFromTypeToEntryTypeRector.php +++ b/rules/symfony3/src/Rector/MethodCall/ChangeCollectionTypeOptionNameFromTypeToEntryTypeRector.php @@ -94,7 +94,7 @@ public function refactor(Node $node): ?Node } $optionsArray = $this->matchOptionsArray($node); - if ($optionsArray === null) { + if (! $optionsArray instanceof Array_) { return null; } diff --git a/rules/symfony3/src/Rector/MethodCall/ChangeStringCollectionOptionToConstantRector.php b/rules/symfony3/src/Rector/MethodCall/ChangeStringCollectionOptionToConstantRector.php index 8da5f4e42048..b96297747e84 100644 --- a/rules/symfony3/src/Rector/MethodCall/ChangeStringCollectionOptionToConstantRector.php +++ b/rules/symfony3/src/Rector/MethodCall/ChangeStringCollectionOptionToConstantRector.php @@ -5,6 +5,7 @@ namespace Rector\Symfony3\Rector\MethodCall; use PhpParser\Node; +use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Scalar\String_; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -91,7 +92,7 @@ public function refactor(Node $node): ?Node } $optionsArray = $this->matchOptionsArray($node); - if ($optionsArray === null) { + if (! $optionsArray instanceof Array_) { return null; } diff --git a/rules/symfony3/src/Rector/MethodCall/FormTypeInstanceToClassConstRector.php b/rules/symfony3/src/Rector/MethodCall/FormTypeInstanceToClassConstRector.php index a5144ec4d81b..9421c941265d 100644 --- a/rules/symfony3/src/Rector/MethodCall/FormTypeInstanceToClassConstRector.php +++ b/rules/symfony3/src/Rector/MethodCall/FormTypeInstanceToClassConstRector.php @@ -19,6 +19,7 @@ use Rector\Symfony3\NodeFactory\BuilderFormNodeFactory; use Rector\Symfony3\NodeFactory\ConfigureOptionsNodeFactory; use ReflectionClass; +use ReflectionMethod; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -144,7 +145,7 @@ private function processNewInstance(MethodCall $methodCall, int $position, int $ $argValue->args ); - if ($methodCall === null) { + if (! $methodCall instanceof \PhpParser\Node\Expr\MethodCall) { return null; } } @@ -157,7 +158,7 @@ private function processNewInstance(MethodCall $methodCall, int $position, int $ private function refactorCollectionOptions(MethodCall $methodCall): void { $optionsArray = $this->matchOptionsArray($methodCall); - if ($optionsArray === null) { + if (! $optionsArray instanceof Array_) { return; } @@ -216,14 +217,14 @@ private function moveArgumentsToOptions( } $formTypeClass = $this->nodeRepository->findClass($className); - if ($formTypeClass === null) { + if (! $formTypeClass instanceof Class_) { return null; } $constructorClassMethod = $formTypeClass->getMethod(MethodName::CONSTRUCT); // nothing we can do, out of scope - if ($constructorClassMethod === null) { + if (! $constructorClassMethod instanceof ClassMethod) { return null; } @@ -245,7 +246,7 @@ private function resolveNamesToArgs(string $className, array $argNodes): array $reflectionClass = new ReflectionClass($className); $constructorReflectionMethod = $reflectionClass->getConstructor(); - if ($constructorReflectionMethod === null) { + if (! $constructorReflectionMethod instanceof ReflectionMethod) { return []; } diff --git a/rules/symfony3/src/Rector/MethodCall/OptionNameRector.php b/rules/symfony3/src/Rector/MethodCall/OptionNameRector.php index 7ffc7275c3de..70b01064d23b 100644 --- a/rules/symfony3/src/Rector/MethodCall/OptionNameRector.php +++ b/rules/symfony3/src/Rector/MethodCall/OptionNameRector.php @@ -5,6 +5,7 @@ namespace Rector\Symfony3\Rector\MethodCall; use PhpParser\Node; +use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Scalar\String_; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -61,7 +62,7 @@ public function refactor(Node $node): ?Node } $optionsArray = $this->matchOptionsArray($node); - if ($optionsArray === null) { + if (! $optionsArray instanceof Array_) { return null; } diff --git a/rules/symfony3/src/Rector/MethodCall/ReadOnlyOptionToAttributeRector.php b/rules/symfony3/src/Rector/MethodCall/ReadOnlyOptionToAttributeRector.php index cb6a9d2c4f98..c6b5cb298c4a 100644 --- a/rules/symfony3/src/Rector/MethodCall/ReadOnlyOptionToAttributeRector.php +++ b/rules/symfony3/src/Rector/MethodCall/ReadOnlyOptionToAttributeRector.php @@ -6,6 +6,7 @@ use PhpParser\Node; use PhpParser\Node\Expr\Array_; +use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Scalar\String_; use Rector\Core\PhpParser\Node\Manipulator\ArrayManipulator; @@ -73,7 +74,7 @@ public function refactor(Node $node): ?Node } $optionsArray = $this->matchOptionsArray($node); - if ($optionsArray === null) { + if (! $optionsArray instanceof Array_) { return null; } if (! $optionsArray instanceof Array_) { @@ -81,7 +82,7 @@ public function refactor(Node $node): ?Node } $readOnlyArrayItem = $this->arrayManipulator->findItemInInArrayByKeyAndUnset($optionsArray, 'read_only'); - if ($readOnlyArrayItem === null) { + if (! $readOnlyArrayItem instanceof ArrayItem) { return null; } diff --git a/rules/symfony4/src/Rector/MethodCall/FormIsValidRector.php b/rules/symfony4/src/Rector/MethodCall/FormIsValidRector.php index f3726e550231..914f6ae44b9c 100644 --- a/rules/symfony4/src/Rector/MethodCall/FormIsValidRector.php +++ b/rules/symfony4/src/Rector/MethodCall/FormIsValidRector.php @@ -85,7 +85,7 @@ private function shouldSkipMethodCall(MethodCall $methodCall): bool { $originalNode = $methodCall->getAttribute(AttributeKey::ORIGINAL_NODE); // skip just added calls - if ($originalNode === null) { + if (! $originalNode instanceof Node) { return true; } diff --git a/rules/symfony4/src/Rector/MethodCall/SimplifyWebTestCaseAssertionsRector.php b/rules/symfony4/src/Rector/MethodCall/SimplifyWebTestCaseAssertionsRector.php index 8409251795a2..31301de62fdb 100644 --- a/rules/symfony4/src/Rector/MethodCall/SimplifyWebTestCaseAssertionsRector.php +++ b/rules/symfony4/src/Rector/MethodCall/SimplifyWebTestCaseAssertionsRector.php @@ -10,6 +10,7 @@ use PhpParser\Node\Expr\PropertyFetch; use PhpParser\Node\Scalar\LNumber; use PhpParser\Node\Scalar\String_; +use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\Expression; use Rector\Core\Rector\AbstractRector; use Rector\NodeTypeResolver\Node\AttributeKey; @@ -131,7 +132,7 @@ public function refactor(Node $node): ?Node private function isInWebTestCase(MethodCall $methodCall): bool { $classLike = $methodCall->getAttribute(AttributeKey::CLASS_NODE); - if ($classLike === null) { + if (! $classLike instanceof ClassLike) { return false; } diff --git a/rules/symfony4/src/Rector/New_/StringToArrayArgumentProcessRector.php b/rules/symfony4/src/Rector/New_/StringToArrayArgumentProcessRector.php index 80958144f3fd..78c50e539923 100644 --- a/rules/symfony4/src/Rector/New_/StringToArrayArgumentProcessRector.php +++ b/rules/symfony4/src/Rector/New_/StringToArrayArgumentProcessRector.php @@ -145,7 +145,7 @@ private function splitProcessCommandToItems(string $process): array private function processPreviousAssign(Node $node, Expr $firstArgumentExpr): void { $previousNodeAssign = $this->findPreviousNodeAssign($node, $firstArgumentExpr); - if ($previousNodeAssign === null) { + if (! $previousNodeAssign instanceof Assign) { return; } diff --git a/rules/transform/src/Rector/Assign/PropertyToMethodRector.php b/rules/transform/src/Rector/Assign/PropertyToMethodRector.php index 2dd9725ce48e..4ea4cbe5bc81 100644 --- a/rules/transform/src/Rector/Assign/PropertyToMethodRector.php +++ b/rules/transform/src/Rector/Assign/PropertyToMethodRector.php @@ -109,7 +109,7 @@ private function processSetter(Assign $assign): ?Node $propertyFetchNode = $assign->var; $propertyToMethodCall = $this->matchPropertyFetchCandidate($propertyFetchNode); - if ($propertyToMethodCall === null) { + if (! $propertyToMethodCall instanceof PropertyToMethod) { return null; } @@ -131,7 +131,7 @@ private function processGetter(Assign $assign): ?Node $propertyFetchNode = $assign->expr; $propertyToMethodCall = $this->matchPropertyFetchCandidate($propertyFetchNode); - if ($propertyToMethodCall === null) { + if (! $propertyToMethodCall instanceof PropertyToMethod) { return null; } diff --git a/rules/transform/src/Rector/FuncCall/ArgumentFuncCallToMethodCallRector.php b/rules/transform/src/Rector/FuncCall/ArgumentFuncCallToMethodCallRector.php index 4147d3702064..f318f977de7b 100644 --- a/rules/transform/src/Rector/FuncCall/ArgumentFuncCallToMethodCallRector.php +++ b/rules/transform/src/Rector/FuncCall/ArgumentFuncCallToMethodCallRector.php @@ -14,6 +14,7 @@ use Rector\Core\Exception\ShouldNotHappenException; use Rector\Core\Rector\AbstractRector; use Rector\Naming\Naming\PropertyNaming; +use Rector\Naming\ValueObject\ExpectedName; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType; use Rector\Transform\ValueObject\ArgumentFuncCallToMethodCall; @@ -179,7 +180,7 @@ private function refactorFuncCallToMethodCall( $fullyQualifiedObjectType = new FullyQualifiedObjectType($argumentFuncCallToMethodCall->getClass()); $expectedName = $this->propertyNaming->getExpectedNameFromType($fullyQualifiedObjectType); - if ($expectedName === null) { + if (! $expectedName instanceof ExpectedName) { throw new ShouldNotHappenException(); } diff --git a/rules/transform/src/Rector/MethodCall/ServiceGetterToConstructorInjectionRector.php b/rules/transform/src/Rector/MethodCall/ServiceGetterToConstructorInjectionRector.php index 547278f2052b..754e6bdb1eee 100644 --- a/rules/transform/src/Rector/MethodCall/ServiceGetterToConstructorInjectionRector.php +++ b/rules/transform/src/Rector/MethodCall/ServiceGetterToConstructorInjectionRector.php @@ -10,6 +10,7 @@ use PhpParser\Node\Expr\Variable; use PhpParser\Node\Identifier; use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Stmt\ClassLike; use PHPStan\Type\ObjectType; use Rector\Core\Contract\Rector\ConfigurableRectorInterface; use Rector\Core\Rector\AbstractRector; @@ -138,7 +139,7 @@ public function getNodeTypes(): array public function refactor(Node $node): ?Node { $classLike = $node->getAttribute(AttributeKey::CLASS_NODE); - if ($classLike === null) { + if (! $classLike instanceof ClassLike) { return null; } diff --git a/rules/transform/src/Rector/New_/NewToConstructorInjectionRector.php b/rules/transform/src/Rector/New_/NewToConstructorInjectionRector.php index 4bc3a1791ac7..837a9aa258ee 100644 --- a/rules/transform/src/Rector/New_/NewToConstructorInjectionRector.php +++ b/rules/transform/src/Rector/New_/NewToConstructorInjectionRector.php @@ -14,6 +14,7 @@ use Rector\Core\Contract\Rector\ConfigurableRectorInterface; use Rector\Core\Rector\AbstractRector; use Rector\Naming\Naming\PropertyNaming; +use Rector\Naming\ValueObject\ExpectedName; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Transform\NodeFactory\PropertyFetchFactory; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; @@ -172,7 +173,7 @@ private function refactorNew(New_ $new): void $objectType = new ObjectType($typeToConstructorInjection); $expectedPropertyName = $this->propertyNaming->getExpectedNameFromType($objectType); - if ($expectedPropertyName === null) { + if (! $expectedPropertyName instanceof ExpectedName) { continue; } diff --git a/rules/twig/src/Rector/Return_/SimpleFunctionAndFilterRector.php b/rules/twig/src/Rector/Return_/SimpleFunctionAndFilterRector.php index 9cb4cf53a587..3cec5c4754ed 100644 --- a/rules/twig/src/Rector/Return_/SimpleFunctionAndFilterRector.php +++ b/rules/twig/src/Rector/Return_/SimpleFunctionAndFilterRector.php @@ -11,6 +11,7 @@ use PhpParser\Node\Expr\New_; use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Scalar\String_; +use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\Return_; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; @@ -100,7 +101,7 @@ public function refactor(Node $node): ?Node } $classLike = $node->getAttribute(AttributeKey::CLASS_NODE); - if ($classLike === null) { + if (! $classLike instanceof ClassLike) { return null; } diff --git a/rules/type-declaration/src/AlreadyAssignDetector/ConstructorAssignDetector.php b/rules/type-declaration/src/AlreadyAssignDetector/ConstructorAssignDetector.php index d2f09a768010..a341576c4361 100644 --- a/rules/type-declaration/src/AlreadyAssignDetector/ConstructorAssignDetector.php +++ b/rules/type-declaration/src/AlreadyAssignDetector/ConstructorAssignDetector.php @@ -5,6 +5,7 @@ namespace Rector\TypeDeclaration\AlreadyAssignDetector; use PhpParser\Node; +use PhpParser\Node\Expr; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Stmt\ClassLike; use PhpParser\NodeTraverser; @@ -21,7 +22,7 @@ public function isPropertyAssigned(ClassLike $classLike, string $propertyName): $propertyName, &$isAssignedInConstructor ): ?int { $expr = $this->matchAssignExprToPropertyName($node, $propertyName); - if ($expr === null) { + if (! $expr instanceof Expr) { return null; } diff --git a/rules/type-declaration/src/AlreadyAssignDetector/NullTypeAssignDetector.php b/rules/type-declaration/src/AlreadyAssignDetector/NullTypeAssignDetector.php index fbd88d923809..2c0f7ca2bba9 100644 --- a/rules/type-declaration/src/AlreadyAssignDetector/NullTypeAssignDetector.php +++ b/rules/type-declaration/src/AlreadyAssignDetector/NullTypeAssignDetector.php @@ -5,6 +5,7 @@ namespace Rector\TypeDeclaration\AlreadyAssignDetector; use PhpParser\Node; +use PhpParser\Node\Expr; use PhpParser\Node\Stmt\ClassLike; use PhpParser\NodeTraverser; use Rector\NodeNestingScope\ScopeNestingComparator; @@ -49,7 +50,7 @@ public function detect(ClassLike $classLike, string $propertyName): ?bool $propertyName, &$needsNullType ): ?int { $expr = $this->matchAssignExprToPropertyName($node, $propertyName); - if ($expr === null) { + if (! $expr instanceof Expr) { return null; } diff --git a/rules/type-declaration/src/ChildPopulator/ChildParamPopulator.php b/rules/type-declaration/src/ChildPopulator/ChildParamPopulator.php index b016ce6e3b91..5abc9e07d47e 100644 --- a/rules/type-declaration/src/ChildPopulator/ChildParamPopulator.php +++ b/rules/type-declaration/src/ChildPopulator/ChildParamPopulator.php @@ -85,7 +85,7 @@ private function addParamTypeToMethod( $methodName = $this->nodeNameResolver->getName($classMethod); $currentClassMethod = $classLike->getMethod($methodName); - if ($currentClassMethod === null) { + if (! $currentClassMethod instanceof ClassMethod) { return; } diff --git a/rules/type-declaration/src/ChildPopulator/ChildReturnPopulator.php b/rules/type-declaration/src/ChildPopulator/ChildReturnPopulator.php index b82e64252f67..2cecc84e126e 100644 --- a/rules/type-declaration/src/ChildPopulator/ChildReturnPopulator.php +++ b/rules/type-declaration/src/ChildPopulator/ChildReturnPopulator.php @@ -66,7 +66,7 @@ private function addReturnTypeToChildMethod( $methodName = $this->nodeNameResolver->getName($classMethod); $currentClassMethod = $classLike->getMethod($methodName); - if ($currentClassMethod === null) { + if (! $currentClassMethod instanceof ClassMethod) { return; } diff --git a/rules/type-declaration/src/PhpDocParser/NonInformativeReturnTagRemover.php b/rules/type-declaration/src/PhpDocParser/NonInformativeReturnTagRemover.php index 4163087cafdf..c599812ce850 100644 --- a/rules/type-declaration/src/PhpDocParser/NonInformativeReturnTagRemover.php +++ b/rules/type-declaration/src/PhpDocParser/NonInformativeReturnTagRemover.php @@ -137,12 +137,12 @@ private function removeNullableType( PhpDocInfo $phpDocInfo ): void { $nullabledReturnType = $this->matchNullabledType($returnType); - if ($nullabledReturnType === null) { + if (! $nullabledReturnType instanceof Type) { return; } $nullabledReturnTagValueNode = $this->matchNullabledReturnTagValueNode($attributeAwareReturnTagValueNode); - if ($nullabledReturnTagValueNode === null) { + if (! $nullabledReturnTagValueNode instanceof TypeNode) { return; } diff --git a/rules/type-declaration/src/Rector/ClassMethod/AddParamTypeDeclarationRector.php b/rules/type-declaration/src/Rector/ClassMethod/AddParamTypeDeclarationRector.php index 6c576fd67324..6b5561e56baf 100644 --- a/rules/type-declaration/src/Rector/ClassMethod/AddParamTypeDeclarationRector.php +++ b/rules/type-declaration/src/Rector/ClassMethod/AddParamTypeDeclarationRector.php @@ -163,7 +163,7 @@ private function refactorClassMethodWithTypehintByParameterPosition( AddParamTypeDeclaration $addParamTypeDeclaration ): void { $parameter = $classMethod->params[$addParamTypeDeclaration->getPosition()] ?? null; - if ($parameter === null) { + if (! $parameter instanceof Param) { return; } diff --git a/rules/type-declaration/src/Rector/Identical/FlipTypeControlToUseExclusiveTypeRector.php b/rules/type-declaration/src/Rector/Identical/FlipTypeControlToUseExclusiveTypeRector.php index c6b1941cc22a..e6c3c6e21394 100644 --- a/rules/type-declaration/src/Rector/Identical/FlipTypeControlToUseExclusiveTypeRector.php +++ b/rules/type-declaration/src/Rector/Identical/FlipTypeControlToUseExclusiveTypeRector.php @@ -14,6 +14,7 @@ use PhpParser\Node\Stmt\Expression; use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode; use PHPStan\Type\NullType; +use PHPStan\Type\ObjectType; use PHPStan\Type\Type; use PHPStan\Type\UnionType; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; @@ -110,6 +111,10 @@ public function refactor(Node $node): ?Node $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($expression); $type = $phpDocInfo->getVarType(); + if (! $type instanceof UnionType) { + $type = $this->getObjectType($assign->expr); + } + if (! $type instanceof UnionType) { return null; } @@ -132,13 +137,14 @@ private function processConvertToExclusiveType(array $types, Expr $expr, PhpDocI ? $types[1] : $types[0]; - if (! $type instanceof FullyQualifiedObjectType) { + if (! $type instanceof FullyQualifiedObjectType && ! $type instanceof ObjectType) { return null; } - /** @var VarTagValueNode $tagValueNode */ $tagValueNode = $phpDocInfo->getVarTagValueNode(); - $this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $tagValueNode); + if ($tagValueNode instanceof VarTagValueNode) { + $this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $tagValueNode); + } return new BooleanNot(new Instanceof_($expr, new FullyQualified($type->getClassName()))); } diff --git a/rules/type-declaration/src/TypeAnalyzer/AdvancedArrayAnalyzer.php b/rules/type-declaration/src/TypeAnalyzer/AdvancedArrayAnalyzer.php index 7961b5d5dfe8..33e7a098b0a8 100644 --- a/rules/type-declaration/src/TypeAnalyzer/AdvancedArrayAnalyzer.php +++ b/rules/type-declaration/src/TypeAnalyzer/AdvancedArrayAnalyzer.php @@ -44,7 +44,7 @@ public function isClassStringArrayByStringArrayOverride(ArrayType $arrayType, Cl $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod); $arrayType = $this->typeNormalizer->convertConstantArrayTypeToArrayType($arrayType); - if ($arrayType === null) { + if (! $arrayType instanceof ArrayType) { return false; } diff --git a/rules/type-declaration/src/TypeInferer/AssignToPropertyTypeInferer.php b/rules/type-declaration/src/TypeInferer/AssignToPropertyTypeInferer.php index 492ccce023a2..de45acdc54c1 100644 --- a/rules/type-declaration/src/TypeInferer/AssignToPropertyTypeInferer.php +++ b/rules/type-declaration/src/TypeInferer/AssignToPropertyTypeInferer.php @@ -5,6 +5,7 @@ namespace Rector\TypeDeclaration\TypeInferer; use PhpParser\Node; +use PhpParser\Node\Expr; use PhpParser\Node\Expr\ArrayDimFetch; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Stmt\ClassLike; @@ -64,12 +65,12 @@ public function inferPropertyInClassLike(string $propertyName, ClassLike $classL } $expr = $this->propertyAssignMatcher->matchPropertyAssignExpr($node, $propertyName); - if ($expr === null) { + if (! $expr instanceof Expr) { return null; } $exprStaticType = $this->resolveExprStaticTypeIncludingDimFetch($node); - if ($exprStaticType === null) { + if (! $exprStaticType instanceof Type) { return null; } diff --git a/rules/type-declaration/src/TypeInferer/ParamTypeInferer/FunctionLikeDocParamTypeInferer.php b/rules/type-declaration/src/TypeInferer/ParamTypeInferer/FunctionLikeDocParamTypeInferer.php index 477685e21c07..2d776759985c 100644 --- a/rules/type-declaration/src/TypeInferer/ParamTypeInferer/FunctionLikeDocParamTypeInferer.php +++ b/rules/type-declaration/src/TypeInferer/ParamTypeInferer/FunctionLikeDocParamTypeInferer.php @@ -30,7 +30,7 @@ public function __construct(NodeNameResolver $nodeNameResolver, PhpDocInfoFactor public function inferParam(Param $param): Type { $functionLike = $this->resolveScopeNode($param); - if ($functionLike === null) { + if (! $functionLike instanceof FunctionLike) { return new MixedType(); } diff --git a/rules/type-declaration/src/TypeInferer/ParamTypeInferer/PHPUnitDataProviderParamTypeInferer.php b/rules/type-declaration/src/TypeInferer/ParamTypeInferer/PHPUnitDataProviderParamTypeInferer.php index 38498c8429fc..9eac4b8fbc53 100644 --- a/rules/type-declaration/src/TypeInferer/ParamTypeInferer/PHPUnitDataProviderParamTypeInferer.php +++ b/rules/type-declaration/src/TypeInferer/ParamTypeInferer/PHPUnitDataProviderParamTypeInferer.php @@ -67,7 +67,7 @@ public function autowirePHPUnitDataProviderParamTypeInferer(NodeTypeResolver $no public function inferParam(Param $param): Type { $dataProviderClassMethod = $this->resolveDataProviderClassMethod($param); - if ($dataProviderClassMethod === null) { + if (! $dataProviderClassMethod instanceof ClassMethod) { return new MixedType(); } diff --git a/rules/type-declaration/src/TypeInferer/PropertyTypeInferer/ConstructorPropertyTypeInferer.php b/rules/type-declaration/src/TypeInferer/PropertyTypeInferer/ConstructorPropertyTypeInferer.php index e51a30f4085f..ce728b3a8cbd 100644 --- a/rules/type-declaration/src/TypeInferer/PropertyTypeInferer/ConstructorPropertyTypeInferer.php +++ b/rules/type-declaration/src/TypeInferer/PropertyTypeInferer/ConstructorPropertyTypeInferer.php @@ -48,14 +48,14 @@ public function inferProperty(Property $property): Type } $classMethod = $classLike->getMethod(MethodName::CONSTRUCT); - if ($classMethod === null) { + if (! $classMethod instanceof ClassMethod) { return new MixedType(); } $propertyName = $this->nodeNameResolver->getName($property); $param = $this->classMethodPropertyFetchManipulator->resolveParamForPropertyFetch($classMethod, $propertyName); - if ($param === null) { + if (! $param instanceof Param) { return new MixedType(); } diff --git a/rules/type-declaration/src/TypeInferer/PropertyTypeInferer/DoctrineColumnPropertyTypeInferer.php b/rules/type-declaration/src/TypeInferer/PropertyTypeInferer/DoctrineColumnPropertyTypeInferer.php index a8f00791582c..7f0cb5a683be 100644 --- a/rules/type-declaration/src/TypeInferer/PropertyTypeInferer/DoctrineColumnPropertyTypeInferer.php +++ b/rules/type-declaration/src/TypeInferer/PropertyTypeInferer/DoctrineColumnPropertyTypeInferer.php @@ -87,7 +87,7 @@ public function inferProperty(Property $property): Type $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property); $doctrineColumnTagValueNode = $phpDocInfo->getByType(ColumnTagValueNode::class); - if ($doctrineColumnTagValueNode === null) { + if (! $doctrineColumnTagValueNode instanceof ColumnTagValueNode) { return new MixedType(); } @@ -97,7 +97,7 @@ public function inferProperty(Property $property): Type } $scalarType = $this->doctrineTypeToScalarType[$type] ?? null; - if ($scalarType === null) { + if (! $scalarType instanceof Type) { return new MixedType(); } diff --git a/rules/type-declaration/src/TypeInferer/PropertyTypeInferer/DoctrineRelationPropertyTypeInferer.php b/rules/type-declaration/src/TypeInferer/PropertyTypeInferer/DoctrineRelationPropertyTypeInferer.php index 159abfdac8fb..5d652c855a14 100644 --- a/rules/type-declaration/src/TypeInferer/PropertyTypeInferer/DoctrineRelationPropertyTypeInferer.php +++ b/rules/type-declaration/src/TypeInferer/PropertyTypeInferer/DoctrineRelationPropertyTypeInferer.php @@ -46,7 +46,7 @@ public function inferProperty(Property $property): Type $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property); $relationTagValueNode = $phpDocInfo->getByType(DoctrineRelationTagValueNodeInterface::class); - if ($relationTagValueNode === null) { + if (! $relationTagValueNode instanceof DoctrineRelationTagValueNodeInterface) { return new MixedType(); } @@ -93,7 +93,7 @@ private function processToOneRelation( } // nullable by default - if ($joinColumnTagValueNode === null || $joinColumnTagValueNode->isNullable()) { + if (! $joinColumnTagValueNode instanceof JoinColumnTagValueNode || $joinColumnTagValueNode->isNullable()) { $types[] = new NullType(); } diff --git a/rules/type-declaration/src/TypeInferer/PropertyTypeInferer/SingleMethodAssignedNodePropertyTypeInferer.php b/rules/type-declaration/src/TypeInferer/PropertyTypeInferer/SingleMethodAssignedNodePropertyTypeInferer.php index fc028d401002..d3fcb3b2b3a4 100644 --- a/rules/type-declaration/src/TypeInferer/PropertyTypeInferer/SingleMethodAssignedNodePropertyTypeInferer.php +++ b/rules/type-declaration/src/TypeInferer/PropertyTypeInferer/SingleMethodAssignedNodePropertyTypeInferer.php @@ -29,14 +29,14 @@ public function inferProperty(Property $property): Type } $classMethod = $classLike->getMethod(MethodName::CONSTRUCT); - if ($classMethod === null) { + if (! $classMethod instanceof ClassMethod) { return new MixedType(); } $propertyName = $this->nodeNameResolver->getName($property); $assignedNode = $this->resolveAssignedNodeToProperty($classMethod, $propertyName); - if ($assignedNode === null) { + if (! $assignedNode instanceof Expr) { return new MixedType(); } diff --git a/rules/type-declaration/src/TypeInferer/ReturnTypeInferer/SetterNodeReturnTypeInferer.php b/rules/type-declaration/src/TypeInferer/ReturnTypeInferer/SetterNodeReturnTypeInferer.php index 78eae5a22bf6..1fd5c4a84120 100644 --- a/rules/type-declaration/src/TypeInferer/ReturnTypeInferer/SetterNodeReturnTypeInferer.php +++ b/rules/type-declaration/src/TypeInferer/ReturnTypeInferer/SetterNodeReturnTypeInferer.php @@ -5,6 +5,7 @@ namespace Rector\TypeDeclaration\TypeInferer\ReturnTypeInferer; use PhpParser\Node\FunctionLike; +use PhpParser\Node\Stmt\ClassLike; use PHPStan\Type\MixedType; use PHPStan\Type\Type; use Rector\Core\PhpParser\Node\Manipulator\FunctionLikeManipulator; @@ -36,7 +37,7 @@ public function __construct( public function inferFunctionLike(FunctionLike $functionLike): Type { $classLike = $functionLike->getAttribute(AttributeKey::CLASS_NODE); - if ($classLike === null) { + if (! $classLike instanceof ClassLike) { return new MixedType(); } diff --git a/rules/type-declaration/src/TypeInferer/ReturnTypeInferer/YieldNodesReturnTypeInferer.php b/rules/type-declaration/src/TypeInferer/ReturnTypeInferer/YieldNodesReturnTypeInferer.php index 3d55fbff254c..6cb538ee6ec0 100644 --- a/rules/type-declaration/src/TypeInferer/ReturnTypeInferer/YieldNodesReturnTypeInferer.php +++ b/rules/type-declaration/src/TypeInferer/ReturnTypeInferer/YieldNodesReturnTypeInferer.php @@ -50,7 +50,7 @@ public function inferFunctionLike(FunctionLike $functionLike): Type $types = []; foreach ($yieldNodes as $yieldNode) { $value = $this->resolveYieldValue($yieldNode); - if ($value === null) { + if (! $value instanceof Expr) { continue; } diff --git a/rules/type-declaration/tests/Rector/Identical/FlipTypeControlToUseExclusiveTypeRector/Fixture/nullable_type.php.inc b/rules/type-declaration/tests/Rector/Identical/FlipTypeControlToUseExclusiveTypeRector/Fixture/nullable_type.php.inc new file mode 100644 index 000000000000..e27af4c48728 --- /dev/null +++ b/rules/type-declaration/tests/Rector/Identical/FlipTypeControlToUseExclusiveTypeRector/Fixture/nullable_type.php.inc @@ -0,0 +1,55 @@ +getStdClass(); + if ($stdClass === null) { + return; + } + } + + private function getStdClass(): ?stdClass + { + if (rand(0, 1)) { + return new stdClass; + } + + return null; + } +} + +?> +----- +getStdClass(); + if (!$stdClass instanceof \stdClass) { + return; + } + } + + private function getStdClass(): ?stdClass + { + if (rand(0, 1)) { + return new stdClass; + } + + return null; + } +} + +?> diff --git a/src/Comments/CommentableNodeResolver.php b/src/Comments/CommentableNodeResolver.php index 1b8c8ecb8769..59fcac53800b 100644 --- a/src/Comments/CommentableNodeResolver.php +++ b/src/Comments/CommentableNodeResolver.php @@ -20,7 +20,7 @@ public function resolve(Node $node): Node while (! $currentNode instanceof Stmt) { $currentNode = $currentNode->getAttribute(AttributeKey::PARENT_NODE); - if ($currentNode === null) { + if (! $currentNode instanceof Node) { return $previousNode; } diff --git a/src/Console/Command/AbstractCommand.php b/src/Console/Command/AbstractCommand.php index d4c3a87331ac..a9eddfce2c4d 100644 --- a/src/Console/Command/AbstractCommand.php +++ b/src/Console/Command/AbstractCommand.php @@ -7,6 +7,7 @@ use Rector\Caching\Detector\ChangedFilesDetector; use Rector\Core\Configuration\Option; use Rector\Core\Exception\ShouldNotHappenException; +use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -29,7 +30,7 @@ public function autowireAbstractCommand(ChangedFilesDetector $changedFilesDetect protected function initialize(InputInterface $input, OutputInterface $output): void { $application = $this->getApplication(); - if ($application === null) { + if (! $application instanceof Application) { throw new ShouldNotHappenException(); } diff --git a/src/Context/ContextAnalyzer.php b/src/Context/ContextAnalyzer.php index b271000201a7..8e2752d26cc3 100644 --- a/src/Context/ContextAnalyzer.php +++ b/src/Context/ContextAnalyzer.php @@ -44,7 +44,7 @@ public function isInLoop(Node $node): bool $stopNodes = array_merge(self::LOOP_NODES, self::BREAK_NODES); $firstParent = $this->betterNodeFinder->findParentTypes($node, $stopNodes); - if ($firstParent === null) { + if (! $firstParent instanceof Node) { return false; } @@ -57,7 +57,7 @@ public function isInIf(Node $node): bool $previousNode = $this->betterNodeFinder->findParentTypes($node, $breakNodes); - if ($previousNode === null) { + if (! $previousNode instanceof Node) { return false; } diff --git a/src/Exclusion/ExclusionManager.php b/src/Exclusion/ExclusionManager.php index a8b68f9c2f3c..98bb0f08bd99 100644 --- a/src/Exclusion/ExclusionManager.php +++ b/src/Exclusion/ExclusionManager.php @@ -36,7 +36,7 @@ public function isNodeSkippedByRector(Node $node, PhpRectorInterface $phpRector) { if ($node instanceof PropertyProperty || $node instanceof Const_) { $node = $node->getAttribute(AttributeKey::PARENT_NODE); - if ($node === null) { + if (! $node instanceof Node) { return false; } } diff --git a/src/NodeAnalyzer/PromotedPropertyResolver.php b/src/NodeAnalyzer/PromotedPropertyResolver.php index 13cc123c46da..ac495f72e749 100644 --- a/src/NodeAnalyzer/PromotedPropertyResolver.php +++ b/src/NodeAnalyzer/PromotedPropertyResolver.php @@ -6,6 +6,7 @@ use PhpParser\Node\Param; use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Stmt\ClassMethod; use Rector\Core\ValueObject\MethodName; final class PromotedPropertyResolver @@ -16,7 +17,7 @@ final class PromotedPropertyResolver public function resolveFromClass(Class_ $class): array { $constructClassMethod = $class->getMethod(MethodName::CONSTRUCT); - if ($constructClassMethod === null) { + if (! $constructClassMethod instanceof ClassMethod) { return []; } diff --git a/src/PHPStan/Reflection/TypeToCallReflectionResolver/ConstantArrayTypeToCallReflectionResolver.php b/src/PHPStan/Reflection/TypeToCallReflectionResolver/ConstantArrayTypeToCallReflectionResolver.php index 7d41d2c185d1..c6a9480b23d3 100644 --- a/src/PHPStan/Reflection/TypeToCallReflectionResolver/ConstantArrayTypeToCallReflectionResolver.php +++ b/src/PHPStan/Reflection/TypeToCallReflectionResolver/ConstantArrayTypeToCallReflectionResolver.php @@ -42,7 +42,7 @@ public function supports(Type $type): bool public function resolve(Type $type, ClassMemberAccessAnswerer $classMemberAccessAnswerer): ?MethodReflection { $constantArrayTypeAndMethod = $this->findTypeAndMethodName($type); - if ($constantArrayTypeAndMethod === null) { + if (! $constantArrayTypeAndMethod instanceof ConstantArrayTypeAndMethod) { return null; } if ($constantArrayTypeAndMethod->isUnknown()) { diff --git a/src/Php/Regex/RegexPatternArgumentManipulator.php b/src/Php/Regex/RegexPatternArgumentManipulator.php index 4475a815ee2e..13672d125b9a 100644 --- a/src/Php/Regex/RegexPatternArgumentManipulator.php +++ b/src/Php/Regex/RegexPatternArgumentManipulator.php @@ -13,6 +13,8 @@ use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Scalar\String_; +use PhpParser\Node\Stmt\ClassConst; +use PhpParser\Node\Stmt\ClassMethod; use Rector\Core\PhpParser\Node\BetterNodeFinder; use Rector\Core\PhpParser\Printer\BetterStandardPrinter; use Rector\NodeCollector\NodeCollector\ParsedNodeCollector; @@ -182,7 +184,7 @@ private function resolveArgumentValues(Expr $expr): array private function findAssignerForVariable(Variable $variable): array { $classMethod = $variable->getAttribute(AttributeKey::METHOD_NODE); - if ($classMethod === null) { + if (! $classMethod instanceof ClassMethod) { return []; } @@ -205,7 +207,7 @@ private function findAssignerForVariable(Variable $variable): array private function resolveClassConstFetchValue(ClassConstFetch $classConstFetch): array { $classConstNode = $this->parsedNodeCollector->findClassConstByClassConstFetch($classConstFetch); - if ($classConstNode === null) { + if (! $classConstNode instanceof ClassConst) { return []; } diff --git a/src/PhpParser/Node/BetterNodeFinder.php b/src/PhpParser/Node/BetterNodeFinder.php index b26fa2121c97..681f244f5450 100644 --- a/src/PhpParser/Node/BetterNodeFinder.php +++ b/src/PhpParser/Node/BetterNodeFinder.php @@ -211,7 +211,7 @@ public function hasInstancesOf($nodes, array $types): bool foreach ($types as $type) { $nodeFinderFindFirstInstanceOf = $this->nodeFinder->findFirstInstanceOf($nodes, $type); - if ($nodeFinderFindFirstInstanceOf === null) { + if (! $nodeFinderFindFirstInstanceOf instanceof Node) { continue; } diff --git a/src/PhpParser/Node/Manipulator/ArrayManipulator.php b/src/PhpParser/Node/Manipulator/ArrayManipulator.php index cf6c6a2231d2..c90b417fba32 100644 --- a/src/PhpParser/Node/Manipulator/ArrayManipulator.php +++ b/src/PhpParser/Node/Manipulator/ArrayManipulator.php @@ -79,7 +79,7 @@ public function findItemInInArrayByKeyAndUnset(Array_ $array, string $keyName): } $removedArrayItem = $array->items[$i]; - if ($removedArrayItem === null) { + if (! $removedArrayItem instanceof ArrayItem) { continue; } // remove + recount for the printer diff --git a/src/PhpParser/Node/Manipulator/ChildAndParentClassManipulator.php b/src/PhpParser/Node/Manipulator/ChildAndParentClassManipulator.php index ef139120ea3b..9a1ffcc40240 100644 --- a/src/PhpParser/Node/Manipulator/ChildAndParentClassManipulator.php +++ b/src/PhpParser/Node/Manipulator/ChildAndParentClassManipulator.php @@ -92,7 +92,7 @@ public function completeChildConstructors(Class_ $class, ClassMethod $constructo foreach ($childClasses as $childClass) { $childConstructorClassMethod = $childClass->getMethod(MethodName::CONSTRUCT); - if ($childConstructorClassMethod === null) { + if (! $childConstructorClassMethod instanceof ClassMethod) { continue; } @@ -116,7 +116,7 @@ public function completeChildConstructors(Class_ $class, ClassMethod $constructo private function completeParentConstructorBasedOnParentNode(Class_ $parentClassNode, ClassMethod $classMethod): void { $firstParentConstructMethodNode = $this->findFirstParentConstructor($parentClassNode); - if ($firstParentConstructMethodNode === null) { + if (! $firstParentConstructMethodNode instanceof ClassMethod) { return; } diff --git a/src/PhpParser/Node/Manipulator/ClassConstManipulator.php b/src/PhpParser/Node/Manipulator/ClassConstManipulator.php index 06481d14b87b..1a2fba08f2a5 100644 --- a/src/PhpParser/Node/Manipulator/ClassConstManipulator.php +++ b/src/PhpParser/Node/Manipulator/ClassConstManipulator.php @@ -8,6 +8,7 @@ use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassConst; +use PhpParser\Node\Stmt\Trait_; use Rector\Core\PhpParser\Node\BetterNodeFinder; use Rector\Core\PhpParser\Printer\BetterStandardPrinter; use Rector\NodeCollector\NodeCollector\ParsedNodeCollector; @@ -70,7 +71,7 @@ public function getAllClassConstFetch(ClassConst $classConst): array $usedTraitNames = $this->classManipulator->getUsedTraits($classLike); foreach ($usedTraitNames as $name) { $name = $this->parsedNodeCollector->findTrait((string) $name); - if ($name === null) { + if (! $name instanceof Trait_) { continue; } diff --git a/src/PhpParser/Node/Manipulator/ClassMethodAssignManipulator.php b/src/PhpParser/Node/Manipulator/ClassMethodAssignManipulator.php index 7394a600bc2d..153dd13d3d80 100644 --- a/src/PhpParser/Node/Manipulator/ClassMethodAssignManipulator.php +++ b/src/PhpParser/Node/Manipulator/ClassMethodAssignManipulator.php @@ -21,6 +21,7 @@ use PhpParser\Node\Stmt\Foreach_; use PHPStan\Reflection\ObjectTypeMethodReflection; use PHPStan\Reflection\ParameterReflection; +use PHPStan\Reflection\ParametersAcceptor; use PHPStan\Type\Type; use Rector\Core\PhpParser\Node\BetterNodeFinder; use Rector\Core\PhpParser\Node\NodeFactory; @@ -326,7 +327,7 @@ private function isMethodCallWithReferencedArgument(Node $node, Variable $variab $variableName = $this->nodeNameResolver->getName($variable); $parametersAcceptor = $this->callReflectionResolver->resolveParametersAcceptor($methodReflection, $node); - if ($parametersAcceptor === null) { + if (! $parametersAcceptor instanceof ParametersAcceptor) { return false; } @@ -376,7 +377,7 @@ private function isParameterReferencedInMethodReflection(New_ $new, int $argumen $methodReflection = $this->callReflectionResolver->resolveConstructor($new); $parametersAcceptor = $this->callReflectionResolver->resolveParametersAcceptor($methodReflection, $new); - if ($parametersAcceptor === null) { + if (! $parametersAcceptor instanceof ParametersAcceptor) { return false; } diff --git a/src/PhpParser/Node/Manipulator/PropertyFetchManipulator.php b/src/PhpParser/Node/Manipulator/PropertyFetchManipulator.php index 08d8f99afccb..3ebe062ffe81 100644 --- a/src/PhpParser/Node/Manipulator/PropertyFetchManipulator.php +++ b/src/PhpParser/Node/Manipulator/PropertyFetchManipulator.php @@ -9,6 +9,7 @@ use PhpParser\Node\Expr\PropertyFetch; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Stmt\Class_; +use PHPStan\Analyser\Scope; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Type\ErrorType; use PHPStan\Type\MixedType; @@ -142,7 +143,7 @@ public function isLocalPropertyFetch(Node $node): bool private function hasPublicProperty(PropertyFetch $propertyFetch, string $propertyName): bool { $nodeScope = $propertyFetch->getAttribute(AttributeKey::SCOPE); - if ($nodeScope === null) { + if (! $nodeScope instanceof Scope) { throw new ShouldNotHappenException(); } diff --git a/src/PhpParser/Node/Value/ValueResolver.php b/src/PhpParser/Node/Value/ValueResolver.php index 731534fe4a07..13ac0d15b202 100644 --- a/src/PhpParser/Node/Value/ValueResolver.php +++ b/src/PhpParser/Node/Value/ValueResolver.php @@ -12,6 +12,7 @@ use PhpParser\Node\Expr\ConstFetch; use PhpParser\Node\Scalar\MagicConst\Dir; use PhpParser\Node\Scalar\MagicConst\File; +use PhpParser\Node\Stmt\ClassConst; use PHPStan\Type\Constant\ConstantArrayType; use PHPStan\Type\ConstantScalarType; use Rector\Core\Exception\ShouldNotHappenException; @@ -226,7 +227,7 @@ private function resolveClassConstFetch(ClassConstFetch $classConstFetch) $classConstNode = $this->parsedNodeCollector->findClassConstant($class, $constant); - if ($classConstNode === null) { + if (! $classConstNode instanceof ClassConst) { // fallback to the name return $class . '::' . $constant; } diff --git a/src/PhpParser/NodeTransformer.php b/src/PhpParser/NodeTransformer.php index 2b9724e3a593..466b91c98985 100644 --- a/src/PhpParser/NodeTransformer.php +++ b/src/PhpParser/NodeTransformer.php @@ -34,7 +34,7 @@ final class NodeTransformer public function transformSprintfToArray(FuncCall $sprintfFuncCall): ?Array_ { $sprintfStringAndArgs = $this->splitMessageAndArgs($sprintfFuncCall); - if ($sprintfStringAndArgs === null) { + if (! $sprintfStringAndArgs instanceof SprintfStringAndArgs) { return null; } diff --git a/src/Rector/AbstractRector.php b/src/Rector/AbstractRector.php index 58fc0fd4308e..8ba270e7284b 100644 --- a/src/Rector/AbstractRector.php +++ b/src/Rector/AbstractRector.php @@ -187,7 +187,7 @@ public function hasParentTypes(Node $node, array $types): bool public function hasParentType(Node $node, string $type): bool { $parent = $node->getAttribute(AttributeKey::PARENT_NODE); - if ($parent === null) { + if (! $parent instanceof Node) { return false; } @@ -233,7 +233,7 @@ final public function enterNode(Node $node) $node = $this->refactor($node); // nothing to change → continue - if ($node === null) { + if (! $node instanceof Node) { return null; } diff --git a/src/Reflection/ClassMethodReflectionFactory.php b/src/Reflection/ClassMethodReflectionFactory.php index c1ca59272fc6..7c07dd6c67ea 100644 --- a/src/Reflection/ClassMethodReflectionFactory.php +++ b/src/Reflection/ClassMethodReflectionFactory.php @@ -30,7 +30,7 @@ public function createFromPHPStanTypeAndMethodName(Type $type, string $methodNam } $methodReflection = $this->createFromPHPStanTypeAndMethodName($unionedType, $methodName); - if ($methodReflection === null) { + if (! $methodReflection instanceof ReflectionMethod) { continue; } diff --git a/src/Reflection/ClassMethodReflectionHelper.php b/src/Reflection/ClassMethodReflectionHelper.php index fee501b613da..94d452fd0257 100644 --- a/src/Reflection/ClassMethodReflectionHelper.php +++ b/src/Reflection/ClassMethodReflectionHelper.php @@ -6,6 +6,7 @@ use Nette\Utils\Reflection; use Rector\Core\PhpDoc\PhpDocTagsFinder; +use ReflectionMethod; final class ClassMethodReflectionHelper { @@ -33,7 +34,7 @@ public function __construct( public function extractTagsFromMethodDocBlock(string $class, string $method): array { $reflectedMethod = $this->classMethodReflectionFactory->createReflectionMethodIfExists($class, $method); - if ($reflectedMethod === null) { + if (! $reflectedMethod instanceof ReflectionMethod) { return []; } diff --git a/src/Reflection/ClassReflectionToAstResolver.php b/src/Reflection/ClassReflectionToAstResolver.php index d699c2bc40d1..e66bf66a85ee 100644 --- a/src/Reflection/ClassReflectionToAstResolver.php +++ b/src/Reflection/ClassReflectionToAstResolver.php @@ -39,7 +39,7 @@ public function __construct(Parser $parser, SmartFileSystem $smartFileSystem, Be public function getClassFromObjectType(ObjectType $objectType): ?Class_ { $classReflection = $objectType->getClassReflection(); - if ($classReflection === null) { + if (! $classReflection instanceof ClassReflection) { return null; }