mirror of
https://github.com/danog/psalm.git
synced 2024-12-02 09:37:59 +01:00
revert: class-string
should not allow callable
only
As per discussion with Ondřej, `class-string` should explicitly target objects. Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
This commit is contained in:
parent
0621ca6e70
commit
a8ed8a7b5c
@ -718,10 +718,6 @@ class TypeParser
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($type instanceof TCallable) {
|
|
||||||
$type = new TCallableObject($from_docblock, $type);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($type instanceof TCallableObject) {
|
if ($type instanceof TCallableObject) {
|
||||||
$types[] = new TUnknownClassString($type, false, $from_docblock);
|
$types[] = new TUnknownClassString($type, false, $from_docblock);
|
||||||
continue;
|
continue;
|
||||||
|
@ -92,29 +92,6 @@ final class IntersectionTypeTest extends TestCase
|
|||||||
'assertions' => [],
|
'assertions' => [],
|
||||||
'ignored_issues' => ['UnsafeInstantiation', 'MixedMethodCall'],
|
'ignored_issues' => ['UnsafeInstantiation', 'MixedMethodCall'],
|
||||||
],
|
],
|
||||||
'classStringOfCallableWillBeTreatedAsCallableObject' => [
|
|
||||||
'code' => '<?php
|
|
||||||
/**
|
|
||||||
* @param class-string<callable():int> $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' => [
|
'classStringOfCallableObjectEqualsObjectWithCallableIntersection' => [
|
||||||
'code' => '<?php
|
'code' => '<?php
|
||||||
/**
|
/**
|
||||||
@ -211,6 +188,30 @@ final class IntersectionTypeTest extends TestCase
|
|||||||
',
|
',
|
||||||
'error_message' => 'MixedMethodCall',
|
'error_message' => 'MixedMethodCall',
|
||||||
],
|
],
|
||||||
|
'classStringOfCallableIsNotAllowed' => [
|
||||||
|
# Ref: https://github.com/phpstan/phpstan/issues/9148
|
||||||
|
'code' => '<?php
|
||||||
|
/**
|
||||||
|
* @param class-string<callable():int> $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'],
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user