diff --git a/packages/BetterPhpDocParser/src/Attributes/Ast/PhpDoc/AttributeAwareParamTagValueNode.php b/packages/BetterPhpDocParser/src/Attributes/Ast/PhpDoc/AttributeAwareParamTagValueNode.php index f6a2ca829290..7ba72847b897 100644 --- a/packages/BetterPhpDocParser/src/Attributes/Ast/PhpDoc/AttributeAwareParamTagValueNode.php +++ b/packages/BetterPhpDocParser/src/Attributes/Ast/PhpDoc/AttributeAwareParamTagValueNode.php @@ -38,6 +38,8 @@ public function __toString(): string $variadic = $this->isVariadic ? '...' : ''; $reference = $this->isReference ? '&' : ''; - return trim("{$this->type} {$variadic}{$reference}{$this->parameterName} {$this->description}"); + return trim( + sprintf('%s %s%s%s %s', $this->type, $variadic, $reference, $this->parameterName, $this->description) + ); } } diff --git a/packages/CakePHP/src/Rector/Name/ChangeSnakedFixtureNameToCamelRector.php b/packages/CakePHP/src/Rector/Name/ChangeSnakedFixtureNameToCamelRector.php index d37743bd661e..026ab962dfec 100644 --- a/packages/CakePHP/src/Rector/Name/ChangeSnakedFixtureNameToCamelRector.php +++ b/packages/CakePHP/src/Rector/Name/ChangeSnakedFixtureNameToCamelRector.php @@ -95,6 +95,6 @@ function ($token): string { ); $table = implode('/', $table); - return new String_("{$prefix}.{$table}", $name->getAttributes()); + return new String_(sprintf('%s.%s', $prefix, $table), $name->getAttributes()); } } diff --git a/packages/CodeQuality/src/Rector/Class_/CompleteDynamicPropertiesRector.php b/packages/CodeQuality/src/Rector/Class_/CompleteDynamicPropertiesRector.php index 6db6559a493a..cef4bc2f3981 100644 --- a/packages/CodeQuality/src/Rector/Class_/CompleteDynamicPropertiesRector.php +++ b/packages/CodeQuality/src/Rector/Class_/CompleteDynamicPropertiesRector.php @@ -216,7 +216,7 @@ private function createNewProperties(array $fetchedLocalPropertyNameToTypes, arr if ($this->isAtLeastPhpVersion('7.4')) { $phpStanNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($propertyType); - if ($phpStanNode) { + if ($phpStanNode !== null) { $property->type = $phpStanNode; } else { // fallback to doc type in PHP 7.4 diff --git a/packages/CodingStyle/src/Rector/FuncCall/ConsistentImplodeRector.php b/packages/CodingStyle/src/Rector/FuncCall/ConsistentImplodeRector.php index 08c578b4c84d..dc8f2a009195 100644 --- a/packages/CodingStyle/src/Rector/FuncCall/ConsistentImplodeRector.php +++ b/packages/CodingStyle/src/Rector/FuncCall/ConsistentImplodeRector.php @@ -77,6 +77,11 @@ public function refactor(Node $node): ?Node return $node; } + $firstArgumentValue = $node->args[0]->value; + if ($firstArgumentValue instanceof String_) { + return null; + } + if (count($node->args) === 2) { if ($this->isStringOrUnionStringOnlyType($node->args[1]->value)) { $node->args = array_reverse($node->args); diff --git a/packages/CodingStyle/src/Rector/Identical/IdenticalFalseToBooleanNotRector.php b/packages/CodingStyle/src/Rector/Identical/IdenticalFalseToBooleanNotRector.php index 04d997650a46..6760cbbc3f74 100644 --- a/packages/CodingStyle/src/Rector/Identical/IdenticalFalseToBooleanNotRector.php +++ b/packages/CodingStyle/src/Rector/Identical/IdenticalFalseToBooleanNotRector.php @@ -11,6 +11,7 @@ use PhpParser\Node\Expr\BooleanNot; use PHPStan\Type\Constant\ConstantBooleanType; use PHPStan\Type\IntegerType; +use PHPStan\Type\MixedType; use PHPStan\Type\Type; use PHPStan\Type\UnionType; use Rector\PhpParser\Node\Manipulator\BinaryOpManipulator; @@ -70,7 +71,14 @@ function (Node $node): bool { /** @var Expr $comparedNode */ [$comparedNode, ] = $matchedNodes; - if ($this->hasNullOrIntegerType($this->getStaticType($comparedNode))) { + $staticType = $this->getStaticType($comparedNode); + + // nothing we can do + if ($staticType instanceof MixedType) { + return null; + } + + if ($this->hasNullOrIntegerType($staticType)) { return null; } @@ -85,15 +93,16 @@ function (Node $node): bool { * E.g strpos() can return 0 and false, so this would be false positive: * ! 0 → true * ! false → true + * ! mixed → true/false */ private function hasNullOrIntegerType(?Type $staticType): bool { - if ($staticType instanceof UnionType) { - return $staticType->isSuperTypeOf(new IntegerType())->yes() && $staticType->isSuperTypeOf( - new ConstantBooleanType(false) - )->yes(); + if (! $staticType instanceof UnionType) { + return false; } - return false; + return $staticType->isSuperTypeOf(new IntegerType())->yes() && $staticType->isSuperTypeOf( + new ConstantBooleanType(false) + )->yes(); } } diff --git a/packages/CodingStyle/src/Rector/If_/NullableCompareToNullRector.php b/packages/CodingStyle/src/Rector/If_/NullableCompareToNullRector.php index 337444e75422..ce05947ce003 100644 --- a/packages/CodingStyle/src/Rector/If_/NullableCompareToNullRector.php +++ b/packages/CodingStyle/src/Rector/If_/NullableCompareToNullRector.php @@ -10,6 +10,7 @@ use PhpParser\Node\Expr\BooleanNot; use PhpParser\Node\Stmt\If_; use PHPStan\Type\ArrayType; +use PHPStan\Type\BooleanType; use PHPStan\Type\FloatType; use PHPStan\Type\IntegerType; use PHPStan\Type\MixedType; @@ -33,7 +34,7 @@ public function getDefinition(): RectorDefinition new CodeSample( <<<'PHP' /** @var stdClass|null $value */ -if ($value) { +if ($value) { } if (!$value) { @@ -113,6 +114,12 @@ private function isNullableNonScalarType(Node $node): bool if ($staticType->isSuperTypeOf(new IntegerType())->yes()) { return false; } + + // is bool? + if ($staticType->isSuperTypeOf(new BooleanType())->yes()) { + return false; + } + return ! $staticType->isSuperTypeOf(new FloatType())->yes(); } } diff --git a/packages/CodingStyle/tests/Rector/FuncCall/ConsistentImplodeRector/ConsistentImplodeRectorTest.php b/packages/CodingStyle/tests/Rector/FuncCall/ConsistentImplodeRector/ConsistentImplodeRectorTest.php index cf6eb97619d2..de16e00bc9cb 100644 --- a/packages/CodingStyle/tests/Rector/FuncCall/ConsistentImplodeRector/ConsistentImplodeRectorTest.php +++ b/packages/CodingStyle/tests/Rector/FuncCall/ConsistentImplodeRector/ConsistentImplodeRectorTest.php @@ -21,6 +21,7 @@ public function test(string $file): void public function provideDataForTest(): Iterator { yield [__DIR__ . '/Fixture/fixture.php.inc']; + yield [__DIR__ . '/Fixture/skip_already_switched.php.inc']; } protected function getRectorClass(): string diff --git a/packages/CodingStyle/tests/Rector/FuncCall/ConsistentImplodeRector/Fixture/skip_already_switched.php.inc b/packages/CodingStyle/tests/Rector/FuncCall/ConsistentImplodeRector/Fixture/skip_already_switched.php.inc new file mode 100644 index 000000000000..2cbb08c6ab08 --- /dev/null +++ b/packages/CodingStyle/tests/Rector/FuncCall/ConsistentImplodeRector/Fixture/skip_already_switched.php.inc @@ -0,0 +1,20 @@ + $configName) { + $setsListInString .= ' * ' . $groupName . ': ' . implode(', ', $configName) . PHP_EOL; + } + + return $setsListInString; + } +} diff --git a/packages/CodingStyle/tests/Rector/Identical/IdenticalFalseToBooleanNotRector/Fixture/fixture.php.inc b/packages/CodingStyle/tests/Rector/Identical/IdenticalFalseToBooleanNotRector/Fixture/fixture.php.inc index 6c1ab8888ad1..2ef2ad015d27 100644 --- a/packages/CodingStyle/tests/Rector/Identical/IdenticalFalseToBooleanNotRector/Fixture/fixture.php.inc +++ b/packages/CodingStyle/tests/Rector/Identical/IdenticalFalseToBooleanNotRector/Fixture/fixture.php.inc @@ -1,13 +1,7 @@ yieldFilesFromDirectory(__DIR__ . '/Fixture'); } protected function getRectorClass(): string diff --git a/packages/CodingStyle/tests/Rector/If_/NullableCompareToNullRector/Fixture/keep_nullable_bool.php.inc b/packages/CodingStyle/tests/Rector/If_/NullableCompareToNullRector/Fixture/keep_nullable_bool.php.inc new file mode 100644 index 000000000000..a530af7cd46b --- /dev/null +++ b/packages/CodingStyle/tests/Rector/If_/NullableCompareToNullRector/Fixture/keep_nullable_bool.php.inc @@ -0,0 +1,13 @@ +yieldFilesFromDirectory(__DIR__ . '/Fixture'); } protected function getRectorClass(): string diff --git a/packages/DeadCode/src/Rector/ClassMethod/RemoveDelegatingParentCallRector.php b/packages/DeadCode/src/Rector/ClassMethod/RemoveDelegatingParentCallRector.php index d858c45c193e..d0d6a658b761 100644 --- a/packages/DeadCode/src/Rector/ClassMethod/RemoveDelegatingParentCallRector.php +++ b/packages/DeadCode/src/Rector/ClassMethod/RemoveDelegatingParentCallRector.php @@ -212,7 +212,7 @@ private function isParentClassMethodVisibilityOverride(ClassMethod $classMethod, $className = $staticCall->getAttribute(AttributeKey::CLASS_NAME); $parentClassName = get_parent_class($className); - if ($parentClassName === false) { + if (! $parentClassName) { throw new ShouldNotHappenException(); } diff --git a/packages/DeadCode/tests/Rector/Stmt/RemoveDeadStmtRector/RemoveDeadStmtRectorTest.php b/packages/DeadCode/tests/Rector/Stmt/RemoveDeadStmtRector/RemoveDeadStmtRectorTest.php index 201956f08aff..75bdb47fb706 100644 --- a/packages/DeadCode/tests/Rector/Stmt/RemoveDeadStmtRector/RemoveDeadStmtRectorTest.php +++ b/packages/DeadCode/tests/Rector/Stmt/RemoveDeadStmtRector/RemoveDeadStmtRectorTest.php @@ -20,7 +20,7 @@ public function test(string $file): void public function provideDataForTest(): Iterator { - yield from $this->provideEachFileInDir(__DIR__ . '/Fixture'); + yield from $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); } protected function getRectorClass(): string diff --git a/packages/Doctrine/src/NodeFactory/EntityUuidNodeFactory.php b/packages/Doctrine/src/NodeFactory/EntityUuidNodeFactory.php index da9f35299645..3d855de98aea 100644 --- a/packages/Doctrine/src/NodeFactory/EntityUuidNodeFactory.php +++ b/packages/Doctrine/src/NodeFactory/EntityUuidNodeFactory.php @@ -50,6 +50,7 @@ public function createTemporaryUuidProperty(): Property { $uuidPropertyBuilder = $this->builderFactory->property('uuid'); $uuidPropertyBuilder->makePrivate(); + $uuidProperty = $uuidPropertyBuilder->getNode(); $this->decoratePropertyWithUuidAnnotations($uuidProperty, true, false); diff --git a/packages/Doctrine/src/Rector/ClassMethod/ChangeGetIdTypeToUuidRector.php b/packages/Doctrine/src/Rector/ClassMethod/ChangeGetIdTypeToUuidRector.php index f08658b4bf6a..415925c8048b 100644 --- a/packages/Doctrine/src/Rector/ClassMethod/ChangeGetIdTypeToUuidRector.php +++ b/packages/Doctrine/src/Rector/ClassMethod/ChangeGetIdTypeToUuidRector.php @@ -45,7 +45,7 @@ public function refactor(Node $node): ?Node } // is already set? - if ($node->returnType) { + if ($node->returnType !== null) { $currentType = $this->getName($node->returnType); if ($currentType === UuidInterface::class) { return null; diff --git a/packages/Doctrine/src/Rector/ClassMethod/ChangeSetIdTypeToUuidRector.php b/packages/Doctrine/src/Rector/ClassMethod/ChangeSetIdTypeToUuidRector.php index cd2f8adac10e..4c04ab095de3 100644 --- a/packages/Doctrine/src/Rector/ClassMethod/ChangeSetIdTypeToUuidRector.php +++ b/packages/Doctrine/src/Rector/ClassMethod/ChangeSetIdTypeToUuidRector.php @@ -48,7 +48,7 @@ public function refactor(Node $node): ?Node $this->renameUuidVariableToId($node); // is already set? - if ($node->params[0]->type) { + if ($node->params[0]->type !== null) { $currentType = $this->getName($node->params[0]->type); if ($currentType === UuidInterface::class) { return null; diff --git a/packages/PHPUnit/src/Rector/ClassMethod/AddDoesNotPerformAssertionToNonAssertingTestRector.php b/packages/PHPUnit/src/Rector/ClassMethod/AddDoesNotPerformAssertionToNonAssertingTestRector.php index 06fa1e311d31..28e28b5ce804 100644 --- a/packages/PHPUnit/src/Rector/ClassMethod/AddDoesNotPerformAssertionToNonAssertingTestRector.php +++ b/packages/PHPUnit/src/Rector/ClassMethod/AddDoesNotPerformAssertionToNonAssertingTestRector.php @@ -266,7 +266,7 @@ private function findClassMethodByParsingReflection(Node $node): ?ClassMethod } $fileName = $reflectionMethod->getFileName(); - if ($fileName === false || ! file_exists($fileName)) { + if (! $fileName || ! file_exists($fileName)) { return null; } diff --git a/packages/RemovingStatic/src/UniqueObjectFactoryFactory.php b/packages/RemovingStatic/src/UniqueObjectFactoryFactory.php index 9e561ff618ad..43b8272d1c47 100644 --- a/packages/RemovingStatic/src/UniqueObjectFactoryFactory.php +++ b/packages/RemovingStatic/src/UniqueObjectFactoryFactory.php @@ -128,7 +128,7 @@ private function createConstructMethod(ObjectType $objectType): ClassMethod $paramBuilder = $this->builderFactory->param($propertyName); $typeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($objectType); - if ($typeNode) { + if ($typeNode !== null) { $paramBuilder->setType($typeNode); } diff --git a/packages/Symfony/src/Rector/BinaryOp/ResponseStatusCodeRector.php b/packages/Symfony/src/Rector/BinaryOp/ResponseStatusCodeRector.php index 6a00f5b8198c..6c90f34076cd 100644 --- a/packages/Symfony/src/Rector/BinaryOp/ResponseStatusCodeRector.php +++ b/packages/Symfony/src/Rector/BinaryOp/ResponseStatusCodeRector.php @@ -25,7 +25,7 @@ final class ResponseStatusCodeRector extends AbstractRector private const RESPONSE_CLASS = 'Symfony\Component\HttpFoundation\Response'; /** - * @var array + * @var string[] */ private const CODE_TO_CONST = [ 100 => 'HTTP_CONTINUE', diff --git a/packages/Symfony/src/Rector/Console/ConsoleExecuteReturnIntRector.php b/packages/Symfony/src/Rector/Console/ConsoleExecuteReturnIntRector.php index 7ff863b5c22e..36bdbf2761de 100644 --- a/packages/Symfony/src/Rector/Console/ConsoleExecuteReturnIntRector.php +++ b/packages/Symfony/src/Rector/Console/ConsoleExecuteReturnIntRector.php @@ -87,7 +87,7 @@ public function refactor(Node $node): ?Node private function refactorReturnTypeDeclaration(ClassMethod $classMethod): void { - if ($classMethod->returnType) { + if ($classMethod->returnType !== null) { // already set if ($this->isName($classMethod->returnType, 'int')) { return; diff --git a/packages/Symfony/src/Rector/MethodCall/FormTypeInstanceToClassConstRector.php b/packages/Symfony/src/Rector/MethodCall/FormTypeInstanceToClassConstRector.php index c05771a08587..53ad77453dbf 100644 --- a/packages/Symfony/src/Rector/MethodCall/FormTypeInstanceToClassConstRector.php +++ b/packages/Symfony/src/Rector/MethodCall/FormTypeInstanceToClassConstRector.php @@ -234,10 +234,12 @@ private function addBuildFormMethod(Class_ $classNode, ClassMethod $classMethod) $formBuilderParamBuilder = $this->builderFactory->param('builder'); $formBuilderParamBuilder->setType(new FullyQualified(FormBuilderInterface::class)); + $formBuilderParam = $formBuilderParamBuilder->getNode(); $optionsParamBuilder = $this->builderFactory->param('options'); $optionsParamBuilder->setType('array'); + $optionsParam = $optionsParamBuilder->getNode(); $buildFormClassMethodBuilder = $this->builderFactory->method('buildForm'); @@ -266,6 +268,7 @@ private function addConfigureOptionsMethod(Class_ $classNode, array $namesToArgs $resolverParamBuilder = $this->builderFactory->param('resolver'); $resolverParamBuilder->setType(new FullyQualified(OptionsResolver::class)); + $resolverParam = $resolverParamBuilder->getNode(); $optionsDefaults = new Array_(); @@ -282,6 +285,7 @@ private function addConfigureOptionsMethod(Class_ $classNode, array $namesToArgs $configureOptionsClassMethodBuilder->makePublic(); $configureOptionsClassMethodBuilder->addParam($resolverParam); $configureOptionsClassMethodBuilder->addStmt($setDefaultsMethodCall); + $configureOptionsClassMethod = $configureOptionsClassMethodBuilder->getNode(); $classNode->stmts[] = $configureOptionsClassMethod; diff --git a/packages/SymfonyPHPUnit/src/Node/KernelTestCaseNodeFactory.php b/packages/SymfonyPHPUnit/src/Node/KernelTestCaseNodeFactory.php index a496542e3e75..c56016f8a294 100644 --- a/packages/SymfonyPHPUnit/src/Node/KernelTestCaseNodeFactory.php +++ b/packages/SymfonyPHPUnit/src/Node/KernelTestCaseNodeFactory.php @@ -76,6 +76,7 @@ public function createSetUpClassMethodWithGetTypes(Class_ $class, array $service $classMethodBuilder = $this->builderFactory->method('setUp'); $classMethodBuilder->makeProtected(); $classMethodBuilder->addStmts($stmts); + $classMethod = $classMethodBuilder->getNode(); $this->phpUnitTypeDeclarationDecorator->decorate($classMethod); diff --git a/packages/TypeDeclaration/src/Rector/Closure/AddClosureReturnTypeRector.php b/packages/TypeDeclaration/src/Rector/Closure/AddClosureReturnTypeRector.php index c8c82e252ed0..236e47252112 100644 --- a/packages/TypeDeclaration/src/Rector/Closure/AddClosureReturnTypeRector.php +++ b/packages/TypeDeclaration/src/Rector/Closure/AddClosureReturnTypeRector.php @@ -77,7 +77,7 @@ public function refactor(Node $node): ?Node return null; } - if ($node->returnType) { + if ($node->returnType !== null) { return null; } diff --git a/packages/TypeDeclaration/src/Rector/FunctionLike/ReturnTypeDeclarationRector.php b/packages/TypeDeclaration/src/Rector/FunctionLike/ReturnTypeDeclarationRector.php index 599e7b7b8a67..686187cfc7ae 100644 --- a/packages/TypeDeclaration/src/Rector/FunctionLike/ReturnTypeDeclarationRector.php +++ b/packages/TypeDeclaration/src/Rector/FunctionLike/ReturnTypeDeclarationRector.php @@ -168,7 +168,7 @@ public function refactor(Node $node): ?Node private function shouldSkip(Node $node): bool { if (! $this->overrideExistingReturnTypes) { - if ($node->returnType) { + if ($node->returnType !== null) { return true; } } diff --git a/packages/TypeDeclaration/src/TypeInferer/PropertyTypeInferer/ConstructorPropertyTypeInferer.php b/packages/TypeDeclaration/src/TypeInferer/PropertyTypeInferer/ConstructorPropertyTypeInferer.php index 1fc251202c3d..20151f023b42 100644 --- a/packages/TypeDeclaration/src/TypeInferer/PropertyTypeInferer/ConstructorPropertyTypeInferer.php +++ b/packages/TypeDeclaration/src/TypeInferer/PropertyTypeInferer/ConstructorPropertyTypeInferer.php @@ -50,7 +50,7 @@ public function inferProperty(Property $property): Type } // A. infer from type declaration of parameter - if ($param->type) { + if ($param->type !== null) { $type = $this->resolveParamTypeToPHPStanType($param); if ($type instanceof MixedType) { return new MixedType(); diff --git a/packages/TypeDeclaration/tests/Rector/Property/PropertyTypeDeclarationRector/PropertyTypeDeclarationRectorTest.php b/packages/TypeDeclaration/tests/Rector/Property/PropertyTypeDeclarationRector/PropertyTypeDeclarationRectorTest.php index 5caa90e775c1..4dcd95c2bc5f 100644 --- a/packages/TypeDeclaration/tests/Rector/Property/PropertyTypeDeclarationRector/PropertyTypeDeclarationRectorTest.php +++ b/packages/TypeDeclaration/tests/Rector/Property/PropertyTypeDeclarationRector/PropertyTypeDeclarationRectorTest.php @@ -20,24 +20,7 @@ public function test(string $file): void public function provideDataForTest(): Iterator { - yield [__DIR__ . '/Fixture/constructor_param.php.inc']; - yield [__DIR__ . '/Fixture/constructor_param_with_aliased_param.php.inc']; - yield [__DIR__ . '/Fixture/complex.php.inc']; - yield [__DIR__ . '/Fixture/single_nullable_return.php.inc']; - yield [__DIR__ . '/Fixture/getter_type.php.inc']; - yield [__DIR__ . '/Fixture/getter_type_from_var_doc.php.inc']; - yield [__DIR__ . '/Fixture/constructor_param_with_nullable.php.inc']; - yield [__DIR__ . '/Fixture/constructor_array_param_with_nullable.php.inc']; - yield [__DIR__ . '/Fixture/constructor_assign.php.inc']; - yield [__DIR__ . '/Fixture/phpunit_setup.php.inc']; - yield [__DIR__ . '/Fixture/default_value.php.inc']; - yield [__DIR__ . '/Fixture/doctrine_column.php.inc']; - yield [__DIR__ . '/Fixture/doctrine_relation_to_many.php.inc']; - yield [__DIR__ . '/Fixture/doctrine_relation_to_one.php.inc']; - yield [__DIR__ . '/Fixture/doctrine_relation_target_entity_same_namespace.php.inc']; - yield [__DIR__ . '/Fixture/setter_type.php.inc']; - yield [__DIR__ . '/Fixture/skip_multi_vars.php.inc']; - yield [__DIR__ . '/Fixture/skip_anonymous_class.php.inc']; + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); } protected function getRectorClass(): string diff --git a/phpstan.neon b/phpstan.neon index 32ef2844a0ac..b3b2b72375ff 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -212,3 +212,5 @@ parameters: # wrong deduction - '#Method Rector\\DeadCode\\Rector\\Stmt\\RemoveDeadStmtRector\:\:keepLivingCodeFromExpr\(\) should return array but returns array#' + - '#Parameter \#1 \$unversionedSets of method Rector\\Bootstrap\\SetOptionResolver\:\:createSetListInString\(\) expects array, array\|string\> given#' + - '#Parameter \#2 \$versionedSets of method Rector\\Bootstrap\\SetOptionResolver\:\:createSetListInString\(\) expects array\>, array\|string\> given#' diff --git a/rector-ci.yaml b/rector-ci.yaml index 93da7708e3a4..3022275af16c 100644 --- a/rector-ci.yaml +++ b/rector-ci.yaml @@ -1,10 +1,16 @@ parameters: sets: - - "code-quality" - - "dead-code" - - "nette-utils-code-quality" + - 'coding-style' +# - 'code-quality' +# - 'dead-code' +# - 'nette-utils-code-quality' exclude_paths: - - "/Fixture/" - - "/Source/" - - "/Expected/" + - '/Fixture/' + - '/Source/' + - '/Expected/' + + exclude_rectors: + # @todo needs to check for "autoload-dev" local dependency + - 'Rector\Php55\Rector\String_\StringClassNameToClassConstantRector' + - 'Rector\CodingStyle\Rector\String_\SplitStringClassConstantToClassConstFetchRector' diff --git a/src/Bootstrap/SetOptionResolver.php b/src/Bootstrap/SetOptionResolver.php index 62b9219e45a3..f031a3715573 100644 --- a/src/Bootstrap/SetOptionResolver.php +++ b/src/Bootstrap/SetOptionResolver.php @@ -106,6 +106,8 @@ private function reportSetNotFound(string $configDirectory, string $setName): vo [$versionedSets, $unversionedSets] = $this->separateVersionedAndUnversionedSets($allSets); + /** @var string[] $unversionedSets */ + /** @var string[][] $versionedSets */ $setsListInString = $this->createSetListInString($unversionedSets, $versionedSets); $setNotFoundMessage = sprintf( @@ -153,7 +155,7 @@ private function findAllSetsInDirectory(string $configDirectory): array /** * @param string[] $allSets - * @return string[][] + * @return string[][]|string[][][] */ private function separateVersionedAndUnversionedSets(array $allSets): array { @@ -181,7 +183,7 @@ private function separateVersionedAndUnversionedSets(array $allSets): array /** * @param string[] $unversionedSets - * @param string[] $versionedSets + * @param string[][] $versionedSets */ private function createSetListInString(array $unversionedSets, array $versionedSets): string { @@ -191,8 +193,8 @@ private function createSetListInString(array $unversionedSets, array $versionedS $setsListInString .= ' * ' . $unversionedSet . PHP_EOL; } - foreach ($versionedSets as $groupName => $configName) { - $setsListInString .= ' * ' . $groupName . ': ' . implode(', ', $configName) . PHP_EOL; + foreach ($versionedSets as $groupName => $configNames) { + $setsListInString .= ' * ' . $groupName . ': ' . implode(', ', $configNames) . PHP_EOL; } return $setsListInString; diff --git a/src/PhpParser/BetterNodeDumper.php b/src/PhpParser/BetterNodeDumper.php index c2c6db765a1b..e496dfb2b478 100644 --- a/src/PhpParser/BetterNodeDumper.php +++ b/src/PhpParser/BetterNodeDumper.php @@ -180,7 +180,7 @@ private function dumpArray(array $node): string if ($value === null) { $r .= 'null'; - } elseif ($value === false) { + } elseif (!$value) { $r .= 'false'; } elseif ($value === true) { $r .= 'true'; diff --git a/src/PhpParser/Node/NodeFactory.php b/src/PhpParser/Node/NodeFactory.php index 42d5bdf8e1cf..4aa631649436 100644 --- a/src/PhpParser/Node/NodeFactory.php +++ b/src/PhpParser/Node/NodeFactory.php @@ -150,7 +150,7 @@ public function createParamFromNameAndType(string $name, Type $type): Param $paramBuild = $this->builderFactory->param($name); $typeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($type); - if ($typeNode) { + if ($typeNode !== null) { $paramBuild->setType($typeNode); } diff --git a/src/PhpParser/Node/Value/ValueResolver.php b/src/PhpParser/Node/Value/ValueResolver.php index dbb17bcabf5b..859bf17d6058 100644 --- a/src/PhpParser/Node/Value/ValueResolver.php +++ b/src/PhpParser/Node/Value/ValueResolver.php @@ -109,7 +109,10 @@ private function getConstExprEvaluator(): ConstExprEvaluator return $this->resolveClassConstFetch($expr); } - throw new ConstExprEvaluationException("Expression of type {$expr->getType()} cannot be evaluated"); + throw new ConstExprEvaluationException(sprintf( + 'Expression of type %s cannot be evaluated', + $expr->getType() + )); }); return $this->constExprEvaluator; diff --git a/src/Testing/PHPUnit/AbstractRectorTestCase.php b/src/Testing/PHPUnit/AbstractRectorTestCase.php index d282c034067c..f39c447928ff 100644 --- a/src/Testing/PHPUnit/AbstractRectorTestCase.php +++ b/src/Testing/PHPUnit/AbstractRectorTestCase.php @@ -122,7 +122,7 @@ protected function tearDown(): void } } - protected function provideEachFileInDir(string $directory): Iterator + protected function yieldFilesFromDirectory(string $directory): Iterator { $fileInfos = $this->findFilesInDirectory($directory); diff --git a/src/Util/RectorStrings.php b/src/Util/RectorStrings.php index 24855c63f544..6fdb254c3fdd 100644 --- a/src/Util/RectorStrings.php +++ b/src/Util/RectorStrings.php @@ -77,7 +77,7 @@ public static function removeSuffixes(string $value, array $suffixesToRemove): s private static function camelCaseToGlue(string $input, string $glue): string { - $matches = Strings::matchAll($input, '!([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!'); + $matches = Strings::matchAll($input, '#([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)#'); $parts = []; foreach ($matches as $match) {