Skip to content

Commit 38e3a6e

Browse files
authored
skip magic methods in NoDynamicNameRule, as dynamic name expected there (#256)
1 parent 84dcc33 commit 38e3a6e

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/Rules/NoDynamicNameRule.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ public function processNode(Node $node, Scope $scope): array
6565
}
6666

6767
if ($node instanceof MethodCall || $node instanceof StaticCall || $node instanceof FuncCall || $node instanceof PropertyFetch) {
68+
// skip magic calls, as dynamic names expected
69+
if (in_array($scope->getFunctionName(), ['__get', '__set'], true)) {
70+
return [];
71+
}
6872

6973
if (! $node->name instanceof Expr) {
7074
return [];
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symplify\PHPStanRules\Tests\Rules\NoDynamicNameRule\Fixture;
6+
7+
final class SkipMagicGet
8+
{
9+
public function __get($name)
10+
{
11+
return $this->{$name};
12+
}
13+
}

tests/Rules/NoDynamicNameRule/NoDynamicNameRuleTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public static function provideData(): Iterator
3838
yield [__DIR__ . '/Fixture/SkipInvokable.php', []];
3939
yield [__DIR__ . '/Fixture/SkipClosure.php', []];
4040
yield [__DIR__ . '/Fixture/SkipCallable.php', []];
41+
yield [__DIR__ . '/Fixture/SkipMagicGet.php', []];
4142
yield [__DIR__ . '/Fixture/SkipCallableUnion.php', []];
4243
yield [__DIR__ . '/Fixture/SkipNullableClosure.php', []];
4344
yield [__DIR__ . '/Fixture/SkipImmediatelyInvokedFunctionExpression.php', []];

0 commit comments

Comments
 (0)