-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunctionDocumentationIsRequiredRule.php
59 lines (53 loc) · 1.47 KB
/
FunctionDocumentationIsRequiredRule.php
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
53
54
55
56
57
58
59
<?php
declare(strict_types=1);
namespace Oneserv\PHPStan\Rules\Functions;
use Oneserv\PHPStan\Services\DocCommentHelper;
use PhpParser\Node;
use PhpParser\Node\Stmt\Function_;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use PHPStan\ShouldNotHappenException;
/**
* Class FunctionDocumentationIsRequiredRule
*
* @implements Rule<Function_>
* @see \Tests\Oneserv\PHPStan\Rules\Functions\FunctionDocumentationIsRequiredRuleTest
*/
class FunctionDocumentationIsRequiredRule implements Rule
{
/**
* FunctionDocumentationIsRequiredRule constructor.
*
* @param DocCommentHelper $docCommentHelper
*/
public function __construct(private readonly DocCommentHelper $docCommentHelper)
{
}
/**
* @inheritDoc
*/
public function getNodeType(): string
{
return Function_::class;
}
/**
* @inheritDoc
* @throws ShouldNotHappenException
*/
public function processNode(Node $node, Scope $scope): array
{
/** @var Function_ $node */
$docComment = (string)$node->getDocComment();
$docComment = $this->docCommentHelper->removeCommentDelimiters($docComment);
$docComment = $this->docCommentHelper->cleanUpDocComment($docComment);
if ($docComment === '') {
return [
sprintf(
'Function %s has no/an empty doc comment.',
$node->name->name
),
];
}
return [];
}
}