Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/Testing/CompositeRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php declare(strict_types = 1);

namespace PHPStan\Testing;

use PhpParser\Node;
use PHPStan\Analyser\NodeCallbackInvoker;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\DirectRegistry;
use PHPStan\Rules\Rule;
use function get_class;

/**
* Allows testing of rules which delegate work to NodeCallbackInvoker.
*
* @implements Rule<Node>
*
* @api
*/
final class CompositeRule implements Rule
{

private DirectRegistry $registry;

public function __construct(DirectRegistry $ruleRegistry)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constructor needs @api too

{
$this->registry = $ruleRegistry;
}

public function getNodeType(): string
{
return Node::class;
}

public function processNode(Node $node, Scope&NodeCallbackInvoker $scope): array
{
$errors = [];

$nodeType = get_class($node);
foreach ($this->registry->getRules($nodeType) as $rule) {
foreach ($rule->processNode($node, $scope) as $error) {
$errors[] = $error;
}
}

return $errors;
}

}
Loading