Skip to content

Commit

Permalink
Make mixin method static if there's __callStatic() in the class
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Aug 27, 2021
1 parent 03d8312 commit 114a38f
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
Expand Up @@ -54,7 +54,6 @@ private function findMethod(ClassReflection $classReflection, string $methodName
if (
!$static
&& $classReflection->hasNativeMethod('__callStatic')
&& !$classReflection->hasNativeMethod('__call')
) {
$static = true;
}
Expand Down
8 changes: 8 additions & 0 deletions tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php
Expand Up @@ -2029,6 +2029,14 @@ public function testNonEmptyStringVerbosity(): void
]);
}

public function testBug5536(): void
{
$this->checkThisOnly = false;
$this->checkNullables = true;
$this->checkUnionTypes = true;
$this->analyse([__DIR__ . '/data/bug-5536.php'], []);
}

public function testBug5372(): void
{
if (!self::$useStaticReflectionProvider && PHP_VERSION_ID < 70400) {
Expand Down
6 changes: 6 additions & 0 deletions tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php
Expand Up @@ -445,4 +445,10 @@ public function testBug5259(): void
$this->analyse([__DIR__ . '/data/bug-5259.php'], []);
}

public function testBug5536(): void
{
$this->checkThisOnly = false;
$this->analyse([__DIR__ . '/data/bug-5536.php'], []);
}

}
47 changes: 47 additions & 0 deletions tests/PHPStan/Rules/Methods/data/bug-5536.php
@@ -0,0 +1,47 @@
<?php

namespace Bug5536;

/**
* @mixin Builder<static>
*/
class Model
{
/**
* @param array<int, mixed> $args
*/
public function __call(string $method, array $args)
{
return $this->$method;
}

/**
* @param array<int, mixed> $args
*/
public static function __callStatic(string $method, array $args)
{
return (new static)->$method(...$args);
}
}

/**
* @template TModel of Model
*/
class Builder
{
/**
* @return array<int, TModel>
*/
public function all(): array
{
return [];
}
}

class User extends Model {}

function (): void {
User::all();
$user = new User();
$user->all();
};

0 comments on commit 114a38f

Please sign in to comment.