reviewer-1.2.x-dev/src/Plugin/reviewer/Review/ReviewBase.php

src/Plugin/reviewer/Review/ReviewBase.php
<?php

declare(strict_types=1);

namespace Drupal\reviewer\Plugin\reviewer\Review;

use Drupal\Core\Plugin\PluginBase;
use Drupal\reviewer\Exception\NoChecklistsException;

/**
 * Provides a base class for reviews that all reviews must extend.
 *
 * Reviews plugins contain checklists (and therefore tasks) which are run to
 * check and fix configuration.
 *
 * Create reviews in the \Drupal\my_module\Plugin\reviewer\Review namespace.
 * Review classes have the \Drupal\reviewer\Attribute\Review attribute.
 *
 * Do not override this class's methods in children. Reviews are instantiated
 * and run internally by reviewer.
 *
 * Here is an example of a review which contains multiple checklists:
 *
 * @code
 * #[Review(
 *   id: 'example',
 *   label: 'Example',
 *   checklists: [
 *     ExampleChecklistOne::class,
 *     ExampleChecklistTwo::class,
 *   ],
 * )]
 * final class Example extends ReviewBase {}
 * @endcode
 *
 * Reviews can also define a config entity type to load and pass to tasks. If
 * the config entity type supports bundles, then the checklists will be run for
 * every bundle.
 *
 * Here is an example of a review which checks all node type bundles:
 *
 * @code
 * #[Review(
 *   id: 'example',
 *   label: 'Example',
 *   checklists: [
 *     ExampleChecklistOne::class,
 *     ExampleChecklistTwo::class,
 *   ],
 *   config_entity_type: 'node_type',
 * )]
 * final class Example extends ReviewBase {}
 * @endcode
 *
 * By default, all bundles for a config entity type are loaded if the type
 * supports bundles. You may also specify bundles in the attribute.
 *
 * Here is an example of a review which checks only some node type bundles:
 *
 * @code
 * #[Review(
 *   id: 'example',
 *   label: 'Example',
 *   checklists: [
 *     ExampleChecklistOne::class,
 *     ExampleChecklistTwo::class,
 *   ],
 *   config_entity_type: 'node_type',
 *   bundles: [
 *     'article',
 *     'page',
 *   ],
 * )]
 * final class Example extends ReviewBase {}
 * @endcode
 *
 * Reviews can ignore failures and errors to suppress false-positives or special
 * cases which violate a task.
 *
 * Here is an example of a review which ignores a failure:
 *
 * @code
 * #[Review(
 *   id: 'example',
 *   label: 'Example',
 *   checklists: [
 *     ExampleChecklistOne::class,
 *     ExampleChecklistTwo::class,
 *   ],
 *   ignore: [
 *     'example.checklist.task' => 'This is ok, this project does not conform to usual standards',
 *   ],
 * )]
 * final class Example extends ReviewBase {}
 * @endcode
 *
 * @see \Drupal\reviewer\Attribute\Review
 * @see \Drupal\reviewer\Reviewer\Result\ResultInterface
 * @see \Drupal\reviewer\Reviewer\Result\CollectionResultInterface
 */
abstract class ReviewBase extends PluginBase implements ReviewPluginInterface {

  /**
   * {@inheritdoc}
   */
  public function getLabel(): string {
    return $this->configuration['label'];
  }

  /**
   * {@inheritdoc}
   */
  public function getChecklists(): array {
    return $this->configuration['checklists'] ?? throw new NoChecklistsException($this->getPluginId());
  }

  /**
   * {@inheritdoc}
   */
  public function getConfigEntityId(): string|null {
    return $this->configuration['config_entity_type'];
  }

  /**
   * {@inheritdoc}
   */
  public function getBundles(): array {
    return $this->configuration['bundles'];
  }

  /**
   * {@inheritdoc}
   */
  public function getIgnored(): array {
    return $this->configuration['ignored'] ?? [];
  }

}

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

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