addStubFile( 'stubOne.phpstub', 'addFile( 'somefile.php', 'analyzeFile('somefile.php', new Context()); } /** * @return iterable,error_levels?:string[]}> */ public function providerValidCodeParse(): iterable { return [ 'classAndPropertyAttributesExists' => [ ' [ ' [ ' [ 'getAttributes(BaseAttribute::class, 2) as $attr) { $attribute = $attr->newInstance(); echo $attribute->name; } }', [], [], '8.0' ], 'testReflectingAllAttributes' => [ 'getAttributes(); ', 'assertions' => [ '$b' => 'array>', ], [], '8.0' ], 'convertKeyedArray' => [ 'methods = $methods; } } #[Route(methods: ["GET"])] class HealthController {}', ], 'allowsRepeatableFlag' => [ ' [ ' $_className */ public function __construct(string $_className) { } } #[Foo(_className: Baz::class)] class Baz {}', ], 'allowsClassStringFromDifferentNamespace' => [ ' $className */ public function __construct(string $className) { $this->className = $className; } } interface FoobarInterface {} class Bar implements FoobarInterface {} } namespace NamespaceTwo { use NamespaceOne\FooAttribute; use NamespaceOne\Bar as ZZ; #[FooAttribute(className: ZZ::class)] class Baz {} } ' ], 'returnTypeWillChange7.1' => [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' [ ' */ public function providerInvalidCodeParse(): iterable { return [ 'attributeClassHasNoAttributeAnnotation' => [ ' 'InvalidAttribute - src' . DIRECTORY_SEPARATOR . 'somefile.php:4:23', ], 'missingAttributeOnClass' => [ ' 'UndefinedAttributeClass - src' . DIRECTORY_SEPARATOR . 'somefile.php:4:23', ], 'missingAttributeOnProperty' => [ ' 'UndefinedAttributeClass - src' . DIRECTORY_SEPARATOR . 'somefile.php:6:27', ], 'missingAttributeOnFunction' => [ ' 'UndefinedAttributeClass - src' . DIRECTORY_SEPARATOR . 'somefile.php:4:23', ], 'missingAttributeOnParam' => [ ' 'UndefinedAttributeClass - src' . DIRECTORY_SEPARATOR . 'somefile.php:4:36', ], 'tooFewArgumentsToAttributeConstructor' => [ ' 'TooFewArguments - src' . DIRECTORY_SEPARATOR . 'somefile.php:9:23', ], 'invalidArgument' => [ ' 'InvalidScalarArgument - src' . DIRECTORY_SEPARATOR . 'somefile.php:10:27', ], 'classAttributeUsedOnFunction' => [ ' 'InvalidAttribute - src' . DIRECTORY_SEPARATOR . 'somefile.php:9:23', ], 'interfaceCannotBeAttributeClass' => [ ' 'InvalidAttribute - src' . DIRECTORY_SEPARATOR . 'somefile.php:2:23', ], 'traitCannotBeAttributeClass' => [ ' 'InvalidAttribute - src' . DIRECTORY_SEPARATOR . 'somefile.php:2:23', ], 'abstractClassCannotBeAttributeClass' => [ ' 'InvalidAttribute - src' . DIRECTORY_SEPARATOR . 'somefile.php:2:23', ], 'attributeClassCannotHavePrivateConstructor' => [ ' 'InvalidAttribute - src' . DIRECTORY_SEPARATOR . 'somefile.php:2:23', ], 'SKIPPED-attributeInvalidTargetClassConst' => [ // Will be implemented in Psalm 5 where we have better class const analysis ' 'InvalidAttribute', ], 'attributeInvalidTargetProperty' => [ ' 'InvalidAttribute', ], 'attributeInvalidTargetMethod' => [ ' 'InvalidAttribute', ], 'attributeInvalidTargetFunction' => [ ' 'InvalidAttribute', ], 'attributeInvalidTargetParameter' => [ ' 'InvalidAttribute', ], 'attributeTargetArgCannotBeVariable' => [ ' 'UndefinedVariable', ], 'attributeTargetArgCannotBeSelfConst' => [ ' 'NonStaticSelfCall', ], 'noParentInAttributeOnClassWithoutParent' => [ ' 'ParentNotFound', ], 'undefinedConstantInAttribute' => [ ' 'UndefinedConstant', ], 'getAttributesOnClassWithNonClassAttribute' => [ 'getAttributes(Attr::class); ', 'error_message' => 'InvalidAttribute - src' . DIRECTORY_SEPARATOR . 'somefile.php:8:39 - Attribute Attr cannot be used on a class', ], 'getAttributesOnFunctionWithNonFunctionAttribute' => [ 'getAttributes(Attr::class); ', 'error_message' => 'InvalidAttribute - src' . DIRECTORY_SEPARATOR . 'somefile.php:9:39 - Attribute Attr cannot be used on a function', ], 'getAttributesOnMethodWithNonMethodAttribute' => [ 'getAttributes(Attr::class); ', 'error_message' => 'InvalidAttribute - src' . DIRECTORY_SEPARATOR . 'somefile.php:11:39 - Attribute Attr cannot be used on a method', ], 'getAttributesOnPropertyWithNonPropertyAttribute' => [ 'getAttributes(Attr::class); ', 'error_message' => 'InvalidAttribute - src' . DIRECTORY_SEPARATOR . 'somefile.php:11:39 - Attribute Attr cannot be used on a property', ], 'getAttributesOnClassConstantWithNonClassConstantAttribute' => [ 'getAttributes(Attr::class); ', 'error_message' => 'InvalidAttribute - src' . DIRECTORY_SEPARATOR . 'somefile.php:11:39 - Attribute Attr cannot be used on a class constant', ], 'getAttributesOnParameterWithNonParameterAttribute' => [ 'getAttributes(Attr::class); ', 'error_message' => 'InvalidAttribute - src' . DIRECTORY_SEPARATOR . 'somefile.php:8:39 - Attribute Attr cannot be used on a function/method parameter', ], 'getAttributesWithNonAttribute' => [ 'getAttributes(NonAttr::class); ', 'error_message' => 'InvalidAttribute - src' . DIRECTORY_SEPARATOR . 'somefile.php:7:39 - The class NonAttr doesn\'t have the Attribute attribute', ], 'analyzeConstructorForNonexistentAttributes' => [ ' 'InvalidScalarArgument', ], 'multipleAttributesShowErrors' => [ ' 'InvalidAttribute', ], 'repeatNonRepeatableAttribute' => [ ' 'InvalidAttribute - src' . DIRECTORY_SEPARATOR . 'somefile.php:5:28 - Attribute Foo is not repeatable', ], 'invalidAttributeConstructionWithReturningFunction' => [ ' 'UndefinedConstant', [], false, '8.1', ], 'sensitiveParameterOnMethod' => [ ' 'Attribute SensitiveParameter cannot be used on a method', ], ]; } }