reviewer-1.2.x-dev/src/Attribute/Checklist.php

src/Attribute/Checklist.php
<?php

declare(strict_types=1);

namespace Drupal\reviewer\Attribute;

use Drupal\reviewer\Reviewer\Task\TaskInterface;

/**
 * Attribute definition for checklists.
 */
#[\Attribute(\Attribute::TARGET_CLASS)]
final readonly class Checklist {

  /**
   * A checklist is a collection of tasks that can be reused across reviews.
   *
   * @param string $id
   *   The checklist unique ID.
   * @param class-string<\Drupal\reviewer\Reviewer\Task\TaskInterface>[] $tasks
   *   The tasks to run on this checklist.
   */
  public function __construct(
    private string $id,
    private array $tasks,
  ) {}

  /**
   * Get the checklist ID.
   */
  public function getId(): string {
    return $this->id;
  }

  /**
   * Get the checklist task objects.
   *
   * @return class-string<\Drupal\reviewer\Reviewer\Task\TaskInterface>[]
   */
  public function getTasks(): array {
    // @todo Replace with array_all() when PHP 8.4 is the minimum supported
    //   version.
    foreach ($this->tasks as $task) {
      // This is an intended runtime check which PHPStan infers correctly but
      // does not know why it exists.
      // @phpstan-ignore function.alreadyNarrowedType
      if (!\is_a($task, TaskInterface::class, TRUE)) {
        throw new \InvalidArgumentException(sprintf('Task %s in checklist %s is not of type %s.', $task, $this->getId(), TaskInterface::class));
      }
    }
    return $this->tasks;
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc