diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 1e75d3c46..dd2cc33dd 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -13,17 +13,11 @@ parameters: path: docs/examples/specs/using-links/attributes/User.php - - message: '#^Call to function method_exists\(\) with ReflectionProperty and ''isPromoted'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType + message: '#^Call to an undefined method Reflector\:\:getAttributes\(\)\.$#' + identifier: method.notFound count: 1 path: src/Analysers/AttributeAnnotationFactory.php - - - message: '#^Call to function method_exists\(\) with ReflectionClass\ and ''isEnum'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: src/Analysers/ReflectionAnalyser.php - - message: '#^Call to function property_exists\(\) with OpenApi\\Annotations\\AbstractAnnotation and ''_context'' will always evaluate to true\.$#' identifier: function.alreadyNarrowedType @@ -102,18 +96,6 @@ parameters: count: 1 path: src/Processors/MergeXmlContent.php - - - message: '#^Call to function method_exists\(\) with ReflectionProperty and ''isPromoted'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 2 - path: src/Type/LegacyTypeResolver.php - - - - message: '#^Call to function method_exists\(\) with ReflectionProperty and ''isPromoted'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 2 - path: src/Type/TypeInfoTypeResolver.php - - message: '#^Parameter \#1 \$callback of function spl_autoload_register expects \(callable\(string\)\: void\)\|null, array\{Composer\\Autoload\\ClassLoader, ''findFile''\} given\.$#' identifier: argument.type diff --git a/src/Analysers/AttributeAnnotationFactory.php b/src/Analysers/AttributeAnnotationFactory.php index facbfc41d..fb9f9d16c 100644 --- a/src/Analysers/AttributeAnnotationFactory.php +++ b/src/Analysers/AttributeAnnotationFactory.php @@ -30,11 +30,11 @@ public function isSupported(): bool public function build(\Reflector $reflector, Context $context): array { - if (!$this->isSupported() || !method_exists($reflector, 'getAttributes')) { + if (!$this->isSupported()) { return []; } - if ($reflector instanceof \ReflectionProperty && method_exists($reflector, 'isPromoted') && $reflector->isPromoted()) { + if ($reflector instanceof \ReflectionProperty && $reflector->isPromoted()) { // handled via __construct() parameter return []; } diff --git a/src/Analysers/ReflectionAnalyser.php b/src/Analysers/ReflectionAnalyser.php index dd3ff6eb4..649f6609b 100644 --- a/src/Analysers/ReflectionAnalyser.php +++ b/src/Analysers/ReflectionAnalyser.php @@ -91,7 +91,9 @@ protected function analyzeFqdn(string $fqdn, Analysis $analysis, array $details) } $rc = new \ReflectionClass($fqdn); - $contextType = $rc->isInterface() ? 'interface' : ($rc->isTrait() ? 'trait' : ((method_exists($rc, 'isEnum') && $rc->isEnum()) ? 'enum' : 'class')); + $contextType = $rc->isInterface() + ? 'interface' + : ($rc->isTrait() ? 'trait' : ($rc->isEnum() ? 'enum' : 'class')); $context = new Context([ $contextType => $rc->getShortName(), 'namespace' => $rc->getNamespaceName() ?: null, diff --git a/src/Type/LegacyTypeResolver.php b/src/Type/LegacyTypeResolver.php index b7fb84395..3548976a0 100644 --- a/src/Type/LegacyTypeResolver.php +++ b/src/Type/LegacyTypeResolver.php @@ -174,7 +174,7 @@ protected function getReflectionTypeDetails(\Reflector $reflector, ?Context $con protected function getDocblockTypeDetails(\Reflector $reflector, ?Context $context): \stdClass { $docComment = match (true) { - $reflector instanceof \ReflectionProperty => (method_exists($reflector, 'isPromoted') && $reflector->isPromoted()) + $reflector instanceof \ReflectionProperty => $reflector->isPromoted() && $reflector->getDeclaringClass() && $reflector->getDeclaringClass()->getConstructor() ? $reflector->getDeclaringClass()->getConstructor()->getDocComment() : $reflector->getDocComment(), @@ -191,7 +191,7 @@ protected function getDocblockTypeDetails(\Reflector $reflector, ?Context $conte } $tagName = match (true) { - $reflector instanceof \ReflectionProperty => (method_exists($reflector, 'isPromoted') && $reflector->isPromoted()) + $reflector instanceof \ReflectionProperty => $reflector->isPromoted() ? '@param' : '@var', $reflector instanceof \ReflectionParameter => '@param', diff --git a/src/Type/TypeInfoTypeResolver.php b/src/Type/TypeInfoTypeResolver.php index 9f7da4aa7..a2e0d0a22 100644 --- a/src/Type/TypeInfoTypeResolver.php +++ b/src/Type/TypeInfoTypeResolver.php @@ -187,7 +187,7 @@ protected function getReflectionType(\Reflector $reflector): ?Type public function getDocblockType(\Reflector $reflector): ?Type { $docComment = match (true) { - $reflector instanceof \ReflectionProperty => (method_exists($reflector, 'isPromoted') && $reflector->isPromoted()) + $reflector instanceof \ReflectionProperty => $reflector->isPromoted() && $reflector->getDeclaringClass() && $reflector->getDeclaringClass()->getConstructor() ? $reflector->getDeclaringClass()->getConstructor()->getDocComment() : $reflector->getDocComment(), @@ -203,7 +203,7 @@ public function getDocblockType(\Reflector $reflector): ?Type $typeContext = (new TypeContextFactory())->createFromReflection($reflector); $tagName = match (true) { - $reflector instanceof \ReflectionProperty => (method_exists($reflector, 'isPromoted') && $reflector->isPromoted()) + $reflector instanceof \ReflectionProperty => $reflector->isPromoted() ? '@param' : '@var', $reflector instanceof \ReflectionParameter => '@param',