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 b21c03d

Browse files
DynamicCallOnStaticMethodsRule - do not report for methods declared on PHPStanTestCase and TypeInferenceTestCase
1 parent ce25f06 commit b21c03d

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

‎src/Rules/StrictCalls/DynamicCallOnStaticMethodsRule.php‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
use PHPStan\Analyser\Scope;
88
use PHPStan\Rules\Rule;
99
use PHPStan\Rules\RuleLevelHelper;
10+
use PHPStan\Testing\PHPStanTestCase;
11+
use PHPStan\Testing\TypeInferenceTestCase;
1012
use PHPStan\Type\ErrorType;
1113
use PHPStan\Type\Type;
14+
use function in_array;
1215
use function sprintf;
1316

1417
class DynamicCallOnStaticMethodsRule implements Rule
@@ -53,6 +56,14 @@ static function (Type $type) use ($name): bool {
5356

5457
$methodReflection = $type->getMethod($name, $scope);
5558
if ($methodReflection->isStatic()) {
59+
$prototype = $methodReflection->getPrototype();
60+
if (in_array($prototype->getDeclaringClass()->getName(), [
61+
TypeInferenceTestCase::class,
62+
PHPStanTestCase::class,
63+
], true)) {
64+
return [];
65+
}
66+
5667
return [sprintf(
5768
'Dynamic call to static method %s::%s().',
5869
$methodReflection->getDeclaringClass()->getDisplayName(),

‎tests/Rules/StrictCalls/data/dynamic-calls-on-static-methods.php‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,16 @@ function () {
4646
$classUsingTrait->foo();
4747
$classUsingTrait->bar();
4848
};
49+
50+
class FooTest extends \PHPStan\Testing\TypeInferenceTestCase
51+
{
52+
53+
public function doFoo(): void
54+
{
55+
self::gatherAssertTypes(__FILE__);
56+
$this->gatherAssertTypes(__FILE__);
57+
self::getContainer();
58+
$this->getContainer();
59+
}
60+
61+
}

0 commit comments

Comments
(0)

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