Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6db6c4b

Browse files
committed
Notes on questions for next steps
1 parent c5a6e8b commit 6db6c4b

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

‎src/Type/Constant/ConstantArrayType.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,12 @@ public function equals(Type $type): bool
316316

317317
public function isCallable(): TrinaryLogic
318318
{
319+
// @todo is there a way to fetch the full scope here.
320+
// An OutOfClassScope causes frivolous errors when checking if a
321+
// non-static method was invoked statically in its own class, which
322+
// is allowed per: https://3v4l.org/mTa9S.
323+
// Should add an optional scope parameter to isCallable and if null,
324+
// create a new OutOfClassScope instance.
319325
$typeAndMethod = $this->findTypeAndMethodName(new OutOfClassScope());
320326
if ($typeAndMethod === null) {
321327
return TrinaryLogic::createNo();

‎tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,11 +450,18 @@ public function testBug5782(): void
450450
$this->analyse([__DIR__ . '/data/bug-5782.php'], [
451451
[
452452
'Parameter #1 $callback of static method Closure::fromCallable() expects callable(): mixed, array{\'Bug5782\\\HelloWorld\', \'sayGoodbye\'} given.',
453-
22,
453+
23,
454454
],
455455
[
456456
'Parameter #1 $callback of static method Closure::fromCallable() expects callable(): mixed, array{\'Bug5782\\\HelloWorld\', \'sayGoodbye\'} given.',
457-
26,
457+
30,
458+
],
459+
// @todo this should also error on mixed type, but doesn't?
460+
// ConstantStringType::getCallableParametersAcceptors returns a
461+
// MixedType but that doesn't cause an error like ConstantArrayType.
462+
[
463+
'Parameter #1 $callback of static method Closure::fromCallable() expects callable(): mixed, array{\'Bug5782\\\HelloWorld\', \'sayGoodbye\'} given.',
464+
31,
458465
],
459466
]);
460467
}

‎tests/PHPStan/Rules/Methods/data/bug-5782.php‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@ public function sayGoodbye(): void
1616

1717
}
1818

19+
class FooWorld
20+
{
21+
public function bazBar(): void
22+
{
23+
$closure1 = \Closure::fromCallable([\Bug5782\HelloWorld::class, 'sayGoodbye']);
24+
}
25+
}
26+
1927
function baz() {
2028
$closure1 = \Closure::fromCallable([\Bug5782\HelloWorld::class, 'sayHello']);
2129
$closure2 = \Closure::fromCallable('\Bug5782\HelloWorld::sayHello');
2230
$closure3 = \Closure::fromCallable([\Bug5782\HelloWorld::class, 'sayGoodbye']);
23-
// @todo this should also error on mixed type, but doesn't?
24-
// ConstantStringType::getCallableParametersAcceptors returns a MixedType
25-
// but that doesn't cause an error like ConstantArrayType.
2631
$closure4 = \Closure::fromCallable('Bug5782\HelloWorld::sayGoodbye');
2732
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /