File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed
tests/PHPStan/Rules/DeadCode Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace PHPStan \Rules \DeadCode ;
4+
5+ use PhpParser \Node ;
6+ use PHPStan \Analyser \Scope ;
7+ use PHPStan \Node \UnreachableStatementNode ;
8+ use PHPStan \Rules \Rule ;
9+ use PHPStan \Rules \RuleErrorBuilder ;
10+ use PHPStan \Testing \RuleTestCase ;
11+
12+ /**
13+ * @extends RuleTestCase<Rule>
14+ */
15+ class UnreachableStatementNextStatementsRuleTest extends RuleTestCase
16+ {
17+
18+ /**
19+ * @return Rule<Node>
20+ */
21+ protected function getRule (): Rule
22+ {
23+ return new class implements Rule {
24+
25+ public function getNodeType (): string
26+ {
27+ return UnreachableStatementNode::class;
28+ }
29+
30+ /**
31+ * @param UnreachableStatementNode $node
32+ */
33+ public function processNode (Node $ node , Scope $ scope ): array
34+ {
35+ $ totalNextStatements = count ($ node ->getNextStatements ());
36+
37+ return [
38+ RuleErrorBuilder::message (sprintf ("It has %d over first unreachable statements " , $ totalNextStatements ))
39+ ->identifier ('tests.total.next.unreachable.statement ' )
40+ ->build (),
41+ ];
42+ }
43+
44+ };
45+ }
46+
47+ public function testRule (): void
48+ {
49+ $ this ->analyse ([__DIR__ . '/data/multiple_unreachable.php ' ], [
50+ [
51+ 'It has 2 over first unreachable statements ' ,
52+ 14
53+ ],
54+ ]);
55+ }
56+
57+ }
You can’t perform that action at this time.
0 commit comments