reviewer-1.2.x-dev/src/Reviewer/Checklist/ChecklistFactory.php
src/Reviewer/Checklist/ChecklistFactory.php
<?php
declare(strict_types=1);
namespace Drupal\reviewer\Reviewer\Checklist;
use Drupal\reviewer\Reviewer\Result\ResultFactoryInterface;
use Drupal\reviewer\Reviewer\Task\TaskFactoryInterface;
/**
* Creates checklists.
*/
final readonly class ChecklistFactory implements ChecklistFactoryInterface {
// phpcs:ignore Drupal.Commenting.FunctionComment.Missing
public function __construct(
private ResultFactoryInterface $resultFactory,
private TaskFactoryInterface $taskFactory,
) {}
/**
* {@inheritdoc}
*/
public function create(string $class): ChecklistInterface {
// This is an intended runtime check which PHPStan infers correctly but does
// not know why it exists.
// @phpstan-ignore function.alreadyNarrowedType
if (!\is_a($class, ChecklistInterface::class, TRUE)) {
throw new \InvalidArgumentException(sprintf('Class %s must be an instance of %s.', $class, ChecklistInterface::class));
}
return new $class(
$this->resultFactory,
$this->taskFactory,
);
}
}
