From 2ea0fa8fdac88700d1a8d0a3c88a8923897ee077 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 30 Jun 2024 18:55:50 +0200 Subject: [PATCH] add file path to tests --- .../Fixture/skip_union_types_on_php74.php.inc | 23 --------- .../FixturePhp80/multiple_union_types.php.inc | 51 ------------------- .../FixturePhp80/pathinfo_return.php.inc | 2 +- .../PHPStan/ObjectTypeSpecifier.php | 1 + .../TypeAnalyzer/ReturnStrictTypeAnalyzer.php | 9 ---- .../PhpDocInfo/PhpDocInfo/PhpDocInfoTest.php | 2 + 6 files changed, 4 insertions(+), 84 deletions(-) delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/skip_union_types_on_php74.php.inc delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/FixturePhp80/multiple_union_types.php.inc diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/skip_union_types_on_php74.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/skip_union_types_on_php74.php.inc deleted file mode 100644 index c743ebf08e6..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/skip_union_types_on_php74.php.inc +++ /dev/null @@ -1,23 +0,0 @@ -getValue(); - } - - return $this->getNextValue(); - } - - private function getValue(): int|string - { - } - - private function getNextValue(): float|string - { - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/FixturePhp80/multiple_union_types.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/FixturePhp80/multiple_union_types.php.inc deleted file mode 100644 index 1771bcfe43f..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/FixturePhp80/multiple_union_types.php.inc +++ /dev/null @@ -1,51 +0,0 @@ -getValue(); - } - - return $this->getNextValue(); - } - - private function getValue(): int|string - { - } - - private function getNextValue(): float|string - { - } -} - -?> ------ -getValue(); - } - - return $this->getNextValue(); - } - - private function getValue(): int|string - { - } - - private function getNextValue(): float|string - { - } -} - -?> diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/FixturePhp80/pathinfo_return.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/FixturePhp80/pathinfo_return.php.inc index af4a16a997b..3475e981ad5 100644 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/FixturePhp80/pathinfo_return.php.inc +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/FixturePhp80/pathinfo_return.php.inc @@ -36,7 +36,7 @@ final class PathInfoReturn * * @psalm-assert-if-true =non-empty-string $filename */ - public static function extension($filename): string|array + public static function extension($filename): array|string { return pathinfo($filename, PATHINFO_EXTENSION); } diff --git a/rules/TypeDeclaration/PHPStan/ObjectTypeSpecifier.php b/rules/TypeDeclaration/PHPStan/ObjectTypeSpecifier.php index a998e930bbb..e01247eb4e6 100644 --- a/rules/TypeDeclaration/PHPStan/ObjectTypeSpecifier.php +++ b/rules/TypeDeclaration/PHPStan/ObjectTypeSpecifier.php @@ -40,6 +40,7 @@ public function narrowToFullyQualifiedOrAliasedObjectType( ?Scope $scope = null, ): FullyQualifiedObjectType | AliasedObjectType | ShortenedGenericObjectType | ShortenedObjectType | NonExistingObjectType | UnionType | MixedType { $filePath = $node->getAttribute(AttributeKey::FILE_PATH); + // $useImportsScope = $this->useImportsResolver->resolve(); $useImportScope = $this->useImportsScopeResolver->resolve($filePath); diff --git a/rules/TypeDeclaration/TypeAnalyzer/ReturnStrictTypeAnalyzer.php b/rules/TypeDeclaration/TypeAnalyzer/ReturnStrictTypeAnalyzer.php index f2e7ea21492..68de89ee46e 100644 --- a/rules/TypeDeclaration/TypeAnalyzer/ReturnStrictTypeAnalyzer.php +++ b/rules/TypeDeclaration/TypeAnalyzer/ReturnStrictTypeAnalyzer.php @@ -96,19 +96,10 @@ public function collectStrictReturnTypes(array $returns, Scope $scope): array public function resolveMethodCallReturnNode(MethodCall | StaticCall | FuncCall $call): ?Node { $returnType = $this->resolveMethodCallReturnType($call); -<<<<<<< HEAD -<<<<<<< HEAD -======= ->>>>>>> 8e47df14f2 (add union type test fixture for ReturnTypeFromStrictTypedCallRector) if (! $returnType instanceof Type) { return null; } -<<<<<<< HEAD -======= ->>>>>>> c1a7c8b301 (traverse with file path, improve CleanupUnneededNullsafeOperatorRector to use type directly isntead of node juggling) -======= ->>>>>>> 8e47df14f2 (add union type test fixture for ReturnTypeFromStrictTypedCallRector) return $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($returnType, TypeKind::RETURN); } diff --git a/tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfo/PhpDocInfoTest.php b/tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfo/PhpDocInfoTest.php index 585dc6f0f9f..a8fb983a7b8 100644 --- a/tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfo/PhpDocInfoTest.php +++ b/tests/BetterPhpDocParser/PhpDocInfo/PhpDocInfo/PhpDocInfoTest.php @@ -11,6 +11,7 @@ use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\BetterPhpDocParser\Printer\PhpDocInfoPrinter; +use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\DocBlockTagReplacer; use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider; use Rector\StaticTypeMapper\ValueObject\Type\NonExistingObjectType; @@ -96,6 +97,7 @@ private function createPhpDocInfoFromFile(string $path): ?PhpDocInfo $nop = new Nop(); $nop->setDocComment(new Doc($phpDocContent)); + $nop->setAttribute(AttributeKey::FILE_PATH, $path); return $phpDocInfoFactory->createFromNode($nop); }