forked from Hexlet/phpstan-functional-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisallowLoopsRule.php
39 lines (32 loc) · 918 Bytes
/
DisallowLoopsRule.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
<?php
namespace Hexlet\PHPStanFp\Rules\Loops;
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Rules\IdentifierRuleError;
abstract class DisallowLoopsRule implements Rule
{
private bool $disallowLoops;
public function __construct(bool $disallowLoops)
{
$this->disallowLoops = $disallowLoops;
}
/**
* @param Node $node
* @param Scope $scope
* @return IdentifierRuleError[]
*/
public function processNode(Node $node, Scope $scope): array
{
if (!$this->disallowLoops) {
return [];
}
return [
RuleErrorBuilder::message("Should not use loop {$this->getLoopType()}")
->identifier('phpstanFunctionalProgramming.disallowLoops')
->build()
];
}
abstract protected function getLoopType(): string;
}