From 55de46a19a0311b598aa7c6c75237992cbb17580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaroslav=20Hansl=C3=ADk?= Date: Fri, 15 Nov 2024 20:11:27 +0100 Subject: [PATCH] Update dependency phpstan/phpstan to v2 --- phpstan.neon | 19 ++++++---- src/Reflection/Adapter/ReflectionClass.php | 4 +-- src/Reflection/Adapter/ReflectionEnum.php | 4 +-- .../Adapter/ReflectionEnumBackedCase.php | 2 +- .../Adapter/ReflectionEnumUnitCase.php | 2 +- src/Reflection/Adapter/ReflectionFunction.php | 4 +-- src/Reflection/Adapter/ReflectionMethod.php | 1 + src/Reflection/Adapter/ReflectionObject.php | 4 +-- .../Adapter/ReflectionParameter.php | 3 +- src/Reflection/ReflectionAttribute.php | 7 ++-- src/Reflection/ReflectionClass.php | 18 ++++++---- src/Reflection/ReflectionConstant.php | 4 ++- src/Reflection/ReflectionMethod.php | 5 ++- src/Reflection/ReflectionProperty.php | 6 +++- .../SourceStubber/ReflectionSourceStubber.php | 20 +++++------ .../AnonymousClassObjectSourceLocator.php | 2 -- .../Type/AutoloadSourceLocator.php | 10 ++++-- .../Type/Composer/Psr/Psr4Mapping.php | 4 +-- .../Type/EvaledCodeSourceLocator.php | 1 - .../Type/FileIteratorSourceLocator.php | 1 + src/Util/ClassExistenceChecker.php | 2 +- src/Util/FileHelper.php | 3 ++ test/unit/BetterReflectionSingleton.php | 2 +- .../NodeCompiler/CompileNodeToValueTest.php | 4 +-- .../Adapter/ReflectionClassConstantTest.php | 2 +- .../Adapter/ReflectionClassTest.php | 2 +- .../Adapter/ReflectionEnumBackedCaseTest.php | 2 +- .../Reflection/Adapter/ReflectionEnumTest.php | 2 +- .../Adapter/ReflectionEnumUnitCaseTest.php | 2 +- .../Adapter/ReflectionFunctionTest.php | 2 +- .../Adapter/ReflectionMethodTest.php | 2 +- .../Adapter/ReflectionObjectTest.php | 2 +- .../Adapter/ReflectionParameterTest.php | 2 +- .../Adapter/ReflectionPropertyTest.php | 2 +- test/unit/Reflection/ReflectionClassTest.php | 11 +++--- test/unit/Reflection/ReflectionObjectTest.php | 22 ++++++------ .../ReflectionClassStringCastTest.php | 2 +- .../ReflectionSourceStubberTest.php | 33 +++++------------ .../AnonymousClassObjectSourceLocatorTest.php | 2 +- .../FileReadTrapStreamWrapperTest.php | 20 ++++++----- .../Type/AutoloadSourceLocatorTest.php | 4 ++- .../Type/ClosureSourceLocatorTest.php | 4 +-- .../Type/FileIteratorSourceLocatorTest.php | 2 +- tools/composer.json | 4 +-- tools/composer.lock | 35 +++++++++---------- 45 files changed, 152 insertions(+), 139 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index 3d5de173f..e94b5da0e 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -25,12 +25,19 @@ parameters: - phar://%currentWorkingDirectory%/test/unit/Fixture/autoload.phar/vendor/autoload.php ignoreErrors: - # Impossible to define type hint for anonymous class - - message: '#Call to an undefined method PhpParser\\NodeVisitorAbstract::(getNode|setConstantName)\(\)#' - path: src/SourceLocator/Type/AutoloadSourceLocator.php + identifier: missingType.generics - - message: '#Method Roave\\BetterReflection\\Reflection\\ReflectionClass::computeModifiers\(\) never returns \d+ so it can be removed from the return type#' - path: src/Reflection/ReflectionClass.php + identifier: possiblyImpure.functionCall - - identifier: missingType.generics + identifier: possiblyImpure.methodCall + - + identifier: possiblyImpure.new + - + identifier: property.readOnlyByPhpDocAssignNotInConstructor + - + identifier: staticMethod.alreadyNarrowedType + path: test/unit/ + - + identifier: varTag.nativeType + path: test/unit/ diff --git a/src/Reflection/Adapter/ReflectionClass.php b/src/Reflection/Adapter/ReflectionClass.php index 2ef80f677..64bbe2ed5 100644 --- a/src/Reflection/Adapter/ReflectionClass.php +++ b/src/Reflection/Adapter/ReflectionClass.php @@ -102,13 +102,13 @@ public function getFileName(): string|false } /** @psalm-mutation-free */ - public function getStartLine(): int|false + public function getStartLine(): int { return $this->betterReflectionClass->getStartLine(); } /** @psalm-mutation-free */ - public function getEndLine(): int|false + public function getEndLine(): int { return $this->betterReflectionClass->getEndLine(); } diff --git a/src/Reflection/Adapter/ReflectionEnum.php b/src/Reflection/Adapter/ReflectionEnum.php index c02a88555..4b475ec79 100644 --- a/src/Reflection/Adapter/ReflectionEnum.php +++ b/src/Reflection/Adapter/ReflectionEnum.php @@ -91,12 +91,12 @@ public function getFileName(): string|false return $fileName !== null ? FileHelper::normalizeSystemPath($fileName) : false; } - public function getStartLine(): int|false + public function getStartLine(): int { return $this->betterReflectionEnum->getStartLine(); } - public function getEndLine(): int|false + public function getEndLine(): int { return $this->betterReflectionEnum->getEndLine(); } diff --git a/src/Reflection/Adapter/ReflectionEnumBackedCase.php b/src/Reflection/Adapter/ReflectionEnumBackedCase.php index c3d87365a..47e3aebcd 100644 --- a/src/Reflection/Adapter/ReflectionEnumBackedCase.php +++ b/src/Reflection/Adapter/ReflectionEnumBackedCase.php @@ -40,7 +40,7 @@ public function hasType(): bool return false; } - public function getType(): ReflectionUnionType|ReflectionNamedType|ReflectionIntersectionType|null + public function getType(): null { return null; } diff --git a/src/Reflection/Adapter/ReflectionEnumUnitCase.php b/src/Reflection/Adapter/ReflectionEnumUnitCase.php index 0eee696d6..f905812fc 100644 --- a/src/Reflection/Adapter/ReflectionEnumUnitCase.php +++ b/src/Reflection/Adapter/ReflectionEnumUnitCase.php @@ -40,7 +40,7 @@ public function hasType(): bool return false; } - public function getType(): ReflectionUnionType|ReflectionNamedType|ReflectionIntersectionType|null + public function getType(): null { return null; } diff --git a/src/Reflection/Adapter/ReflectionFunction.php b/src/Reflection/Adapter/ReflectionFunction.php index 8084f2a15..94a6b70a5 100644 --- a/src/Reflection/Adapter/ReflectionFunction.php +++ b/src/Reflection/Adapter/ReflectionFunction.php @@ -95,13 +95,13 @@ public function getDocComment(): string|false } /** @psalm-mutation-free */ - public function getStartLine(): int|false + public function getStartLine(): int { return $this->betterReflectionFunction->getStartLine(); } /** @psalm-mutation-free */ - public function getEndLine(): int|false + public function getEndLine(): int { return $this->betterReflectionFunction->getEndLine(); } diff --git a/src/Reflection/Adapter/ReflectionMethod.php b/src/Reflection/Adapter/ReflectionMethod.php index 18a6c9294..2d2caf45a 100644 --- a/src/Reflection/Adapter/ReflectionMethod.php +++ b/src/Reflection/Adapter/ReflectionMethod.php @@ -363,6 +363,7 @@ public function hasPrototype(): bool * @codeCoverageIgnore * @infection-ignore-all * @psalm-pure + * @phpstan-ignore pureMethod.void */ public function setAccessible(bool $accessible): void { diff --git a/src/Reflection/Adapter/ReflectionObject.php b/src/Reflection/Adapter/ReflectionObject.php index b61a1a68d..6221d013c 100644 --- a/src/Reflection/Adapter/ReflectionObject.php +++ b/src/Reflection/Adapter/ReflectionObject.php @@ -82,13 +82,13 @@ public function getFileName(): string|false } /** @psalm-mutation-free */ - public function getStartLine(): int|false + public function getStartLine(): int { return $this->betterReflectionObject->getStartLine(); } /** @psalm-mutation-free */ - public function getEndLine(): int|false + public function getEndLine(): int { return $this->betterReflectionObject->getEndLine(); } diff --git a/src/Reflection/Adapter/ReflectionParameter.php b/src/Reflection/Adapter/ReflectionParameter.php index dd2a8c0d9..9f7eafc8a 100644 --- a/src/Reflection/Adapter/ReflectionParameter.php +++ b/src/Reflection/Adapter/ReflectionParameter.php @@ -117,7 +117,7 @@ public function getClass(): CoreReflectionClass|null } try { - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore variable.undefined */ return new ReflectionClass($classType->getClass()); } catch (LogicException) { return null; @@ -217,6 +217,7 @@ public function hasType(): bool return $this->betterReflectionParameter->hasType(); } + /** @phpstan-ignore return.unusedType */ public function getType(): ReflectionNamedType|ReflectionUnionType|ReflectionIntersectionType|ReflectionType|null { return ReflectionType::fromTypeOrNull($this->betterReflectionParameter->getType()); diff --git a/src/Reflection/ReflectionAttribute.php b/src/Reflection/ReflectionAttribute.php index 70625f992..22d15c6cb 100644 --- a/src/Reflection/ReflectionAttribute.php +++ b/src/Reflection/ReflectionAttribute.php @@ -20,7 +20,7 @@ class ReflectionAttribute private string $name; /** @var array */ - private array $arguments = []; + private array $arguments; /** @internal */ public function __construct( @@ -31,9 +31,12 @@ public function __construct( ) { $this->name = $node->name->toString(); + $arguments = []; foreach ($node->args as $argNo => $arg) { - $this->arguments[$arg->name?->toString() ?? $argNo] = $arg->value; + $arguments[$arg->name?->toString() ?? $argNo] = $arg->value; } + + $this->arguments = $arguments; } /** @internal */ diff --git a/src/Reflection/ReflectionClass.php b/src/Reflection/ReflectionClass.php index c4d8cf23e..111a26b51 100644 --- a/src/Reflection/ReflectionClass.php +++ b/src/Reflection/ReflectionClass.php @@ -162,19 +162,19 @@ protected function __construct( private LocatedSource $locatedSource, private string|null $namespace = null, ) { - $this->name = null; - $this->shortName = null; + $name = null; + $shortName = null; + if ($node->name instanceof Node\Identifier) { $namespacedName = $node->namespacedName; assert($namespacedName instanceof Node\Name); /** @psalm-var class-string|trait-string */ $name = $namespacedName->toString(); $shortName = $node->name->name; - - $this->name = $name; - $this->shortName = $shortName; } + $this->name = $name; + $this->shortName = $shortName; $this->isInterface = $node instanceof InterfaceNode; $this->isTrait = $node instanceof TraitNode; $this->isEnum = $node instanceof EnumNode; @@ -380,7 +380,7 @@ private function createMethodsFromTrait(ReflectionMethod $method): array $createMethod = function (string|null $aliasMethodName) use ($method, $methodModifiers): ReflectionMethod { assert($aliasMethodName === null || $aliasMethodName !== ''); - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore argument.type */ return $method->withImplementingClass($this, $aliasMethodName, $methodModifiers); }; @@ -1229,7 +1229,11 @@ public function getModifiers(): int return $this->modifiers; } - /** @return int-mask-of */ + /** + * @return int-mask-of + * + * @phpstan-ignore-next-line return.unusedType + */ private function computeModifiers(ClassNode|InterfaceNode|TraitNode|EnumNode $node): int { if (! $node instanceof ClassNode) { diff --git a/src/Reflection/ReflectionConstant.php b/src/Reflection/ReflectionConstant.php index 617fdbcd5..8a3ad091e 100644 --- a/src/Reflection/ReflectionConstant.php +++ b/src/Reflection/ReflectionConstant.php @@ -325,7 +325,9 @@ private function setNamesFromNode(Node\Stmt\Const_|Node\Expr\FuncCall $node, int $shortName = $constNode->name->name; } - $this->name = $name; + /** @phpstan-ignore assign.readOnlyPropertyByPhpDoc */ + $this->name = $name; + /** @phpstan-ignore assign.readOnlyPropertyByPhpDoc */ $this->shortName = $shortName; } diff --git a/src/Reflection/ReflectionMethod.php b/src/Reflection/ReflectionMethod.php index f33528150..19ac618ed 100644 --- a/src/Reflection/ReflectionMethod.php +++ b/src/Reflection/ReflectionMethod.php @@ -151,7 +151,8 @@ public function withImplementingClass(ReflectionClass $implementingClass, string /** @internal */ public function withCurrentClass(ReflectionClass $currentClass): self { - $clone = clone $this; + $clone = clone $this; + /** @phpstan-ignore property.readOnlyByPhpDocAssignNotInConstructor */ $clone->currentClass = $currentClass; if ($clone->returnType !== null) { @@ -430,6 +431,7 @@ private function callStaticMethod(array $args): mixed /** @psalm-suppress InvalidStringClass */ $closure = Closure::bind(fn (string $implementingClassName, string $_methodName, array $methodArgs): mixed => $implementingClassName::{$_methodName}(...$methodArgs), null, $implementingClassName); + /** @phpstan-ignore function.alreadyNarrowedType, instanceof.alwaysTrue */ assert($closure instanceof Closure); return $closure->__invoke($implementingClassName, $this->getName(), $args); @@ -441,6 +443,7 @@ private function callObjectMethod(object $object, array $args): mixed /** @psalm-suppress MixedMethodCall */ $closure = Closure::bind(fn (object $object, string $methodName, array $methodArgs): mixed => $object->{$methodName}(...$methodArgs), $object, $this->getImplementingClass()->getName()); + /** @phpstan-ignore function.alreadyNarrowedType, instanceof.alwaysTrue */ assert($closure instanceof Closure); return $closure->__invoke($object, $this->getName(), $args); diff --git a/src/Reflection/ReflectionProperty.php b/src/Reflection/ReflectionProperty.php index 12c8e22db..dd56af161 100644 --- a/src/Reflection/ReflectionProperty.php +++ b/src/Reflection/ReflectionProperty.php @@ -281,7 +281,7 @@ public function isInitialized(object|null $object = null): bool return true; - // @phpstan-ignore-next-line + /** @phpstan-ignore catch.neverThrown */ } catch (Error $e) { if (str_contains($e->getMessage(), 'must not be accessed before initialization')) { return false; @@ -452,6 +452,7 @@ public function getValue(object|null $object = null): mixed $closure = Closure::bind(fn (string $implementingClassName, string $propertyName): mixed => $implementingClassName::${$propertyName}, null, $implementingClassName); + /** @phpstan-ignore function.alreadyNarrowedType, instanceof.alwaysTrue */ assert($closure instanceof Closure); return $closure->__invoke($implementingClassName, $this->getName()); @@ -461,6 +462,7 @@ public function getValue(object|null $object = null): mixed $closure = Closure::bind(fn (object $instance, string $propertyName): mixed => $instance->{$propertyName}, $instance, $implementingClassName); + /** @phpstan-ignore function.alreadyNarrowedType, instanceof.alwaysTrue */ assert($closure instanceof Closure); return $closure->__invoke($instance, $this->getName()); @@ -484,6 +486,7 @@ public function setValue(mixed $object, mixed $value = null): void $_implementingClassName::${$_propertyName} = $value; }, null, $implementingClassName); + /** @phpstan-ignore function.alreadyNarrowedType, instanceof.alwaysTrue */ assert($closure instanceof Closure); $closure->__invoke($implementingClassName, $this->getName(), func_num_args() === 2 ? $value : $object); @@ -497,6 +500,7 @@ public function setValue(mixed $object, mixed $value = null): void $instance->{$propertyName} = $value; }, $instance, $implementingClassName); + /** @phpstan-ignore function.alreadyNarrowedType, instanceof.alwaysTrue */ assert($closure instanceof Closure); $closure->__invoke($instance, $this->getName(), $value); diff --git a/src/SourceLocator/SourceStubber/ReflectionSourceStubber.php b/src/SourceLocator/SourceStubber/ReflectionSourceStubber.php index def55adda..9d9e2b246 100644 --- a/src/SourceLocator/SourceStubber/ReflectionSourceStubber.php +++ b/src/SourceLocator/SourceStubber/ReflectionSourceStubber.php @@ -79,6 +79,7 @@ public function __construct() /** @param class-string|trait-string $className */ public function generateClassStub(string $className): StubData|null { + /** @phpstan-ignore staticMethod.alreadyNarrowedType */ if (! ClassExistenceChecker::exists($className)) { return null; } @@ -139,10 +140,7 @@ public function generateFunctionStub(string $functionName): StubData|null $this->addDocComment($functionNode, $functionReflection); $this->addParameters($functionNode, $functionReflection); - $returnType = $functionReflection->getReturnType(); - if ($returnType === null && method_exists($functionReflection, 'getTentativeReturnType')) { - $returnType = $functionReflection->getTentativeReturnType(); - } + $returnType = $functionReflection->getReturnType() ?? $functionReflection->getTentativeReturnType(); if ($returnType !== null) { assert($returnType instanceof CoreReflectionNamedType || $returnType instanceof CoreReflectionUnionType || $returnType instanceof CoreReflectionIntersectionType); @@ -228,7 +226,7 @@ private function addDocComment( $annotations[] = '@deprecated'; } - if (method_exists($reflection, 'hasTentativeReturnType') && $reflection->hasTentativeReturnType()) { + if ($reflection->hasTentativeReturnType()) { $annotations[] = sprintf('@%s', AnnotationHelper::TENTATIVE_RETURN_TYPE_ANNOTATION); } } @@ -253,6 +251,7 @@ private function addEnumBackingType(Enum_ $enumNode, CoreReflectionEnum $enumRef } $backingType = $enumReflection->getBackingType(); + /** @phpstan-ignore function.alreadyNarrowedType, instanceof.alwaysTrue */ assert($backingType instanceof CoreReflectionNamedType); $enumNode->setScalarType($backingType->getName()); @@ -378,7 +377,7 @@ private function isPropertyDeclaredInClass(CoreReflectionProperty $propertyRefle private function addPropertyModifiers(Property $propertyNode, CoreReflectionProperty $propertyReflection): void { - if (method_exists($propertyReflection, 'isReadOnly') && $propertyReflection->isReadOnly()) { + if ($propertyReflection->isReadOnly()) { $propertyNode->makeReadonly(); } @@ -411,7 +410,7 @@ private function addEnumCases(Enum_ $enumNode, CoreReflectionEnum $enumReflectio private function addClassConstants(Class_|Interface_|Trait_|Enum_ $classNode, CoreReflectionClass $classReflection): void { foreach ($classReflection->getReflectionConstants() as $constantReflection) { - if (method_exists($constantReflection, 'isEnumCase') && $constantReflection->isEnumCase()) { + if ($constantReflection->isEnumCase()) { continue; } @@ -442,7 +441,7 @@ private function addClassConstants(Class_|Interface_|Trait_|Enum_ $classNode, Co private function addClassConstantModifiers(ClassConst $classConstantNode, CoreReflectionClassConstant $classConstantReflection): void { - if (method_exists($classConstantReflection, 'isFinal') && $classConstantReflection->isFinal()) { + if ($classConstantReflection->isFinal()) { $classConstantNode->makeFinal(); } @@ -468,10 +467,7 @@ private function addMethods(Class_|Interface_|Trait_|Enum_ $classNode, CoreRefle $this->addDocComment($methodNode, $methodReflection); $this->addParameters($methodNode, $methodReflection); - $returnType = $methodReflection->getReturnType(); - if ($returnType === null && method_exists($methodReflection, 'getTentativeReturnType')) { - $returnType = $methodReflection->getTentativeReturnType(); - } + $returnType = $methodReflection->getReturnType() ?? $methodReflection->getTentativeReturnType(); if ($returnType !== null) { assert($returnType instanceof CoreReflectionNamedType || $returnType instanceof CoreReflectionUnionType || $returnType instanceof CoreReflectionIntersectionType); diff --git a/src/SourceLocator/Type/AnonymousClassObjectSourceLocator.php b/src/SourceLocator/Type/AnonymousClassObjectSourceLocator.php index 3ec006321..23734964b 100644 --- a/src/SourceLocator/Type/AnonymousClassObjectSourceLocator.php +++ b/src/SourceLocator/Type/AnonymousClassObjectSourceLocator.php @@ -11,7 +11,6 @@ use PhpParser\NodeVisitorAbstract; use PhpParser\Parser; use ReflectionClass as CoreReflectionClass; -use ReflectionException; use Roave\BetterReflection\Identifier\Identifier; use Roave\BetterReflection\Identifier\IdentifierType; use Roave\BetterReflection\Reflection\Reflection; @@ -36,7 +35,6 @@ final class AnonymousClassObjectSourceLocator implements SourceLocator { private CoreReflectionClass $coreClassReflection; - /** @throws ReflectionException */ public function __construct(object $anonymousClassObject, private Parser $parser) { $this->coreClassReflection = new CoreReflectionClass($anonymousClassObject); diff --git a/src/SourceLocator/Type/AutoloadSourceLocator.php b/src/SourceLocator/Type/AutoloadSourceLocator.php index 009994da7..64dd4eae8 100644 --- a/src/SourceLocator/Type/AutoloadSourceLocator.php +++ b/src/SourceLocator/Type/AutoloadSourceLocator.php @@ -246,7 +246,10 @@ private function locateConstantByName(string $constantName): array|null return null; } - /** @psalm-suppress UndefinedMethod */ + /** + * @psalm-suppress UndefinedMethod + * @phpstan-ignore method.notFound + */ $this->constantVisitor->setConstantName($constantName); $constantFileName = null; @@ -268,7 +271,10 @@ private function locateConstantByName(string $constantName): array|null $this->nodeTraverser->traverse($ast); - /** @psalm-suppress UndefinedMethod */ + /** + * @psalm-suppress UndefinedMethod + * @phpstan-ignore method.notFound + */ if ($this->constantVisitor->getNode() !== null) { $constantFileName = $includedFileName; break; diff --git a/src/SourceLocator/Type/Composer/Psr/Psr4Mapping.php b/src/SourceLocator/Type/Composer/Psr/Psr4Mapping.php index dc2707951..cbf0c8a15 100644 --- a/src/SourceLocator/Type/Composer/Psr/Psr4Mapping.php +++ b/src/SourceLocator/Type/Composer/Psr/Psr4Mapping.php @@ -59,7 +59,7 @@ public function resolvePossibleFilePaths(Identifier $identifier): array $className = $identifier->getName(); $matchingPrefixes = $this->matchingPrefixes($className); - return array_values(array_filter(array_merge( + return array_merge( [], ...array_map(static function (array $paths, string $prefix) use ($className): array { $subPath = ltrim(str_replace('\\', '/', substr($className, strlen($prefix))), '/'); @@ -70,7 +70,7 @@ public function resolvePossibleFilePaths(Identifier $identifier): array return array_map(static fn (string $path): string => $path . '/' . $subPath . '.php', $paths); }, $matchingPrefixes, array_keys($matchingPrefixes)), - ))); + ); } /** @return array> */ diff --git a/src/SourceLocator/Type/EvaledCodeSourceLocator.php b/src/SourceLocator/Type/EvaledCodeSourceLocator.php index b7b0597e9..53eec3f69 100644 --- a/src/SourceLocator/Type/EvaledCodeSourceLocator.php +++ b/src/SourceLocator/Type/EvaledCodeSourceLocator.php @@ -52,7 +52,6 @@ private function getInternalReflectionClass(Identifier $identifier): ReflectionC return null; } - /** @psalm-var class-string|trait-string $name */ $name = $identifier->getName(); if (! ClassExistenceChecker::exists($name)) { diff --git a/src/SourceLocator/Type/FileIteratorSourceLocator.php b/src/SourceLocator/Type/FileIteratorSourceLocator.php index 5f025c25f..dcd9cc0f0 100644 --- a/src/SourceLocator/Type/FileIteratorSourceLocator.php +++ b/src/SourceLocator/Type/FileIteratorSourceLocator.php @@ -40,6 +40,7 @@ class FileIteratorSourceLocator implements SourceLocator public function __construct(Iterator $fileInfoIterator, private Locator $astLocator) { foreach ($fileInfoIterator as $fileInfo) { + /** @phpstan-ignore instanceof.alwaysTrue */ if (! $fileInfo instanceof SplFileInfo) { throw InvalidFileInfo::fromNonSplFileInfo($fileInfo); } diff --git a/src/Util/ClassExistenceChecker.php b/src/Util/ClassExistenceChecker.php index 5f8ea8b6c..9974930b2 100644 --- a/src/Util/ClassExistenceChecker.php +++ b/src/Util/ClassExistenceChecker.php @@ -11,7 +11,7 @@ /** @internal */ class ClassExistenceChecker { - /** @psalm-assert-if-true class-string $name */ + /** @psalm-assert-if-true class-string|trait-string $name */ public static function exists(string $name): bool { return self::classExists($name) || self::interfaceExists($name) || self::traitExists($name); diff --git a/src/Util/FileHelper.php b/src/Util/FileHelper.php index 6277240a9..e61c184d4 100644 --- a/src/Util/FileHelper.php +++ b/src/Util/FileHelper.php @@ -23,6 +23,8 @@ class FileHelper public static function normalizeWindowsPath(string $path): string { $path = str_replace('\\', '/', $path); + + /** @phpstan-ignore function.alreadyNarrowedType, notIdentical.alwaysTrue */ assert($path !== ''); return $path; @@ -50,6 +52,7 @@ public static function normalizeSystemPath(string $originalPath): string $path = str_replace('/', DIRECTORY_SEPARATOR, $path); } + /** @phpstan-ignore function.alreadyNarrowedType, notIdentical.alwaysTrue */ assert($path !== ''); return ($scheme !== null ? sprintf('%s://', $scheme) : '') . $path; diff --git a/test/unit/BetterReflectionSingleton.php b/test/unit/BetterReflectionSingleton.php index 15c702616..1ac1b2e00 100644 --- a/test/unit/BetterReflectionSingleton.php +++ b/test/unit/BetterReflectionSingleton.php @@ -8,7 +8,7 @@ abstract class BetterReflectionSingleton { - private static BetterReflection|null $betterReflection; + private static BetterReflection $betterReflection; final private function __construct() { diff --git a/test/unit/NodeCompiler/CompileNodeToValueTest.php b/test/unit/NodeCompiler/CompileNodeToValueTest.php index 691a25eba..9f093ecfc 100644 --- a/test/unit/NodeCompiler/CompileNodeToValueTest.php +++ b/test/unit/NodeCompiler/CompileNodeToValueTest.php @@ -859,7 +859,7 @@ public function getName(): string|null return $this->next->getName(); } - public function getFileName(): string|null + public function getFileName(): string { return '/non/existing/path/to/sources.php'; } @@ -1096,7 +1096,7 @@ private static function realPath(string|false $path): string { $realPath = realpath($path); - assert(is_string($realPath) && $realPath !== ''); + assert(is_string($realPath)); return $realPath; } diff --git a/test/unit/Reflection/Adapter/ReflectionClassConstantTest.php b/test/unit/Reflection/Adapter/ReflectionClassConstantTest.php index 6fbc34b66..5a09ec314 100644 --- a/test/unit/Reflection/Adapter/ReflectionClassConstantTest.php +++ b/test/unit/Reflection/Adapter/ReflectionClassConstantTest.php @@ -370,7 +370,7 @@ public function testUnknownProperty(): void $reflectionClassConstantAdapter = new ReflectionClassConstantAdapter($betterReflectionClassConstant); $this->expectException(OutOfBoundsException::class); $this->expectExceptionMessage('Property Roave\BetterReflection\Reflection\Adapter\ReflectionClassConstant::$foo does not exist.'); - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore property.notFound, expr.resultUnused */ $reflectionClassConstantAdapter->foo; } diff --git a/test/unit/Reflection/Adapter/ReflectionClassTest.php b/test/unit/Reflection/Adapter/ReflectionClassTest.php index 5078fcb1a..75e0f2db9 100644 --- a/test/unit/Reflection/Adapter/ReflectionClassTest.php +++ b/test/unit/Reflection/Adapter/ReflectionClassTest.php @@ -975,7 +975,7 @@ public function testUnknownProperty(): void $reflectionClassAdapter = new ReflectionClassAdapter($betterReflectionClass); $this->expectException(OutOfBoundsException::class); $this->expectExceptionMessage('Property Roave\BetterReflection\Reflection\Adapter\ReflectionClass::$foo does not exist.'); - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore property.notFound, expr.resultUnused */ $reflectionClassAdapter->foo; } diff --git a/test/unit/Reflection/Adapter/ReflectionEnumBackedCaseTest.php b/test/unit/Reflection/Adapter/ReflectionEnumBackedCaseTest.php index 2588ec0f9..deaab9481 100644 --- a/test/unit/Reflection/Adapter/ReflectionEnumBackedCaseTest.php +++ b/test/unit/Reflection/Adapter/ReflectionEnumBackedCaseTest.php @@ -385,7 +385,7 @@ public function testUnknownProperty(): void $reflectionEnumBackedCaseAdapter = new ReflectionEnumBackedCaseAdapter($betterReflectionEnumCase); $this->expectException(OutOfBoundsException::class); $this->expectExceptionMessage('Property Roave\BetterReflection\Reflection\Adapter\ReflectionEnumBackedCase::$foo does not exist.'); - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore property.notFound, expr.resultUnused */ $reflectionEnumBackedCaseAdapter->foo; } } diff --git a/test/unit/Reflection/Adapter/ReflectionEnumTest.php b/test/unit/Reflection/Adapter/ReflectionEnumTest.php index dd29887e3..4f0f2f3a1 100644 --- a/test/unit/Reflection/Adapter/ReflectionEnumTest.php +++ b/test/unit/Reflection/Adapter/ReflectionEnumTest.php @@ -260,7 +260,7 @@ public function testUnknownProperty(): void $this->expectException(OutOfBoundsException::class); $this->expectExceptionMessage('Property Roave\BetterReflection\Reflection\Adapter\ReflectionEnum::$foo does not exist.'); - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore property.notFound, expr.resultUnused */ $reflectionEnumAdapter->foo; } diff --git a/test/unit/Reflection/Adapter/ReflectionEnumUnitCaseTest.php b/test/unit/Reflection/Adapter/ReflectionEnumUnitCaseTest.php index d92f93fe8..103b5a344 100644 --- a/test/unit/Reflection/Adapter/ReflectionEnumUnitCaseTest.php +++ b/test/unit/Reflection/Adapter/ReflectionEnumUnitCaseTest.php @@ -373,7 +373,7 @@ public function testUnknownProperty(): void $reflectionEnumUnitCaseAdapter = new ReflectionEnumUnitCaseAdapter($betterReflectionEnumCase); $this->expectException(OutOfBoundsException::class); $this->expectExceptionMessage('Property Roave\BetterReflection\Reflection\Adapter\ReflectionEnumUnitCase::$foo does not exist.'); - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore property.notFound, expr.resultUnused */ $reflectionEnumUnitCaseAdapter->foo; } } diff --git a/test/unit/Reflection/Adapter/ReflectionFunctionTest.php b/test/unit/Reflection/Adapter/ReflectionFunctionTest.php index 369c0d291..d1e787463 100644 --- a/test/unit/Reflection/Adapter/ReflectionFunctionTest.php +++ b/test/unit/Reflection/Adapter/ReflectionFunctionTest.php @@ -433,7 +433,7 @@ public function testUnknownProperty(): void $reflectionFunctionAdapter = new ReflectionFunctionAdapter($betterReflectionFunction); $this->expectException(OutOfBoundsException::class); $this->expectExceptionMessage('Property Roave\BetterReflection\Reflection\Adapter\ReflectionFunction::$foo does not exist.'); - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore property.notFound, expr.resultUnused */ $reflectionFunctionAdapter->foo; } diff --git a/test/unit/Reflection/Adapter/ReflectionMethodTest.php b/test/unit/Reflection/Adapter/ReflectionMethodTest.php index 020983194..d97b81fb6 100644 --- a/test/unit/Reflection/Adapter/ReflectionMethodTest.php +++ b/test/unit/Reflection/Adapter/ReflectionMethodTest.php @@ -604,7 +604,7 @@ public function testUnknownProperty(): void $reflectionMethodAdapter = new ReflectionMethodAdapter($betterReflectionMethod); $this->expectException(OutOfBoundsException::class); $this->expectExceptionMessage('Property Roave\BetterReflection\Reflection\Adapter\ReflectionMethod::$foo does not exist.'); - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore property.notFound, expr.resultUnused */ $reflectionMethodAdapter->foo; } diff --git a/test/unit/Reflection/Adapter/ReflectionObjectTest.php b/test/unit/Reflection/Adapter/ReflectionObjectTest.php index 9977a2296..aa130483c 100644 --- a/test/unit/Reflection/Adapter/ReflectionObjectTest.php +++ b/test/unit/Reflection/Adapter/ReflectionObjectTest.php @@ -1114,7 +1114,7 @@ public function testUnknownProperty(): void $reflectionObjectAdapter = new ReflectionObjectAdapter($betterReflectionObject); $this->expectException(OutOfBoundsException::class); $this->expectExceptionMessage('Property Roave\BetterReflection\Reflection\Adapter\ReflectionObject::$foo does not exist.'); - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore property.notFound, expr.resultUnused */ $reflectionObjectAdapter->foo; } diff --git a/test/unit/Reflection/Adapter/ReflectionParameterTest.php b/test/unit/Reflection/Adapter/ReflectionParameterTest.php index b84e3a3ec..5a37e099d 100644 --- a/test/unit/Reflection/Adapter/ReflectionParameterTest.php +++ b/test/unit/Reflection/Adapter/ReflectionParameterTest.php @@ -346,7 +346,7 @@ public function testUnknownProperty(): void $reflectionParameterAdapter = new ReflectionParameterAdapter($betterReflectionParameter); $this->expectException(OutOfBoundsException::class); $this->expectExceptionMessage('Property Roave\BetterReflection\Reflection\Adapter\ReflectionParameter::$foo does not exist.'); - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore property.notFound, expr.resultUnused */ $reflectionParameterAdapter->foo; } diff --git a/test/unit/Reflection/Adapter/ReflectionPropertyTest.php b/test/unit/Reflection/Adapter/ReflectionPropertyTest.php index f1df4964f..f35f4a0f0 100644 --- a/test/unit/Reflection/Adapter/ReflectionPropertyTest.php +++ b/test/unit/Reflection/Adapter/ReflectionPropertyTest.php @@ -457,7 +457,7 @@ public function testUnknownProperty(): void $reflectionPropertyAdapter = new ReflectionPropertyAdapter($betterReflectionProperty); $this->expectException(OutOfBoundsException::class); $this->expectExceptionMessage('Property Roave\BetterReflection\Reflection\Adapter\ReflectionProperty::$foo does not exist.'); - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore property.notFound, expr.resultUnused */ $reflectionPropertyAdapter->foo; } } diff --git a/test/unit/Reflection/ReflectionClassTest.php b/test/unit/Reflection/ReflectionClassTest.php index b11b23fa5..4dea2ba1d 100644 --- a/test/unit/Reflection/ReflectionClassTest.php +++ b/test/unit/Reflection/ReflectionClassTest.php @@ -96,7 +96,6 @@ use function array_keys; use function array_map; -use function array_values; use function array_walk; use function basename; use function class_exists; @@ -468,7 +467,7 @@ public function testGetInterfaceClassNames(string $sourcePath, string $className ); } - /** @return list}> */ + /** @return list}> */ public static function getInterfaceClassNamesDataProvider(): array { return [ @@ -1597,7 +1596,7 @@ public function testGetTraitClassNames(string $sourcePath, string $className, ar ); } - /** @return list}> */ + /** @return list}> */ public static function getTraitClassNamesDataProvider(): array { return [ @@ -2010,7 +2009,7 @@ public function testIsInstance(): void $this->expectException(TypeError::class); - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore argument.type */ $class->isInstance('foo'); } @@ -2229,8 +2228,8 @@ public function testGetImmediateInterfacesDoesNotIncludeCurrentInterface(): void sort($cInterfaces); sort($dInterfaces); - self::assertSame(['B'], array_values($cInterfaces)); - self::assertSame(['A', 'C'], array_values($dInterfaces)); + self::assertSame(['B'], $cInterfaces); + self::assertSame(['A', 'C'], $dInterfaces); } public function testReflectedTraitHasNoInterfaces(): void diff --git a/test/unit/Reflection/ReflectionObjectTest.php b/test/unit/Reflection/ReflectionObjectTest.php index 3099228b3..67167ee25 100644 --- a/test/unit/Reflection/ReflectionObjectTest.php +++ b/test/unit/Reflection/ReflectionObjectTest.php @@ -48,7 +48,7 @@ private function parse(string $code): array public static function anonymousClassInstancesProvider(): array { $file = realpath(__DIR__ . '/../Fixture/AnonymousClassInstances.php'); - assert(is_string($file) && $file !== ''); + assert(is_string($file)); $file = FileHelper::normalizeWindowsPath($file); @@ -76,7 +76,7 @@ public function testReflectionForAnonymousClass(object $anonymousClass, string $ public function testReflectionForAnonymousClassWithInterface(): void { $file = realpath(__DIR__ . '/../Fixture/AnonymousClassInstanceWithInterfaceForRequire.php'); - assert(is_string($file) && $file !== ''); + assert(is_string($file)); $file = FileHelper::normalizeWindowsPath($file); @@ -116,8 +116,8 @@ public function testReflectionWorksWithEvaledClasses(): void public function testReflectionWorksWithDynamicallyDeclaredMembers(): void { $foo = new RuntimeProperties(); - $foo->bar = 'huzzah'; // @phpstan-ignore-line - $foo->baz = 'bazzah'; // @phpstan-ignore-line + $foo->bar = 'huzzah'; // @phpstan-ignore property.notFound + $foo->baz = 'bazzah'; // @phpstan-ignore property.notFound $classInfo = ReflectionObject::createFromInstance($foo); @@ -139,7 +139,7 @@ public function testReflectionWorksWithDynamicallyDeclaredMembers(): void public function testExceptionThrownWhenInvalidInstanceGiven(): void { $foo = new RuntimeProperties(); - $foo->bar = 'huzzah'; // @phpstan-ignore-line + $foo->bar = 'huzzah'; // @phpstan-ignore property.notFound $classInfo = ReflectionObject::createFromInstance($foo); @@ -162,8 +162,8 @@ public function testExceptionThrownWhenInvalidInstanceGiven(): void public function testGetRuntimePropertiesWithFilter(): void { $foo = new RuntimeProperties(); - $foo->bar = 'huzzah'; // @phpstan-ignore-line - $foo->baz = 'bazzah'; // @phpstan-ignore-line + $foo->bar = 'huzzah'; // @phpstan-ignore property.notFound + $foo->baz = 'bazzah'; // @phpstan-ignore property.notFound $classInfo = ReflectionObject::createFromInstance($foo); @@ -176,8 +176,8 @@ public function testGetRuntimePropertiesWithFilter(): void public function testGetRuntimeImmediatePropertiesWithFilter(): void { $foo = new RuntimeProperties(); - $foo->bar = 'huzzah'; // @phpstan-ignore-line - $foo->baz = 'bazzah'; // @phpstan-ignore-line + $foo->bar = 'huzzah'; // @phpstan-ignore property.notFound + $foo->baz = 'bazzah'; // @phpstan-ignore property.notFound $classInfo = ReflectionObject::createFromInstance($foo); @@ -190,7 +190,7 @@ public function testGetRuntimeImmediatePropertiesWithFilter(): void public function testRuntimePropertyCannotBePromoted(): void { $foo = new RuntimeProperties(); - $foo->bar = 'huzzah'; // @phpstan-ignore-line + $foo->bar = 'huzzah'; // @phpstan-ignore property.notFound $classInfo = ReflectionObject::createFromInstance($foo); $propertyInfo = $classInfo->getProperty('bar'); @@ -202,7 +202,7 @@ public function testRuntimePropertyCannotBePromoted(): void public function testGetDefaultPropertiesShouldIgnoreRuntimeProperty(): void { $object = new DefaultProperties(); - $object->notDefaultProperty = null; // @phpstan-ignore-line + $object->notDefaultProperty = null; // @phpstan-ignore property.notFound $classInfo = ReflectionObject::createFromInstance($object); diff --git a/test/unit/Reflection/StringCast/ReflectionClassStringCastTest.php b/test/unit/Reflection/StringCast/ReflectionClassStringCastTest.php index 928e6a38f..8bce67b40 100644 --- a/test/unit/Reflection/StringCast/ReflectionClassStringCastTest.php +++ b/test/unit/Reflection/StringCast/ReflectionClassStringCastTest.php @@ -132,7 +132,7 @@ public function testClassObjectToString(): void $object = new StringCastClassObject(); - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore property.notFound */ $object->dynamicProperty = 'string'; $objectReflection = ReflectionObject::createFromInstance($object); diff --git a/test/unit/SourceLocator/SourceStubber/ReflectionSourceStubberTest.php b/test/unit/SourceLocator/SourceStubber/ReflectionSourceStubberTest.php index dec9a7a14..bc386299c 100644 --- a/test/unit/SourceLocator/SourceStubber/ReflectionSourceStubberTest.php +++ b/test/unit/SourceLocator/SourceStubber/ReflectionSourceStubberTest.php @@ -378,19 +378,10 @@ private function assertSameMethodAttributes(CoreReflectionMethod $original, Refl self::assertSame($original->isAbstract(), $stubbed->isAbstract()); self::assertSame($original->isDeprecated(), $stubbed->isDeprecated()); - if (method_exists($original, 'hasTentativeReturnType')) { - self::assertSame($original->hasTentativeReturnType(), $stubbed->hasTentativeReturnType(), $original->getName()); - self::assertSame( - (string) $original->getTentativeReturnType(), - (string) ReflectionType::fromTypeOrNull($stubbed->getTentativeReturnType()), - $original->getName(), - ); - } - - self::assertSame($original->hasReturnType(), $stubbed->hasReturnType(), $original->getName()); + self::assertSame($original->hasTentativeReturnType(), $stubbed->hasTentativeReturnType(), $original->getName()); self::assertSame( - (string) $original->getReturnType(), - (string) ReflectionType::fromTypeOrNull($stubbed->getReturnType()), + (string) $original->getTentativeReturnType(), + (string) ReflectionType::fromTypeOrNull($stubbed->getTentativeReturnType()), $original->getName(), ); } @@ -444,19 +435,11 @@ public function testInternalFunctionsReturnType(string $functionName): void $stubbedReflection = $this->reflector->reflectFunction($functionName); $originalReflection = new CoreReflectionFunction($functionName); - if (method_exists($originalReflection, 'hasTentativeReturnType') && $originalReflection->hasTentativeReturnType()) { - self::assertSame($originalReflection->hasTentativeReturnType(), $stubbedReflection->hasTentativeReturnType()); - self::assertSame( - (string) $originalReflection->getTentativeReturnType(), - (string) ReflectionType::fromTypeOrNull($stubbedReflection->getTentativeReturnType()), - ); - } else { - self::assertSame($originalReflection->hasReturnType(), $stubbedReflection->hasReturnType()); - self::assertSame( - (string) $originalReflection->getReturnType(), - (string) ReflectionType::fromTypeOrNull($stubbedReflection->getReturnType()), - ); - } + self::assertSame($originalReflection->hasTentativeReturnType(), $stubbedReflection->hasTentativeReturnType()); + self::assertSame( + (string) $originalReflection->getTentativeReturnType(), + (string) ReflectionType::fromTypeOrNull($stubbedReflection->getTentativeReturnType()), + ); } public function testFunctionWithParameterPassedByReference(): void diff --git a/test/unit/SourceLocator/Type/AnonymousClassObjectSourceLocatorTest.php b/test/unit/SourceLocator/Type/AnonymousClassObjectSourceLocatorTest.php index a27acd0bc..cdc9f1a04 100644 --- a/test/unit/SourceLocator/Type/AnonymousClassObjectSourceLocatorTest.php +++ b/test/unit/SourceLocator/Type/AnonymousClassObjectSourceLocatorTest.php @@ -274,7 +274,7 @@ private static function realPath(string|false $path): string { $realPath = realpath($path); - assert(is_string($realPath) && $realPath !== ''); + assert(is_string($realPath)); return $realPath; } diff --git a/test/unit/SourceLocator/Type/AutoloadSourceLocator/FileReadTrapStreamWrapperTest.php b/test/unit/SourceLocator/Type/AutoloadSourceLocator/FileReadTrapStreamWrapperTest.php index d558dbc25..259f14eb4 100644 --- a/test/unit/SourceLocator/Type/AutoloadSourceLocator/FileReadTrapStreamWrapperTest.php +++ b/test/unit/SourceLocator/Type/AutoloadSourceLocator/FileReadTrapStreamWrapperTest.php @@ -48,7 +48,7 @@ static function (): string { throw new UnexpectedValueException('is_file() should operate as usual'); } - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore notIdentical.alwaysFalse */ if (FileReadTrapStreamWrapper::$autoloadLocatedFile !== null) { throw new UnexpectedValueException('FileReadTrapStreamWrapper::$autoloadLocatedFile should not be populated when file existence is checked'); } @@ -57,11 +57,12 @@ static function (): string { throw new UnexpectedValueException('file_get_contents() should fail: file should not be readable when this stream wrapper is active'); } + /** @phpstan-ignore notIdentical.alwaysTrue */ if (__FILE__ !== FileReadTrapStreamWrapper::$autoloadLocatedFile) { throw new UnexpectedValueException('FileReadTrapStreamWrapper::$autoloadLocatedFile should have been populated by the failed file access'); } - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore deadCode.unreachable */ return 'value produced by the function'; }, ['file'], @@ -93,7 +94,7 @@ static function () use ($nonExistingFilePath): string { throw new UnexpectedValueException('is_file() should operate as usual - file does indeed not exist'); } - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore notIdentical.alwaysFalse */ if (FileReadTrapStreamWrapper::$autoloadLocatedFile !== null) { throw new UnexpectedValueException('FileReadTrapStreamWrapper::$autoloadLocatedFile should not be populated when file existence is checked'); } @@ -102,11 +103,12 @@ static function () use ($nonExistingFilePath): string { throw new UnexpectedValueException('file_get_contents() should fail: file should not be readable when this stream wrapper is active'); } + /** @phpstan-ignore notIdentical.alwaysTrue */ if ($nonExistingFilePath !== FileReadTrapStreamWrapper::$autoloadLocatedFile) { throw new UnexpectedValueException('FileReadTrapStreamWrapper::$autoloadLocatedFile should have been populated by the failed file access'); } - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore deadCode.unreachable */ return 'the value produced by the function'; }, ['file'], @@ -133,7 +135,7 @@ static function (): string { throw new UnexpectedValueException('is_file() should operate as usual - stream wrapper not active'); } - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore notIdentical.alwaysFalse */ if (FileReadTrapStreamWrapper::$autoloadLocatedFile !== null) { throw new UnexpectedValueException('FileReadTrapStreamWrapper::$autoloadLocatedFile should not be populated when file existence is checked'); } @@ -142,7 +144,7 @@ static function (): string { throw new UnexpectedValueException('file_get_contents() should work: file access not on this protocol'); } - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore notIdentical.alwaysFalse */ if (FileReadTrapStreamWrapper::$autoloadLocatedFile !== null) { throw new UnexpectedValueException('FileReadTrapStreamWrapper::$autoloadLocatedFile should not have been populated: unrelated protocol'); } @@ -173,14 +175,14 @@ static function () use ($thrown): void { ['http'], ); - // @phpstan-ignore deadCode.unreachable + /** @phpstan-ignore deadCode.unreachable */ self::fail('No exception was raised'); - // @phpstan-ignore catch.neverThrown + /** @phpstan-ignore catch.neverThrown */ } catch (Throwable $caught) { self::assertSame($thrown, $caught); } - // @phpstan-ignore deadCode.unreachable + /** @phpstan-ignore deadCode.unreachable */ self::assertNull(FileReadTrapStreamWrapper::$autoloadLocatedFile); self::assertNotEmpty(file_get_contents(__FILE__), 'Stream wrapper was removed, file reads work again'); } diff --git a/test/unit/SourceLocator/Type/AutoloadSourceLocatorTest.php b/test/unit/SourceLocator/Type/AutoloadSourceLocatorTest.php index a1ce9f1c9..9ca33733b 100644 --- a/test/unit/SourceLocator/Type/AutoloadSourceLocatorTest.php +++ b/test/unit/SourceLocator/Type/AutoloadSourceLocatorTest.php @@ -86,6 +86,7 @@ public function testClassLoadsWorksWithExistingClass(): void $reflector = new DefaultReflector(new AutoloadSourceLocator($this->astLocator)); // Ensure class is loaded first + /** @phpstan-ignore new.resultUnused */ new ClassForHinting(); self::assertTrue(class_exists(ClassForHinting::class, false)); @@ -100,6 +101,7 @@ public function testClassLoadsWithLowercasedName(): void $reflector = new DefaultReflector(new AutoloadSourceLocator($this->astLocator)); // Ensure class is loaded first + /** @phpstan-ignore new.resultUnused */ new ClassForHinting(); self::assertTrue(class_exists(ClassForHinting::class, false)); @@ -403,7 +405,7 @@ public function testCanAutoloadPsr4ClassesInPotentiallyMultipleDirectories(): vo return true; }; - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore argument.type */ spl_autoload_register($autoload); self::assertNotNull( diff --git a/test/unit/SourceLocator/Type/ClosureSourceLocatorTest.php b/test/unit/SourceLocator/Type/ClosureSourceLocatorTest.php index e76e36ab1..7e2d31e54 100644 --- a/test/unit/SourceLocator/Type/ClosureSourceLocatorTest.php +++ b/test/unit/SourceLocator/Type/ClosureSourceLocatorTest.php @@ -88,7 +88,7 @@ public function testEvaledClosureThrowsInvalidFileLocation(): void { eval('$closure = function () {};'); - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore variable.undefined */ $locator = new ClosureSourceLocator($closure, $this->parser); $this->expectException(EvaledClosureCannotBeLocated::class); @@ -233,7 +233,7 @@ private static function realPath(string|false $path): string { $realPath = realpath($path); - assert(is_string($realPath) && $realPath !== ''); + assert(is_string($realPath)); return $realPath; } diff --git a/test/unit/SourceLocator/Type/FileIteratorSourceLocatorTest.php b/test/unit/SourceLocator/Type/FileIteratorSourceLocatorTest.php index e1ff02c1b..a13ab201b 100644 --- a/test/unit/SourceLocator/Type/FileIteratorSourceLocatorTest.php +++ b/test/unit/SourceLocator/Type/FileIteratorSourceLocatorTest.php @@ -79,7 +79,7 @@ public function testIteratorWithoutSplFileInfo(): void { $this->expectException(InvalidFileInfo::class); - /** @phpstan-ignore-next-line */ + /** @phpstan-ignore argument.type */ new FileIteratorSourceLocator(new ArrayIterator([new stdClass()]), BetterReflectionSingleton::instance()->astLocator()); } } diff --git a/tools/composer.json b/tools/composer.json index f6ef40abf..f684e8aa5 100644 --- a/tools/composer.json +++ b/tools/composer.json @@ -1,8 +1,8 @@ { "require": { "doctrine/coding-standard": "^12.0.0", - "phpstan/phpstan": "^1.12.11", - "phpstan/phpstan-phpunit": "^1.4.1", + "phpstan/phpstan": "^2.0.2", + "phpstan/phpstan-phpunit": "^2.0.1", "vimeo/psalm": "^5.26.1", "roave/backward-compatibility-check": "^8.10.0", "roave/infection-static-analysis-plugin": "^1.35.0" diff --git a/tools/composer.lock b/tools/composer.lock index ad7148750..5c5577632 100644 --- a/tools/composer.lock +++ b/tools/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "2f88545baf54e10aa7ce47438ed53463", + "content-hash": "c959d25dec46c2ad2f93aa6fe09a9b4b", "packages": [ { "name": "amphp/amp", @@ -2371,20 +2371,20 @@ }, { "name": "phpstan/phpstan", - "version": "1.12.11", + "version": "2.0.2", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "0d1fc20a962a91be578bcfe7cf939e6e1a2ff733" + "reference": "6c98c7600fc717b2c78c11ef60040d5b1e359c82" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/0d1fc20a962a91be578bcfe7cf939e6e1a2ff733", - "reference": "0d1fc20a962a91be578bcfe7cf939e6e1a2ff733", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/6c98c7600fc717b2c78c11ef60040d5b1e359c82", + "reference": "6c98c7600fc717b2c78c11ef60040d5b1e359c82", "shasum": "" }, "require": { - "php": "^7.2|^8.0" + "php": "^7.4|^8.0" }, "conflict": { "phpstan/phpstan-shim": "*" @@ -2425,34 +2425,33 @@ "type": "github" } ], - "time": "2024-11-17T14:08:01+00:00" + "time": "2024-11-17T14:17:00+00:00" }, { "name": "phpstan/phpstan-phpunit", - "version": "1.4.1", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-phpunit.git", - "reference": "11d4235fbc6313ecbf93708606edfd3222e44949" + "reference": "4b6ad7fab8683ff4efd7887ba26ef8ee171c7475" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/11d4235fbc6313ecbf93708606edfd3222e44949", - "reference": "11d4235fbc6313ecbf93708606edfd3222e44949", + "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/4b6ad7fab8683ff4efd7887ba26ef8ee171c7475", + "reference": "4b6ad7fab8683ff4efd7887ba26ef8ee171c7475", "shasum": "" }, "require": { - "php": "^7.2 || ^8.0", - "phpstan/phpstan": "^1.12" + "php": "^7.4 || ^8.0", + "phpstan/phpstan": "^2.0" }, "conflict": { "phpunit/phpunit": "<7.0" }, "require-dev": { - "nikic/php-parser": "^4.13.0", "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/phpstan-strict-rules": "^1.5.1", - "phpunit/phpunit": "^9.5" + "phpstan/phpstan-strict-rules": "^2.0", + "phpunit/phpunit": "^9.6" }, "type": "phpstan-extension", "extra": { @@ -2475,9 +2474,9 @@ "description": "PHPUnit extensions and rules for PHPStan", "support": { "issues": "https://github.com/phpstan/phpstan-phpunit/issues", - "source": "https://github.com/phpstan/phpstan-phpunit/tree/1.4.1" + "source": "https://github.com/phpstan/phpstan-phpunit/tree/2.0.1" }, - "time": "2024-11-12T12:43:59+00:00" + "time": "2024-11-12T12:48:00+00:00" }, { "name": "psr/container",