forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhpdocCommentRule.php
More file actions
52 lines (41 loc) · 1.03 KB
/
PhpdocCommentRule.php
File metadata and controls
52 lines (41 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Playground;
use Nette\Utils\Strings;
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Node\VirtualNode;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use function str_starts_with;
/**
* @implements Rule<Node>
*/
final class PhpdocCommentRule implements Rule
{
public function getNodeType(): string
{
return Node::class;
}
public function processNode(Node $node, Scope $scope): array
{
if ($node instanceof VirtualNode) {
return [];
}
$comments = $node->getComments();
$errors = [];
foreach ($comments as $comment) {
foreach (['/**', '//', '#'] as $startTag) {
if (str_starts_with($comment->getText(), $startTag)) {
continue 2;
}
}
if (Strings::match($comment->getText(), '{(\s|^)@\w+(\s|$)}') === null) {
continue;
}
$errors[] = RuleErrorBuilder::message('Comment contains PHPDoc tag but does not start with /** prefix.')
->identifier('phpstanPlayground.phpDoc')
->build();
}
return $errors;
}
}