Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NodeScopeResolver: call nodeCallback for all attribute-related nodes
- Loading branch information
Showing
8 changed files
with
299 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Node; | ||
|
||
use PhpParser\Node; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Rules\Rule; | ||
|
||
/** | ||
* @implements Rule<Node\Arg> | ||
*/ | ||
class AttributeArgRule implements Rule | ||
{ | ||
|
||
public const ERROR_MESSAGE = 'Found Arg'; | ||
|
||
public function getNodeType(): string | ||
{ | ||
return Node\Arg::class; | ||
} | ||
|
||
/** | ||
* @param Node\Arg $node | ||
* @return string[] | ||
*/ | ||
public function processNode(Node $node, Scope $scope): array | ||
{ | ||
return [self::ERROR_MESSAGE]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Node; | ||
|
||
use PhpParser\Node; | ||
use PHPStan\Rules\Rule; | ||
use PHPStan\Testing\RuleTestCase; | ||
|
||
/** | ||
* @extends RuleTestCase<Rule> | ||
*/ | ||
class AttributeArgRuleTest extends RuleTestCase | ||
{ | ||
|
||
/** | ||
* @return Rule<Node\Arg> | ||
*/ | ||
protected function getRule(): Rule | ||
{ | ||
return new AttributeArgRule(); | ||
} | ||
|
||
public function dataRule(): iterable | ||
{ | ||
yield [ | ||
__DIR__ . '/data/attributes.php', | ||
AttributeArgRule::ERROR_MESSAGE, | ||
[8, 16, 20, 23, 26, 27, 34, 40], | ||
]; | ||
} | ||
|
||
/** | ||
* @param int[] $lines | ||
* @dataProvider dataRule | ||
*/ | ||
public function testRule(string $file, string $expectedError, array $lines): void | ||
{ | ||
$errors = []; | ||
foreach ($lines as $line) { | ||
$errors[] = [$expectedError, $line]; | ||
} | ||
$this->analyse([$file], $errors); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Node; | ||
|
||
use PhpParser\Node; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Rules\Rule; | ||
|
||
/** | ||
* @implements Rule<Node\AttributeGroup> | ||
*/ | ||
class AttributeGroupRule implements Rule | ||
{ | ||
|
||
public const ERROR_MESSAGE = 'Found AttributeGroup'; | ||
|
||
public function getNodeType(): string | ||
{ | ||
return Node\AttributeGroup::class; | ||
} | ||
|
||
/** | ||
* @param Node\AttributeGroup $node | ||
* @return string[] | ||
*/ | ||
public function processNode(Node $node, Scope $scope): array | ||
{ | ||
return [self::ERROR_MESSAGE]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Node; | ||
|
||
use PhpParser\Node; | ||
use PHPStan\Rules\Rule; | ||
use PHPStan\Testing\RuleTestCase; | ||
|
||
/** | ||
* @extends RuleTestCase<Rule> | ||
*/ | ||
class AttributeGroupRuleTest extends RuleTestCase | ||
{ | ||
|
||
/** | ||
* @return Rule<Node\AttributeGroup> | ||
*/ | ||
protected function getRule(): Rule | ||
{ | ||
return new AttributeGroupRule(); | ||
} | ||
|
||
public function dataRule(): iterable | ||
{ | ||
yield [ | ||
__DIR__ . '/data/attributes.php', | ||
AttributeGroupRule::ERROR_MESSAGE, | ||
[8, 16, 20, 23, 26, 27, 34, 40], | ||
]; | ||
} | ||
|
||
/** | ||
* @param int[] $lines | ||
* @dataProvider dataRule | ||
*/ | ||
public function testRule(string $file, string $expectedError, array $lines): void | ||
{ | ||
$errors = []; | ||
foreach ($lines as $line) { | ||
$errors[] = [$expectedError, $line]; | ||
} | ||
$this->analyse([$file], $errors); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Node; | ||
|
||
use PhpParser\Node; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\Rules\Rule; | ||
|
||
/** | ||
* @implements Rule<Node\Attribute> | ||
*/ | ||
class AttributeRule implements Rule | ||
{ | ||
|
||
public const ERROR_MESSAGE = 'Found Attribute'; | ||
|
||
public function getNodeType(): string | ||
{ | ||
return Node\Attribute::class; | ||
} | ||
|
||
/** | ||
* @param Node\Attribute $node | ||
* @return string[] | ||
*/ | ||
public function processNode(Node $node, Scope $scope): array | ||
{ | ||
return [self::ERROR_MESSAGE]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Node; | ||
|
||
use PhpParser\Node; | ||
use PHPStan\Rules\Rule; | ||
use PHPStan\Testing\RuleTestCase; | ||
|
||
/** | ||
* @extends RuleTestCase<Rule> | ||
*/ | ||
class AttributeRuleTest extends RuleTestCase | ||
{ | ||
|
||
/** | ||
* @return Rule<Node\Attribute> | ||
*/ | ||
protected function getRule(): Rule | ||
{ | ||
return new AttributeRule(); | ||
} | ||
|
||
public function dataRule(): iterable | ||
{ | ||
yield [ | ||
__DIR__ . '/data/attributes.php', | ||
AttributeRule::ERROR_MESSAGE, | ||
[8, 16, 20, 23, 26, 27, 34, 40], | ||
]; | ||
} | ||
|
||
/** | ||
* @param int[] $lines | ||
* @dataProvider dataRule | ||
*/ | ||
public function testRule(string $file, string $expectedError, array $lines): void | ||
{ | ||
$errors = []; | ||
foreach ($lines as $line) { | ||
$errors[] = [$expectedError, $line]; | ||
} | ||
$this->analyse([$file], $errors); | ||
} | ||
|
||
} |
Oops, something went wrong.