File tree Expand file tree Collapse file tree 4 files changed +79
-0
lines changed
tests/PHPStan/CustomPHPStanRule Expand file tree Collapse file tree 4 files changed +79
-0
lines changed Original file line number Diff line number Diff line change 1+ composer.lock
2+ /vendor
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " rector/rector-compat-tests" ,
3+ "description" : " Tests for compatibility with PHPStand and PHPUnit preload magic" ,
4+ "require-dev" : {
5+ "php" : " ^8.2" ,
6+ "phpunit/phpunit" : " ^9.6|^10.*|^11.*|^12.*" ,
7+ "rector/rector" : " ^2.2" ,
8+ "phpstan/phpstan" : " ^2.1"
9+ },
10+ "autoload" : {
11+ "psr-4" : {
12+ "Rector\\ RectorCompatTests\\ " : " src"
13+ }
14+ },
15+ "autoload-dev" : {
16+ "psr-4" : {
17+ "Rector\\ RectorCompatTests\\ Tests\\ " : " tests"
18+ }
19+ }
20+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Rector \RectorCompatTests \PHPStan ;
6+
7+ use PhpParser \Node ;
8+ use PhpParser \Node \Stmt \Class_ ;
9+ use PHPStan \Analyser \Scope ;
10+ use PHPStan \Rules \Rule ;
11+ use PHPStan \Rules \RuleError ;
12+ use PHPStan \Rules \RuleErrorBuilder ;
13+
14+ /**
15+ * @implements Rule<Class_>
16+ */
17+ final class CustomPHPStanRule implements Rule
18+ {
19+ public function getNodeType (): string
20+ {
21+ return Class_::class;
22+ }
23+
24+ /**
25+ * @param Class_ $node
26+ * @return RuleError[]
27+ */
28+ public function processNode (Node $ node , Scope $ scope ): array
29+ {
30+ if ($ node ->isFinal ()) {
31+ return [];
32+ }
33+
34+ $ ruleErrorMessage = RuleErrorBuilder::message (
35+ sprintf ('Class "%s" is not final. ' , $ node ->name ->toString ())
36+ )->build ();
37+
38+ return [$ ruleErrorMessage ];
39+ }
40+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Rector \RectorCompatTests \Tests \PHPStan \CustomPHPStanRule ;
4+
5+ use PHPStan \Rules \Rule ;
6+ use PHPStan \Testing \RuleTestCase ;
7+ use Rector \RectorCompatTests \PHPStan \CustomPHPStanRule ;
8+
9+ final class CustomPHPStanRuleTest extends RuleTestCase
10+ {
11+ // @todo
12+
13+ protected function getRule (): Rule
14+ {
15+ return new CustomPHPStanRule ();
16+ }
17+ }
You can’t perform that action at this time.
0 commit comments