Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Rules/NoDynamicNameRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public function processNode(Node $node, Scope $scope): array
}

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

if (! $node->name instanceof Expr) {
return [];
Expand Down
13 changes: 13 additions & 0 deletions tests/Rules/NoDynamicNameRule/Fixture/SkipMagicGet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Symplify\PHPStanRules\Tests\Rules\NoDynamicNameRule\Fixture;

final class SkipMagicGet
{
public function __get($name)
{
return $this->{$name};
}
}
1 change: 1 addition & 0 deletions tests/Rules/NoDynamicNameRule/NoDynamicNameRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static function provideData(): Iterator
yield [__DIR__ . '/Fixture/SkipInvokable.php', []];
yield [__DIR__ . '/Fixture/SkipClosure.php', []];
yield [__DIR__ . '/Fixture/SkipCallable.php', []];
yield [__DIR__ . '/Fixture/SkipMagicGet.php', []];
yield [__DIR__ . '/Fixture/SkipCallableUnion.php', []];
yield [__DIR__ . '/Fixture/SkipNullableClosure.php', []];
yield [__DIR__ . '/Fixture/SkipImmediatelyInvokedFunctionExpression.php', []];
Expand Down