Skip to content

Commit

Permalink
Notes on questions for next steps
Browse files Browse the repository at this point in the history
  • Loading branch information
mglaman committed Nov 18, 2021
1 parent 1c3c5e3 commit c815c71
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/Type/Constant/ConstantArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,12 @@ public function equals(Type $type): bool

public function isCallable(): TrinaryLogic
{
// @todo is there a way to fetch the full scope here.
// An OutOfClassScope causes frivolous errors when checking if a
// non-static method was invoked statically in its own class, which
// is allowed per: https://3v4l.org/mTa9S.
// Should add an optional scope parameter to isCallable and if null,
// create a new OutOfClassScope instance.
$typeAndMethod = $this->findTypeAndMethodName(new OutOfClassScope());
if ($typeAndMethod === null) {
return TrinaryLogic::createNo();
Expand Down
11 changes: 9 additions & 2 deletions tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,18 @@ public function testBug5782(): void
$this->analyse([__DIR__ . '/data/bug-5782.php'], [
[
'Parameter #1 $callback of static method Closure::fromCallable() expects callable(): mixed, array{\'Bug5782\\\HelloWorld\', \'sayGoodbye\'} given.',
22,
23,
],
[
'Parameter #1 $callback of static method Closure::fromCallable() expects callable(): mixed, array{\'Bug5782\\\HelloWorld\', \'sayGoodbye\'} given.',
26,
30,
],
// @todo this should also error on mixed type, but doesn't?
// ConstantStringType::getCallableParametersAcceptors returns a
// MixedType but that doesn't cause an error like ConstantArrayType.
[
'Parameter #1 $callback of static method Closure::fromCallable() expects callable(): mixed, array{\'Bug5782\\\HelloWorld\', \'sayGoodbye\'} given.',
31,
],
]);
}
Expand Down
11 changes: 8 additions & 3 deletions tests/PHPStan/Rules/Methods/data/bug-5782.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ public function sayGoodbye(): void

}

class FooWorld
{
public function bazBar(): void
{
$closure1 = \Closure::fromCallable([\Bug5782\HelloWorld::class, 'sayGoodbye']);
}
}

function baz() {
$closure1 = \Closure::fromCallable([\Bug5782\HelloWorld::class, 'sayHello']);
$closure2 = \Closure::fromCallable('\Bug5782\HelloWorld::sayHello');
$closure3 = \Closure::fromCallable([\Bug5782\HelloWorld::class, 'sayGoodbye']);
// @todo this should also error on mixed type, but doesn't?
// ConstantStringType::getCallableParametersAcceptors returns a MixedType
// but that doesn't cause an error like ConstantArrayType.
$closure4 = \Closure::fromCallable('Bug5782\HelloWorld::sayGoodbye');
}

0 comments on commit c815c71

Please sign in to comment.