From ed8ebe7755dbfe398e46d433cbd8da102a3e14d9 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Thu, 12 Dec 2024 17:32:38 +0100 Subject: [PATCH] fix class-string compare --- composer.json | 20 ---------------- phpstan.neon | 24 +------------------ .../Fixture/pass_const_fetch_arg.php | 20 ---------------- .../If_/RemoveAlwaysTrueIfConditionRector.php | 17 ++++++------- .../TypeInferer/SplArrayFixedTypeNarrower.php | 4 +--- .../ClassRenamePhpDocNodeVisitor.php | 4 ---- .../TypeComparator/TypeComparator.php | 10 -------- .../ClassNameFromObjectTypeResolver.php | 3 --- stubs/Twig/Extension/SandboxExtension.php | 12 ++++++++++ 9 files changed, 21 insertions(+), 93 deletions(-) delete mode 100644 rules-tests/Php81/Rector/ClassMethod/NewInInitializerRector/Fixture/pass_const_fetch_arg.php create mode 100644 stubs/Twig/Extension/SandboxExtension.php diff --git a/composer.json b/composer.json index 8c97974b7c9..79f57b46c09 100644 --- a/composer.json +++ b/composer.json @@ -50,37 +50,17 @@ "phpstan/phpstan-webmozart-assert": "^2.0", "phpunit/phpunit": "^11.5", "rector/release-notes-generator": "^0.3.0", -<<<<<<< HEAD -<<<<<<< HEAD "rector/swiss-knife": "^2.0", -======= -<<<<<<< HEAD - "rector/swiss-knife": "^0.2.16", ->>>>>>> 7745041b3b (restore dev static analysis tools) "rector/type-perfect": "^2.0", "shipmonk/composer-dependency-analyser": "^1.8", "symplify/easy-coding-standard": "^12.5", "symplify/phpstan-extensions": "^12.0", -<<<<<<< HEAD - "symplify/phpstan-rules": "^14.0", "symplify/rule-doc-generator": "^12.2.5", "symplify/vendor-patches": "^11.3", "tomasvotruba/class-leak": "^2.0", -======= -======= - "rector/type-perfect": "^2.0", ->>>>>>> d8ba100b89 (bump deps) "symplify/phpstan-rules": "^14.0.2", - "rector/swiss-knife": "^2.0", - "shipmonk/composer-dependency-analyser": "^1.8", - "symplify/easy-coding-standard": "^12.4", - "symplify/phpstan-extensions": "^12.0", - "symplify/rule-doc-generator": "^12.2", - "symplify/vendor-patches": "^11.3", - "tomasvotruba/class-leak": "^2.0", "tomasvotruba/type-coverage": "^2.0", "tomasvotruba/unused-public": "^2.0", ->>>>>>> 7745041b3b (restore dev static analysis tools) "tracy/tracy": "^2.9" }, "replace": { diff --git a/phpstan.neon b/phpstan.neon index 2d542ab2e14..944b545269a 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -5,20 +5,7 @@ includes: parameters: level: 8 errorFormat: symplify -<<<<<<< HEAD - -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> 4e3ac08b3c (fix few reported static errors) - reportUnmatchedIgnoredErrors: false - errorFormat: symplify -======= - # reportUnmatchedIgnoredErrors: false ->>>>>>> 7a1a2b4658 (cleanup fixed phpstan errors) -======= reportUnmatchedIgnoredErrors: false ->>>>>>> 95bce6d377 (use config param to set error format) # requires exact closure types checkMissingCallableSignature: true @@ -323,7 +310,6 @@ parameters: - '#Method Rector\\.*::providePolyfillPackage\(\) never returns#' - '#Method Rector\\.*::filterPolyfillPackages\(\) should return array\<#' -<<<<<<< HEAD - identifier: typePerfect.noMixedMethodCaller paths: @@ -332,14 +318,11 @@ parameters: - path: src/NodeTypeResolver/PHPStan/Type/TypeFactory.php message: '#Method Rector\\NodeTypeResolver\\PHPStan\\Type\\TypeFactory\:\:uniquateTypes\(\) should return array but returns list#' -======= + # collection of Type - message: '#Method Rector\\NodeTypeResolver\\PHPStan\\Type\\TypeFactory::uniquateTypes\(\) should return array\ but returns list\#' path: src/NodeTypeResolver/PHPStan/Type/TypeFactory.php -<<<<<<< HEAD ->>>>>>> 7a1a2b4658 (cleanup fixed phpstan errors) -======= # known native PHP type - @@ -355,12 +338,7 @@ parameters: - message: '#Possibly invalid array key type array\|PHPStan\\PhpDocParser\\Ast\\ConstExpr\\ConstExprNode\|Rector\\BetterPhpDocParser\\PhpDoc\\DoctrineAnnotationTagValueNode\|Rector\\BetterPhpDocParser\\PhpDoc\\StringNode\|Rector\\BetterPhpDocParser\\ValueObject\\PhpDoc\\DoctrineAnnotation\\CurlyListNode\|string#' path: src/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser.php -<<<<<<< HEAD ->>>>>>> 4e3ac08b3c (fix few reported static errors) -======= # overly detailed - '#expects (non\-empty\-string|class-string), string given#' - '#expects list<(.*?)>, array<(.*?)> given#' - ->>>>>>> e70cfd86c4 (add few static fixes) diff --git a/rules-tests/Php81/Rector/ClassMethod/NewInInitializerRector/Fixture/pass_const_fetch_arg.php b/rules-tests/Php81/Rector/ClassMethod/NewInInitializerRector/Fixture/pass_const_fetch_arg.php deleted file mode 100644 index 8b78d8ea9d2..00000000000 --- a/rules-tests/Php81/Rector/ClassMethod/NewInInitializerRector/Fixture/pass_const_fetch_arg.php +++ /dev/null @@ -1,20 +0,0 @@ -dateTime = $dateTime ?? new DateTime(NOW); - } -} - -?> diff --git a/rules/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector.php b/rules/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector.php index f4b74f71ec6..e45b33d1d7a 100644 --- a/rules/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector.php +++ b/rules/DeadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector.php @@ -148,16 +148,13 @@ private function shouldSkipFromVariable(Expr $expr): bool private function shouldSkipExpr(Expr $expr): bool { - return (bool) $this->betterNodeFinder->findInstancesOf( - $expr, - [ - PropertyFetch::class, - StaticPropertyFetch::class, - ArrayDimFetch::class, - MethodCall::class, - StaticCall::class, - ] - ); + return (bool) $this->betterNodeFinder->findInstancesOf($expr, [ + PropertyFetch::class, + StaticPropertyFetch::class, + ArrayDimFetch::class, + MethodCall::class, + StaticCall::class, + ]); } private function refactorIfWithBooleanAnd(If_ $if): ?If_ diff --git a/rules/TypeDeclaration/TypeInferer/SplArrayFixedTypeNarrower.php b/rules/TypeDeclaration/TypeInferer/SplArrayFixedTypeNarrower.php index b9a46e0654b..3d9c988f7cb 100644 --- a/rules/TypeDeclaration/TypeInferer/SplArrayFixedTypeNarrower.php +++ b/rules/TypeDeclaration/TypeInferer/SplArrayFixedTypeNarrower.php @@ -30,9 +30,7 @@ public function narrow(Type $paramType): Type if ($className === 'PhpCsFixer\Tokenizer\Tokens') { $types[] = new ObjectType('PhpCsFixer\Tokenizer\Token'); - } - - if ($className === 'PhpCsFixer\Doctrine\Annotation\Tokens') { + } elseif ($className === 'PhpCsFixer\Doctrine\Annotation\Tokens') { $types[] = new ObjectType('PhpCsFixer\Doctrine\Annotation\Token'); } diff --git a/src/NodeTypeResolver/PhpDocNodeVisitor/ClassRenamePhpDocNodeVisitor.php b/src/NodeTypeResolver/PhpDocNodeVisitor/ClassRenamePhpDocNodeVisitor.php index 30d9c55ea10..4551416fd66 100644 --- a/src/NodeTypeResolver/PhpDocNodeVisitor/ClassRenamePhpDocNodeVisitor.php +++ b/src/NodeTypeResolver/PhpDocNodeVisitor/ClassRenamePhpDocNodeVisitor.php @@ -74,15 +74,11 @@ public function enterNode(Node $node): ?Node foreach ($this->oldToNewTypes as $oldToNewType) { $oldType = $oldToNewType->getOldType(); -<<<<<<< HEAD if (! $oldType instanceof ObjectType) { continue; } if (! $objectType->equals($oldType)) { -======= - if (! $oldType instanceof ObjectType || ! $objectType->equals($oldType)) { ->>>>>>> e07c5f96d4 (add few static fixes) continue; } diff --git a/src/NodeTypeResolver/TypeComparator/TypeComparator.php b/src/NodeTypeResolver/TypeComparator/TypeComparator.php index 1778d833593..1961ee5e1ad 100644 --- a/src/NodeTypeResolver/TypeComparator/TypeComparator.php +++ b/src/NodeTypeResolver/TypeComparator/TypeComparator.php @@ -26,10 +26,6 @@ { public function __construct( private TypeHasher $typeHasher, -<<<<<<< HEAD -======= - // private TypeNormalizer $typeNormalizer, ->>>>>>> e07c5f96d4 (add few static fixes) private StaticTypeMapper $staticTypeMapper, private ArrayTypeComparator $arrayTypeComparator, private ScalarTypeComparator $scalarTypeComparator, @@ -58,12 +54,6 @@ public function areTypesEqual(Type $firstType, Type $secondType): bool return true; } -<<<<<<< HEAD -======= - // $firstType = $this->typeNormalizer->normalizeArrayOfUnionToUnionArray($firstType); - // $secondType = $this->typeNormalizer->normalizeArrayOfUnionToUnionArray($secondType); - ->>>>>>> e07c5f96d4 (add few static fixes) if ($this->typeHasher->areTypesEqual($firstType, $secondType)) { return true; } diff --git a/src/StaticTypeMapper/Resolver/ClassNameFromObjectTypeResolver.php b/src/StaticTypeMapper/Resolver/ClassNameFromObjectTypeResolver.php index 51caefb5476..935f0971d5a 100644 --- a/src/StaticTypeMapper/Resolver/ClassNameFromObjectTypeResolver.php +++ b/src/StaticTypeMapper/Resolver/ClassNameFromObjectTypeResolver.php @@ -8,9 +8,6 @@ final class ClassNameFromObjectTypeResolver { - /** - * @return class-string|null - */ public static function resolve(Type $type): ?string { /** @var array $objectClassNames */ diff --git a/stubs/Twig/Extension/SandboxExtension.php b/stubs/Twig/Extension/SandboxExtension.php new file mode 100644 index 00000000000..743035ccd23 --- /dev/null +++ b/stubs/Twig/Extension/SandboxExtension.php @@ -0,0 +1,12 @@ +