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 22
33namespace PHPStan \Rules \Playground ;
44
5+ use Nette \Utils \Strings ;
56use PhpParser \Node ;
67use PHPStan \Analyser \Scope ;
78use PHPStan \Node \VirtualNode ;
@@ -31,16 +32,16 @@ public function processNode(Node $node, Scope $scope): array
3132
3233 $ errors = [];
3334 foreach ($ comments as $ comment ) {
34- if (!str_contains ($ comment ->getText (), '@ ' )) {
35- continue ;
36- }
37-
3835 foreach (['/** ' , '// ' , '# ' ] as $ startTag ) {
3936 if (str_starts_with ($ comment ->getText (), $ startTag )) {
4037 continue 2 ;
4138 }
4239 }
4340
41+ if (!Strings::match ($ comment ->getText (), '{(\s|^)@\w+(\s|$)} ' )) {
42+ continue ;
43+ }
44+
4445 $ errors [] = RuleErrorBuilder::message ('Comment contains PHPDoc tag but does not start with /** prefix. ' )
4546 ->identifier ('phpstanPlayground.phpDoc ' )
4647 ->build ();
Original file line number Diff line number Diff line change @@ -35,4 +35,15 @@ public function getBar(): FooInterface
3535
3636 // this should not error: @var
3737 # this should not error: @var
38+
39+ /*
40+ * comments which look like phpdoc should be ignored
41+ *
42+ * x@x.cz
43+ * 10 amps @ 1 volt
44+ */
45+ public function ignoreComments (): FooInterface
46+ {
47+ return $ this ->foo ;
48+ }
3849}
You can’t perform that action at this time.
0 commit comments