Skip to content

Commit 114a38f

Browse files
committed
Make mixin method static if there's __callStatic() in the class
1 parent 03d8312 commit 114a38f

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

src/Reflection/Mixin/MixinMethodsClassReflectionExtension.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ private function findMethod(ClassReflection $classReflection, string $methodName
5454
if (
5555
!$static
5656
&& $classReflection->hasNativeMethod('__callStatic')
57-
&& !$classReflection->hasNativeMethod('__call')
5857
) {
5958
$static = true;
6059
}

tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,6 +2029,14 @@ public function testNonEmptyStringVerbosity(): void
20292029
]);
20302030
}
20312031

2032+
public function testBug5536(): void
2033+
{
2034+
$this->checkThisOnly = false;
2035+
$this->checkNullables = true;
2036+
$this->checkUnionTypes = true;
2037+
$this->analyse([__DIR__ . '/data/bug-5536.php'], []);
2038+
}
2039+
20322040
public function testBug5372(): void
20332041
{
20342042
if (!self::$useStaticReflectionProvider && PHP_VERSION_ID < 70400) {

tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,4 +445,10 @@ public function testBug5259(): void
445445
$this->analyse([__DIR__ . '/data/bug-5259.php'], []);
446446
}
447447

448+
public function testBug5536(): void
449+
{
450+
$this->checkThisOnly = false;
451+
$this->analyse([__DIR__ . '/data/bug-5536.php'], []);
452+
}
453+
448454
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace Bug5536;
4+
5+
/**
6+
* @mixin Builder<static>
7+
*/
8+
class Model
9+
{
10+
/**
11+
* @param array<int, mixed> $args
12+
*/
13+
public function __call(string $method, array $args)
14+
{
15+
return $this->$method;
16+
}
17+
18+
/**
19+
* @param array<int, mixed> $args
20+
*/
21+
public static function __callStatic(string $method, array $args)
22+
{
23+
return (new static)->$method(...$args);
24+
}
25+
}
26+
27+
/**
28+
* @template TModel of Model
29+
*/
30+
class Builder
31+
{
32+
/**
33+
* @return array<int, TModel>
34+
*/
35+
public function all(): array
36+
{
37+
return [];
38+
}
39+
}
40+
41+
class User extends Model {}
42+
43+
function (): void {
44+
User::all();
45+
$user = new User();
46+
$user->all();
47+
};

0 commit comments

Comments
 (0)