diff --git a/packages/StaticTypeMapper/PhpParser/IntersectionTypeNodeMapper.php b/packages/StaticTypeMapper/PhpParser/IntersectionTypeNodeMapper.php index 24f2a27f2f01..489130cf46cc 100644 --- a/packages/StaticTypeMapper/PhpParser/IntersectionTypeNodeMapper.php +++ b/packages/StaticTypeMapper/PhpParser/IntersectionTypeNodeMapper.php @@ -24,9 +24,6 @@ public function autowireUnionTypeNodeMapper(PhpParserNodeMapper $phpParserNodeMa $this->phpParserNodeMapper = $phpParserNodeMapper; } - /** - * @return class-string - */ public function getNodeType(): string { return Node\IntersectionType::class; diff --git a/packages/StaticTypeMapper/PhpParser/NullableTypeNodeMapper.php b/packages/StaticTypeMapper/PhpParser/NullableTypeNodeMapper.php index 062c0a968113..633706e7c931 100644 --- a/packages/StaticTypeMapper/PhpParser/NullableTypeNodeMapper.php +++ b/packages/StaticTypeMapper/PhpParser/NullableTypeNodeMapper.php @@ -31,9 +31,6 @@ public function autowireNullableTypeNodeMapper(PhpParserNodeMapper $phpParserNod $this->phpParserNodeMapper = $phpParserNodeMapper; } - /** - * @return class-string - */ public function getNodeType(): string { return NullableType::class; diff --git a/packages/StaticTypeMapper/PhpParser/UnionTypeNodeMapper.php b/packages/StaticTypeMapper/PhpParser/UnionTypeNodeMapper.php index d07e2433d58f..8e2cf2c4556f 100644 --- a/packages/StaticTypeMapper/PhpParser/UnionTypeNodeMapper.php +++ b/packages/StaticTypeMapper/PhpParser/UnionTypeNodeMapper.php @@ -30,9 +30,6 @@ public function autowireUnionTypeNodeMapper(PhpParserNodeMapper $phpParserNodeMa $this->phpParserNodeMapper = $phpParserNodeMapper; } - /** - * @return class-string - */ public function getNodeType(): string { return UnionType::class; diff --git a/packages/VendorLocker/NodeVendorLocker/PropertyTypeVendorLockResolver.php b/packages/VendorLocker/NodeVendorLocker/PropertyTypeVendorLockResolver.php index dfff231aec89..4e7dd127795b 100644 --- a/packages/VendorLocker/NodeVendorLocker/PropertyTypeVendorLockResolver.php +++ b/packages/VendorLocker/NodeVendorLocker/PropertyTypeVendorLockResolver.php @@ -57,7 +57,7 @@ private function isParentClassLocked(ClassReflection $classReflection, string $p continue; } - if ($parentClassReflection->getfileName() === $fileName) { + if ($parentClassReflection->getFileName() === $fileName) { continue; } diff --git a/rules/Arguments/ArgumentDefaultValueReplacer.php b/rules/Arguments/ArgumentDefaultValueReplacer.php index 3ca9fa945521..6632e23ebc8f 100644 --- a/rules/Arguments/ArgumentDefaultValueReplacer.php +++ b/rules/Arguments/ArgumentDefaultValueReplacer.php @@ -102,7 +102,7 @@ private function processArgs( } elseif (is_array($replaceArgumentDefaultValue->getValueBefore())) { $newArgs = $this->processArrayReplacement($expr->args, $replaceArgumentDefaultValue); - if ($newArgs) { + if (is_array($newArgs)) { $expr->args = $newArgs; } } diff --git a/rules/CodeQuality/Rector/Foreach_/SimplifyForeachToCoalescingRector.php b/rules/CodeQuality/Rector/Foreach_/SimplifyForeachToCoalescingRector.php index 6e8553f8aab1..4e30174cbecb 100644 --- a/rules/CodeQuality/Rector/Foreach_/SimplifyForeachToCoalescingRector.php +++ b/rules/CodeQuality/Rector/Foreach_/SimplifyForeachToCoalescingRector.php @@ -129,7 +129,7 @@ private function matchReturnOrAssignNode(Foreach_ $foreach): ?Node }); } - private function processForeachNodeWithReturnInside(Foreach_ $foreach, Return_ $return): ?Node + private function processForeachNodeWithReturnInside(Foreach_ $foreach, Return_ $return): Return_|null { if (! $this->nodeComparator->areNodesEqual($foreach->valueVar, $return->expr)) { return null; @@ -160,7 +160,7 @@ private function processForeachNodeWithReturnInside(Foreach_ $foreach, Return_ $ $coalesce = new Coalesce(new ArrayDimFetch( $foreach->expr, $checkedNode - ), $this->return && $this->return->expr !== null ? $this->return->expr : $checkedNode); + ), $this->return instanceof Return_ && $this->return->expr !== null ? $this->return->expr : $checkedNode); if ($this->return !== null) { return new Return_($coalesce); diff --git a/rules/CodingStyle/Naming/ClassNaming.php b/rules/CodingStyle/Naming/ClassNaming.php index 700450cc735f..939606a4988b 100644 --- a/rules/CodingStyle/Naming/ClassNaming.php +++ b/rules/CodingStyle/Naming/ClassNaming.php @@ -50,7 +50,7 @@ public function getNamespace(string $fullyQualifiedName): ?string { $fullyQualifiedName = trim($fullyQualifiedName, '\\'); - return Strings::before($fullyQualifiedName, '\\', -1) ?: null; + return Strings::before($fullyQualifiedName, '\\', -1); } public function getNameFromFileInfo(SmartFileInfo $smartFileInfo): string diff --git a/rules/CodingStyle/NodeFactory/JsonArrayFactory.php b/rules/CodingStyle/NodeFactory/JsonArrayFactory.php index 93b6146d2972..d0c0dab09501 100644 --- a/rules/CodingStyle/NodeFactory/JsonArrayFactory.php +++ b/rules/CodingStyle/NodeFactory/JsonArrayFactory.php @@ -60,7 +60,7 @@ private function replaceNodeObjectHashPlaceholdersWithNodes(Array_ $array, array $placeholderNode = $this->matchPlaceholderNode($onlyItem->value, $placeholderNodes); - if ($placeholderNode && $this->implodeAnalyzer->isImplodeToJson($placeholderNode)) { + if ($placeholderNode instanceof Expr && $this->implodeAnalyzer->isImplodeToJson($placeholderNode)) { /** * @var FuncCall $placeholderNode * @var Arg $firstArg diff --git a/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php b/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php index 64a67ae1c952..d9ad11a740bd 100644 --- a/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php +++ b/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php @@ -87,7 +87,7 @@ public function refactor(Node $node): ?Node } $oldVariableName = $this->getName($node->var); - if (! $oldVariableName) { + if (! is_string($oldVariableName)) { return null; } diff --git a/rules/DeadCode/PhpDoc/DeadParamTagValueNodeAnalyzer.php b/rules/DeadCode/PhpDoc/DeadParamTagValueNodeAnalyzer.php index 668dde1b1a6f..17e1a64d087d 100644 --- a/rules/DeadCode/PhpDoc/DeadParamTagValueNodeAnalyzer.php +++ b/rules/DeadCode/PhpDoc/DeadParamTagValueNodeAnalyzer.php @@ -20,6 +20,7 @@ use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey; use Rector\BetterPhpDocParser\ValueObject\Type\BracketsAwareUnionTypeNode; use Rector\BetterPhpDocParser\ValueObject\Type\SpacingAwareCallableTypeNode; +use Rector\DeadCode\TypeNodeAnalyzer\GenericTypeNodeAnalyzer; use Rector\NodeNameResolver\NodeNameResolver; use Rector\NodeTypeResolver\TypeComparator\TypeComparator; @@ -27,7 +28,8 @@ final class DeadParamTagValueNodeAnalyzer { public function __construct( private NodeNameResolver $nodeNameResolver, - private TypeComparator $typeComparator + private TypeComparator $typeComparator, + private GenericTypeNodeAnalyzer $genericTypeNodeAnalyzer, ) { } @@ -65,7 +67,7 @@ public function isDead(ParamTagValueNode $paramTagValueNode, FunctionLike $funct return $this->isEmptyDescription($paramTagValueNode, $param->type); } - if (! $this->hasGenericType($paramTagValueNode->type)) { + if (! $this->genericTypeNodeAnalyzer->hasGenericType($paramTagValueNode->type)) { return $this->isEmptyDescription($paramTagValueNode, $param->type); } @@ -136,23 +138,6 @@ private function isUnionIdentifier(PhpDocTagNode $phpDocTagNode): bool return true; } - private function hasGenericType(BracketsAwareUnionTypeNode $bracketsAwareUnionTypeNode): bool - { - $types = $bracketsAwareUnionTypeNode->types; - - foreach ($types as $type) { - if ($type instanceof GenericTypeNode) { - if ($type->type instanceof IdentifierTypeNode && $type->type->name === 'array') { - continue; - } - - return true; - } - } - - return false; - } - private function matchParamByName(string $desiredParamName, FunctionLike $functionLike): ?Param { foreach ($functionLike->getParams() as $param) { diff --git a/rules/DeadCode/PhpDoc/DeadReturnTagValueNodeAnalyzer.php b/rules/DeadCode/PhpDoc/DeadReturnTagValueNodeAnalyzer.php index 120fbe45ee8c..8093314b3e55 100644 --- a/rules/DeadCode/PhpDoc/DeadReturnTagValueNodeAnalyzer.php +++ b/rules/DeadCode/PhpDoc/DeadReturnTagValueNodeAnalyzer.php @@ -9,11 +9,11 @@ use PhpParser\Node\Stmt\Trait_; use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode; use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode; -use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; use PHPStan\PhpDocParser\Ast\Type\ThisTypeNode; use Rector\BetterPhpDocParser\ValueObject\Type\BracketsAwareUnionTypeNode; use Rector\BetterPhpDocParser\ValueObject\Type\SpacingAwareCallableTypeNode; use Rector\Core\PhpParser\Node\BetterNodeFinder; +use Rector\DeadCode\TypeNodeAnalyzer\GenericTypeNodeAnalyzer; use Rector\NodeTypeResolver\TypeComparator\TypeComparator; final class DeadReturnTagValueNodeAnalyzer @@ -21,6 +21,7 @@ final class DeadReturnTagValueNodeAnalyzer public function __construct( private TypeComparator $typeComparator, private BetterNodeFinder $betterNodeFinder, + private GenericTypeNodeAnalyzer $genericTypeNodeAnalyzer, ) { } @@ -55,27 +56,10 @@ public function isDead(ReturnTagValueNode $returnTagValueNode, FunctionLike $fun return $returnTagValueNode->description === ''; } - if (! $this->hasGenericType($returnTagValueNode->type)) { + if (! $this->genericTypeNodeAnalyzer->hasGenericType($returnTagValueNode->type)) { return $returnTagValueNode->description === ''; } return false; } - - private function hasGenericType(BracketsAwareUnionTypeNode $bracketsAwareUnionTypeNode): bool - { - $types = $bracketsAwareUnionTypeNode->types; - - foreach ($types as $type) { - if ($type instanceof GenericTypeNode) { - if ($type->type instanceof IdentifierTypeNode && $type->type->name === 'array') { - continue; - } - - return true; - } - } - - return false; - } } diff --git a/rules/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector.php b/rules/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector.php index eaa8cf199f61..db851a0882a3 100644 --- a/rules/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector.php +++ b/rules/DeadCode/Rector/Assign/RemoveUnusedVariableAssignRector.php @@ -125,7 +125,11 @@ private function shouldSkip(Assign $assign): bool return true; } - return $variable->name instanceof Variable && $this->betterNodeFinder->findFirstNext( + if (! $variable->name instanceof Variable) { + return false; + } + + return (bool) $this->betterNodeFinder->findFirstNext( $assign, fn (Node $node): bool => $node instanceof Variable ); diff --git a/rules/DeadCode/Rector/ClassMethod/RemoveDelegatingParentCallRector.php b/rules/DeadCode/Rector/ClassMethod/RemoveDelegatingParentCallRector.php index 3f37b13e5c62..18b6e72acd3d 100644 --- a/rules/DeadCode/Rector/ClassMethod/RemoveDelegatingParentCallRector.php +++ b/rules/DeadCode/Rector/ClassMethod/RemoveDelegatingParentCallRector.php @@ -163,16 +163,17 @@ private function shouldSkipWithAnnotationsOrAttributes(ClassMethod $classMethod) private function matchClassMethodOnlyStmt(ClassMethod $classMethod): null | Stmt | Expr { - if ($classMethod->stmts === null) { + $classMethodStmts = $classMethod->stmts; + if ($classMethodStmts === null) { return null; } - if (count((array) $classMethod->stmts) !== 1) { + if (count($classMethodStmts) !== 1) { return null; } // recount empty notes - $stmtsValues = array_values($classMethod->stmts); + $stmtsValues = array_values($classMethodStmts); return $this->unwrapExpression($stmtsValues[0]); } diff --git a/rules/DeadCode/Rector/FunctionLike/RemoveOverriddenValuesRector.php b/rules/DeadCode/Rector/FunctionLike/RemoveOverriddenValuesRector.php index 993fed219804..8d67a62b3b27 100644 --- a/rules/DeadCode/Rector/FunctionLike/RemoveOverriddenValuesRector.php +++ b/rules/DeadCode/Rector/FunctionLike/RemoveOverriddenValuesRector.php @@ -151,7 +151,7 @@ private function getNodeNames(array $nodes): array $nodeNames = []; foreach ($nodes as $node) { $nodeName = $this->getName($node); - if ($nodeName) { + if (is_string($nodeName)) { $nodeNames[] = $nodeName; } } diff --git a/rules/DeadCode/Rector/If_/UnwrapFutureCompatibleIfPhpVersionRector.php b/rules/DeadCode/Rector/If_/UnwrapFutureCompatibleIfPhpVersionRector.php index c484df62d796..bd0fdaceb71a 100644 --- a/rules/DeadCode/Rector/If_/UnwrapFutureCompatibleIfPhpVersionRector.php +++ b/rules/DeadCode/Rector/If_/UnwrapFutureCompatibleIfPhpVersionRector.php @@ -65,7 +65,7 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?array { - if ($node->elseifs) { + if ($node->elseifs !== []) { return null; } @@ -92,7 +92,7 @@ public function refactor(Node $node): ?array */ private function refactorIsMatch(If_ $if): ?array { - if ($if->elseifs) { + if ($if->elseifs !== []) { return null; } diff --git a/rules/DeadCode/Rector/Node/RemoveNonExistingVarAnnotationRector.php b/rules/DeadCode/Rector/Node/RemoveNonExistingVarAnnotationRector.php index 0d40cca0768a..6f829f837076 100644 --- a/rules/DeadCode/Rector/Node/RemoveNonExistingVarAnnotationRector.php +++ b/rules/DeadCode/Rector/Node/RemoveNonExistingVarAnnotationRector.php @@ -4,7 +4,6 @@ namespace Rector\DeadCode\Rector\Node; -use PhpParser\Comment; use PhpParser\Node; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\AssignRef; @@ -121,7 +120,7 @@ public function refactor(Node $node): ?Node } $comments = $node->getComments(); - if (isset($comments[1]) && $comments[1] instanceof Comment) { + if (isset($comments[1])) { $this->commentRemover->rollbackComments($node, $comments[1]); return $node; } diff --git a/rules/DeadCode/Rector/PropertyProperty/RemoveNullPropertyInitializationRector.php b/rules/DeadCode/Rector/PropertyProperty/RemoveNullPropertyInitializationRector.php index 6a521c526e47..6b5972420241 100644 --- a/rules/DeadCode/Rector/PropertyProperty/RemoveNullPropertyInitializationRector.php +++ b/rules/DeadCode/Rector/PropertyProperty/RemoveNullPropertyInitializationRector.php @@ -61,7 +61,7 @@ public function refactor(Node $node): ?Node $parent = $node->getAttribute(AttributeKey::PARENT_NODE); // skip typed properties - if ($parent instanceof Property && $parent->type) { + if ($parent instanceof Property && $parent->type !== null) { return null; } diff --git a/rules/DeadCode/Rector/Switch_/RemoveDuplicatedCaseInSwitchRector.php b/rules/DeadCode/Rector/Switch_/RemoveDuplicatedCaseInSwitchRector.php index 4bba06ab13e5..dfa9d60e3de0 100644 --- a/rules/DeadCode/Rector/Switch_/RemoveDuplicatedCaseInSwitchRector.php +++ b/rules/DeadCode/Rector/Switch_/RemoveDuplicatedCaseInSwitchRector.php @@ -85,7 +85,7 @@ public function refactor(Node $node): ?Node /** @var Case_|null $previousCase */ $previousCase = null; foreach ($node->cases as $case) { - if ($previousCase && $this->areSwitchStmtsEqualsAndWithBreak($case, $previousCase)) { + if ($previousCase instanceof Case_ && $this->areSwitchStmtsEqualsAndWithBreak($case, $previousCase)) { $previousCase->stmts = []; } diff --git a/rules/DeadCode/TypeNodeAnalyzer/GenericTypeNodeAnalyzer.php b/rules/DeadCode/TypeNodeAnalyzer/GenericTypeNodeAnalyzer.php new file mode 100644 index 000000000000..194276a60f8e --- /dev/null +++ b/rules/DeadCode/TypeNodeAnalyzer/GenericTypeNodeAnalyzer.php @@ -0,0 +1,28 @@ +types; + + foreach ($types as $type) { + if ($type instanceof GenericTypeNode) { + if ($type->type->name === 'array') { + continue; + } + + return true; + } + } + + return false; + } +} diff --git a/rules/DowngradePhp72/Rector/FuncCall/DowngradePregUnmatchedAsNullConstantRector.php b/rules/DowngradePhp72/Rector/FuncCall/DowngradePregUnmatchedAsNullConstantRector.php index 92d1233c2e25..08a15c250239 100644 --- a/rules/DowngradePhp72/Rector/FuncCall/DowngradePregUnmatchedAsNullConstantRector.php +++ b/rules/DowngradePhp72/Rector/FuncCall/DowngradePregUnmatchedAsNullConstantRector.php @@ -232,17 +232,9 @@ private function cleanBitwiseOrFlags(FuncCall $funcCall, BitwiseOr $bitwiseOr, E private function assignThirdArgsValue(FuncCall $funcCall, BitwiseOr $bitwiseOr): void { - if ($bitwiseOr instanceof BitwiseOr && $bitwiseOr->right instanceof ConstFetch && $this->isName( - $bitwiseOr->right, - self::FLAG - )) { + if ($bitwiseOr->right instanceof ConstFetch && $this->isName($bitwiseOr->right, self::FLAG)) { $bitwiseOr = $bitwiseOr->left; - } - - if ($bitwiseOr instanceof BitwiseOr && $bitwiseOr->left instanceof ConstFetch && $this->isName( - $bitwiseOr->left, - self::FLAG - )) { + } elseif ($bitwiseOr->left instanceof ConstFetch && $this->isName($bitwiseOr->left, self::FLAG)) { $bitwiseOr = $bitwiseOr->right; } diff --git a/rules/DowngradePhp74/Rector/Array_/DowngradeArraySpreadRector.php b/rules/DowngradePhp74/Rector/Array_/DowngradeArraySpreadRector.php index 2356e18725cd..4c244d4356b0 100644 --- a/rules/DowngradePhp74/Rector/Array_/DowngradeArraySpreadRector.php +++ b/rules/DowngradePhp74/Rector/Array_/DowngradeArraySpreadRector.php @@ -216,11 +216,8 @@ private function createArrayMerge(Array_ $array, array $items): FuncCall * as to invoke it only once and avoid potential bugs, * such as a method executing some side-effect */ - private function createVariableFromNonVariable( - Array_ $array, - ArrayItem $arrayItem, - int | string $position - ): Variable { + private function createVariableFromNonVariable(Array_ $array, ArrayItem $arrayItem, int $position): Variable + { /** @var Scope $nodeScope */ $nodeScope = $array->getAttribute(AttributeKey::SCOPE); // The variable name will be item0Unpacked, item1Unpacked, etc, @@ -277,18 +274,16 @@ private function createArgFromSpreadArrayItem(Scope $nodeScope, ArrayItem $array $iteratorToArrayFuncCall = new FuncCall(new Name('iterator_to_array'), [new Arg($arrayItem)]); - if ($type !== null) { - // If we know it is an array, then print it directly - // Otherwise PHPStan throws an error: - // "Else branch is unreachable because ternary operator condition is always true." - if ($type instanceof ArrayType) { - return new Arg($arrayItem); - } + // If we know it is an array, then print it directly + // Otherwise PHPStan throws an error: + // "Else branch is unreachable because ternary operator condition is always true." + if ($type instanceof ArrayType) { + return new Arg($arrayItem); + } - // If it is iterable, then directly return `iterator_to_array` - if ($this->isIterableType($type)) { - return new Arg($iteratorToArrayFuncCall); - } + // If it is iterable, then directly return `iterator_to_array` + if ($this->isIterableType($type)) { + return new Arg($iteratorToArrayFuncCall); } // Print a ternary, handling either an array or an iterator diff --git a/rules/DowngradePhp74/Rector/ClassMethod/DowngradeCovariantReturnTypeRector.php b/rules/DowngradePhp74/Rector/ClassMethod/DowngradeCovariantReturnTypeRector.php index 0cfdaf797e61..6af25526e9be 100644 --- a/rules/DowngradePhp74/Rector/ClassMethod/DowngradeCovariantReturnTypeRector.php +++ b/rules/DowngradePhp74/Rector/ClassMethod/DowngradeCovariantReturnTypeRector.php @@ -112,7 +112,7 @@ public function refactor(Node $node): ?Node return null; } - $isAlreadyDowngraded = $node->getAttribute(self::ALREADY_DOWNGRADED); + $isAlreadyDowngraded = (bool) $node->getAttribute(self::ALREADY_DOWNGRADED, false); if ($isAlreadyDowngraded) { return null; } diff --git a/rules/EarlyReturn/NodeFactory/InvertedIfFactory.php b/rules/EarlyReturn/NodeFactory/InvertedIfFactory.php index f46b6688c90e..24931ac376f1 100644 --- a/rules/EarlyReturn/NodeFactory/InvertedIfFactory.php +++ b/rules/EarlyReturn/NodeFactory/InvertedIfFactory.php @@ -31,7 +31,8 @@ public function createFromConditions(If_ $if, array $conditions, Return_ $return { $ifs = []; $ifNextReturn = $this->getIfNextReturn($if); - $stmt = $this->contextAnalyzer->isInLoop($if) && ! $ifNextReturn + + $stmt = $this->contextAnalyzer->isInLoop($if) && ! $ifNextReturn instanceof Return_ ? [new Continue_()] : [$return]; diff --git a/rules/Php71/Rector/BooleanOr/IsIterableRector.php b/rules/Php71/Rector/BooleanOr/IsIterableRector.php index 15ff0471e417..f10a079f47c6 100644 --- a/rules/Php71/Rector/BooleanOr/IsIterableRector.php +++ b/rules/Php71/Rector/BooleanOr/IsIterableRector.php @@ -56,7 +56,7 @@ public function refactor(Node $node): ?Node return null; } - return $this->isArrayAndDualCheckToAble->processBooleanOr($node, 'Traversable', 'is_iterable') ?: $node; + return $this->isArrayAndDualCheckToAble->processBooleanOr($node, 'Traversable', 'is_iterable'); } private function shouldSkip(): bool diff --git a/rules/Php71/Rector/FuncCall/CountOnNullRector.php b/rules/Php71/Rector/FuncCall/CountOnNullRector.php index a7c9507e9731..273834bdad42 100644 --- a/rules/Php71/Rector/FuncCall/CountOnNullRector.php +++ b/rules/Php71/Rector/FuncCall/CountOnNullRector.php @@ -175,7 +175,7 @@ private function shouldSkip(FuncCall $funcCall): bool return true; } - $alreadyChangedOnCount = $funcCall->getAttribute(self::ALREADY_CHANGED_ON_COUNT); + $alreadyChangedOnCount = (bool) $funcCall->getAttribute(self::ALREADY_CHANGED_ON_COUNT, false); // check if it has some condition before already, if so, probably it's already handled if ($alreadyChangedOnCount) { diff --git a/rules/Php72/NodeFactory/AnonymousFunctionFactory.php b/rules/Php72/NodeFactory/AnonymousFunctionFactory.php index 617dbfeaa0d3..2ac12cba79e5 100644 --- a/rules/Php72/NodeFactory/AnonymousFunctionFactory.php +++ b/rules/Php72/NodeFactory/AnonymousFunctionFactory.php @@ -160,7 +160,7 @@ public function createAnonymousFunctionFromString(Expr $expr): ?Closure } $match = Strings::match($node->value, self::DIM_FETCH_REGEX); - if (! $match) { + if ($match === null) { return $node; } diff --git a/rules/PhpSpecToPHPUnit/Naming/PhpSpecRenaming.php b/rules/PhpSpecToPHPUnit/Naming/PhpSpecRenaming.php index 25a6b37a859c..00ee65283452 100644 --- a/rules/PhpSpecToPHPUnit/Naming/PhpSpecRenaming.php +++ b/rules/PhpSpecToPHPUnit/Naming/PhpSpecRenaming.php @@ -129,6 +129,10 @@ private function removeNamePrefixes(string $name): string ['it_should_have_', 'it_should_be', 'it_should_', 'it_is_', 'it_', 'is_'] ); - return $name ?: $originalName; + if ($name === '') { + return $originalName; + } + + return $name; } } diff --git a/rules/PhpSpecToPHPUnit/Rector/MethodCall/PhpSpecMocksToPHPUnitMocksRector.php b/rules/PhpSpecToPHPUnit/Rector/MethodCall/PhpSpecMocksToPHPUnitMocksRector.php index a8e4c4f201db..7036f0f82399 100644 --- a/rules/PhpSpecToPHPUnit/Rector/MethodCall/PhpSpecMocksToPHPUnitMocksRector.php +++ b/rules/PhpSpecToPHPUnit/Rector/MethodCall/PhpSpecMocksToPHPUnitMocksRector.php @@ -234,7 +234,7 @@ private function createIsTypeOrIsInstanceOf(StaticCall $staticCall): MethodCall private function createMockVarDoc(Param $param, Name $name): string { - $paramType = (string) ($name->getAttribute(AttributeKey::ORIGINAL_NAME) ?: $name); + $paramType = (string) $name->getAttribute(AttributeKey::ORIGINAL_NAME, $name); $variableName = $this->getName($param->var); if ($variableName === null) { diff --git a/rules/Renaming/NodeManipulator/ClassRenamer.php b/rules/Renaming/NodeManipulator/ClassRenamer.php index 5d3d1e6a51d0..5e909e40aa46 100644 --- a/rules/Renaming/NodeManipulator/ClassRenamer.php +++ b/rules/Renaming/NodeManipulator/ClassRenamer.php @@ -214,7 +214,7 @@ private function refactorNamespace(Namespace_ $namespace, array $oldToNewClasses $newNamespace = $this->classNaming->getNamespace($newClassFullyQualified); // Renaming to class without namespace (example MyNamespace\DateTime -> DateTimeImmutable) - if (! $newNamespace) { + if (! is_string($newNamespace)) { $classLike->name = new Identifier($newClassFullyQualified); return $classLike;