[ 'code' => ' [ 'code' => ' $className */ function takesCallableObject(string $className): void { $object = new $className(); $object(); }', 'assertions' => [], 'ignored_issues' => ['UnsafeInstantiation', 'MixedMethodCall'], ], 'callableObjectWithRequiredStringArgument' => [ 'code' => ' [ 'code' => ' $className */ function takesCallableObject(string $className): void { $object = new $className(); $object("foo"); }', 'assertions' => [], 'ignored_issues' => ['UnsafeInstantiation', 'MixedMethodCall'], ], 'callableObjectWithReturnType' => [ 'code' => ' [ 'code' => ' $className */ function takesCallableObject(string $className): int { $object = new $className(); return $object(); } class Foo { public function __invoke(): int { return 0; } } takesCallableObject(Foo::class); ', 'assertions' => [], 'ignored_issues' => ['UnsafeInstantiation', 'MixedMethodCall'], ], 'classStringOfCallableObjectEqualsObjectWithCallableIntersection' => [ 'code' => ' $className */ function takesCallableObject(string $className): void { $object = new $className(); $object(); } class Foo { public function __invoke(): void { } } takesCallableObject(Foo::class); ', 'assertions' => [], 'ignored_issues' => ['UnsafeInstantiation', 'MixedMethodCall'], ], 'classStringOfImportedCallableTypeIntersection' => [ 'code' => ' $className */ function takesCallableObject(string $className): void {} } ', 'assertions' => [], 'ignored_issues' => [], ], ]; } public function providerInvalidCodeParse(): iterable { return [ 'callableObjectWithMissingStringArgument' => [ 'code' => ' 'TooFewArguments', ], 'classStringOfCallableObjectWithMissingRequiredStringArgument' => [ 'code' => ' $className */ function takesCallableObject(string $className): void { $object = new $className(); $object(); }', 'error_message' => 'TooFewArguments', 'error_levels' => ['UnsafeInstantiation', 'MixedMethodCall'], ], 'callableObjectWithInvalidStringArgument' => [ 'code' => ' 'InvalidArgument', 'error_levels' => ['UnsafeInstantiation', 'MixedMethodCall'], ], 'classStringOfCallableObjectWithInvalidStringArgument' => [ 'code' => ' $className */ function takesCallableObject(string $className): void { $object = new $className(); $object(0); }', 'error_message' => 'InvalidArgument', 'error_levels' => ['UnsafeInstantiation', 'MixedMethodCall'], ], 'classStringOfCallableObjectWillTriggerMixedMethodCall' => [ 'code' => ' $className */ function takesCallableObject(string $className): void { new $className(); } class Foo { public function __invoke(): int { return 0; } } takesCallableObject(Foo::class); ', 'error_message' => 'MixedMethodCall', ], 'classStringOfCallableIsNotAllowed' => [ # Ref: https://github.com/phpstan/phpstan/issues/9148 'code' => ' $className */ function takesCallableObject(string $className): int { $object = new $className(); return $object(); } class Foo { public function __invoke(): int { return 0; } } takesCallableObject(Foo::class); ', 'error_message' => 'class-string param can only target', 'error_levels' => ['UnsafeInstantiation', 'MixedMethodCall'], ], ]; } }