Skip to content

Commit b60c8fb

Browse files
committed
Integration test for parent/previous/next node attributes
1 parent d77a607 commit b60c8fb

File tree

5 files changed

+71
-0
lines changed

5 files changed

+71
-0
lines changed

.github/workflows/other-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ jobs:
155155
- |
156156
cd e2e/attribute-74
157157
../../phpstan analyse -l 9 test.php -c test.neon
158+
- |
159+
cd e2e/node-connecting
160+
../../phpstan analyse -a Rule.php
158161
include:
159162
- php-version: 8.0
160163
ini-values: memory_limit=256M

e2e/node-connecting/Rule.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace NodeConnectingRule;
4+
5+
use PhpParser\Node;
6+
use PhpParser\Node\Stmt\Echo_;
7+
use PHPStan\Analyser\Scope;
8+
9+
/** @implements \PHPStan\Rules\Rule<Echo_> */
10+
class Rule implements \PHPStan\Rules\Rule
11+
{
12+
13+
public function getNodeType(): string
14+
{
15+
return Echo_::class;
16+
}
17+
18+
public function processNode(Node $node, Scope $scope): array
19+
{
20+
return [
21+
sprintf(
22+
'Parent: %s, previous: %s, next: %s',
23+
get_class($node->getAttribute('parent')),
24+
get_class($node->getAttribute('previous')),
25+
get_class($node->getAttribute('next'))
26+
),
27+
];
28+
}
29+
30+
31+
}

e2e/node-connecting/baseline.neon

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Parent\\: PhpParser\\\\Node\\\\Stmt\\\\ClassMethod, previous\\: PhpParser\\\\Node\\\\Stmt\\\\If_, next\\: PhpParser\\\\Node\\\\Stmt\\\\Do_$#"
5+
count: 1
6+
path: src/test.php
7+

e2e/node-connecting/phpstan.neon

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
includes:
2+
- phar://phpstan.phar/conf/bleedingEdge.neon
3+
- baseline.neon
4+
5+
parameters:
6+
paths:
7+
- src
8+
level: 8
9+
10+
rules:
11+
- NodeConnectingRule\Rule

e2e/node-connecting/src/test.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace NodeConnecting;
4+
5+
class Foo
6+
{
7+
8+
public function doFoo(bool $b): void
9+
{
10+
if ($b) {
11+
12+
}
13+
echo 'bar';
14+
do {
15+
break;
16+
} while ($b);
17+
}
18+
19+
}

0 commit comments

Comments
 (0)