File tree Expand file tree Collapse file tree 2 files changed +16
-4
lines changed
tests/PHPStan/Rules/Playground/data Expand file tree Collapse file tree 2 files changed +16
-4
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace PHPStan \Rules \Playground ;
4
4
5
+ use Nette \Utils \Strings ;
5
6
use PhpParser \Node ;
6
7
use PHPStan \Analyser \Scope ;
7
8
use PHPStan \Node \VirtualNode ;
@@ -31,16 +32,16 @@ public function processNode(Node $node, Scope $scope): array
31
32
32
33
$ errors = [];
33
34
foreach ($ comments as $ comment ) {
34
- if (!str_contains ($ comment ->getText (), '@ ' )) {
35
- continue ;
36
- }
37
-
38
35
foreach (['/** ' , '// ' , '# ' ] as $ startTag ) {
39
36
if (str_starts_with ($ comment ->getText (), $ startTag )) {
40
37
continue 2 ;
41
38
}
42
39
}
43
40
41
+ if (!Strings::match ($ comment ->getText (), '{(\s|^)@\w+(\s|$)} ' )) {
42
+ continue ;
43
+ }
44
+
44
45
$ errors [] = RuleErrorBuilder::message ('Comment contains PHPDoc tag but does not start with /** prefix. ' )
45
46
->identifier ('phpstanPlayground.phpDoc ' )
46
47
->build ();
Original file line number Diff line number Diff line change @@ -35,4 +35,15 @@ public function getBar(): FooInterface
35
35
36
36
// this should not error: @var
37
37
# this should not error: @var
38
+
39
+ /*
40
+ * comments which look like phpdoc should be ignored
41
+ *
42
+
43
+ * 10 amps @ 1 volt
44
+ */
45
+ public function ignoreComments (): FooInterface
46
+ {
47
+ return $ this ->foo ;
48
+ }
38
49
}
You can’t perform that action at this time.
0 commit comments