reviewer-1.2.x-dev/src/Reviewer/Review/Review.php
src/Reviewer/Review/Review.php
<?php
declare(strict_types=1);
namespace Drupal\reviewer\Reviewer\Review;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\reviewer\Reviewer\Action;
use Drupal\reviewer\Reviewer\Result\CollectionResultInterface;
use Drupal\reviewer\Reviewer\Result\ResultFactoryInterface;
use Drupal\reviewer\Reviewer\Status\Status;
/**
* A review.
*
* Reviews are created internally from review plugins by the review builder,
* after which they can be run.
*
* @see \Drupal\reviewer\Reviewer\Review\ReviewBuilderInterface
* @see \Drupal\reviewer\Reviewer\Review\ReviewFactoryInterface
* @see \Drupal\reviewer\Reviewer\Review\ReviewRunnerInterface
*/
final readonly class Review implements ReviewInterface {
private CollectionResultInterface $results;
/**
* Constructor.
*
* @param array<string, \Drupal\reviewer\Reviewer\Checklist\ChecklistInterface> $checklists
* @param array{id: string, reason: string}[] $ignored
*/
public function __construct(
private string $id,
private string $label,
private array $checklists,
private array $ignored,
private ResultFactoryInterface $resultFactory,
private ConfigEntityInterface|null $configEntity = NULL,
) {
$this->results = $this->resultFactory->createCollection($this->getId());
}
/**
* {@inheritdoc}
*
* @throws \Drupal\reviewer\Exception\NoChecklistsException
*/
public function run(Action $action): ReviewInterface {
foreach ($this->getChecklists() as $checklist) {
$checklist->run($action);
$this->results->add($checklist->getResults());
}
return $this;
}
/**
* {@inheritdoc}
*/
public function getId(): string {
return $this->id;
}
/**
* {@inheritdoc}
*/
public function resultId(): string {
return $this->id;
}
/**
* {@inheritdoc}
*/
public function getLabel(): string {
return $this->label;
}
/**
* {@inheritdoc}
*/
public function getChecklists(): array {
return $this->checklists;
}
/**
* {@inheritdoc}
*/
public function getConfigEntity(): ConfigEntityInterface|null {
return $this->configEntity;
}
/**
* {@inheritdoc}
*/
public function getIgnored(): array {
return $this->ignored;
}
/**
* {@inheritdoc}
*/
public function getStatus(): Status {
return $this->getResults()->getStatus();
}
/**
* {@inheritdoc}
*/
public function getResults(): CollectionResultInterface {
return $this->results;
}
}
