Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Registry: support multiple rules registered by a single class
- Loading branch information
1 parent
941684d
commit 1956c7f
Showing
3 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Rules; | ||
|
||
use PhpParser\Node; | ||
use PHPStan\Analyser\Scope; | ||
|
||
class UniversalRule implements Rule | ||
{ | ||
|
||
/** @var string */ | ||
private $nodeType; | ||
|
||
/** @var callable */ | ||
private $processNodeCallback; | ||
|
||
public function __construct(string $nodeType, callable $processNodeCallback) | ||
{ | ||
$this->nodeType = $nodeType; | ||
$this->processNodeCallback = $processNodeCallback; | ||
} | ||
|
||
public function getNodeType(): string | ||
{ | ||
return $this->nodeType; | ||
} | ||
|
||
public function processNode(Node $node, Scope $scope): array | ||
{ | ||
$callback = $this->processNodeCallback; | ||
$callback($node, $scope); | ||
} | ||
|
||
} |