You are here

class Issue in Drupal 7 to 8/9 Module Upgrader 8

Hierarchy

Expanded class hierarchy of Issue

3 files declare their use of Issue
InfoFile.php in src/Plugin/DMU/Analyzer/InfoFile.php
IssueTest.php in tests/src/Unit/IssueTest.php
ReportTest.php in tests/src/Unit/ReportTest.php
1 string reference to 'Issue'
drupalmoduleupgrader_theme in ./drupalmoduleupgrader.module
Implements hook_theme().

File

src/Issue.php, line 9

Namespace

Drupal\drupalmoduleupgrader
View source
class Issue implements IssueInterface {

  /**
   * @var TargetInterface
   */
  protected $target;

  /**
   * @var string
   */
  protected $title;

  /**
   * @var string
   */
  protected $summary;

  /**
   * @var array
   */
  protected $documentation = [];

  /**
   * @var array
   */
  protected $violations = [];

  /**
   * @var AnalyzerInterface[]
   */
  protected $detectors = [];

  /**
   * @var mixed[]
   */
  protected $tags = [];

  /**
   * @var array[]
   */
  protected $fixes = [];

  /**
   * @var \cebe\markdown\Markdown
   */
  protected $parser;
  public function __construct(Target $target, $title, $summary = NULL) {
    $this->target = $target;
    $this
      ->setTitle($title);
    if (isset($summary)) {
      $this
        ->setSummary($summary);
    }
    $this->parser = new Markdown();
    $this->parser->html5 = TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function getTitle() {
    return $this->parser
      ->parseParagraph($this->title);
  }

  /**
   * {@inheritdoc}
   */
  public function setTitle($title) {
    $this->title = (string) $title;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getSummary() {
    return $this->parser
      ->parse($this->summary);
  }

  /**
   * {@inheritdoc}
   */
  public function setSummary($summary) {
    $this->summary = (string) $summary;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function addDocumentation($url, $title) {
    $this->documentation[] = [
      'url' => $url,
      'title' => $this->parser
        ->parseParagraph($title),
    ];
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getDocumentation() {
    return $this->documentation;
  }

  /**
   * {@inheritdoc}
   */
  public function addAffectedFile($file, AnalyzerInterface $detector) {
    if (empty($this->violations[$file])) {
      $this->violations[$file] = [];
    }
    $this
      ->addDetector($detector);
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function addViolation(Node $node, AnalyzerInterface $detector) {
    $file = $node
      ->getFilename();
    if ($file) {
      $this->violations[$file][] = [
        'line_number' => $node
          ->getLineNumber(),
      ];
    }
    else {
      throw new \DomainException('Cannot record an issue violation from a detached node.');
    }
    $this
      ->addDetector($detector);
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getViolations() {
    $return_violations = [];
    foreach ($this->violations as $file => $file_violations) {
      if ($file_violations) {
        foreach ($file_violations as $violation) {
          $violation['file'] = $file;
          $return_violations[] = $violation;
        }
      }
      else {
        $return_violations[] = [
          'file' => $file,
        ];
      }
    }
    return $return_violations;
  }

  /**
   * {@inheritdoc}
   */
  public function getDetectors() {
    return array_unique($this->detectors);
  }

  /**
   * {@inheritdoc}
   */
  public function hasTag($tag) {
    return array_key_exists($tag, $this->tags);
  }

  /**
   * {@inheritdoc}
   */
  public function getTag($tag) {
    return $this->tags[$tag];
  }

  /**
   * {@inheritdoc}
   */
  public function setTag($tag, $value) {
    $this->tags[$tag] = $value;
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function clearTag($tag) {
    unset($this->tags[$tag]);
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function getFixes() {
    return $this->fixes;
  }

  /**
   * {@inheritdoc}
   */
  public function addFix($fixer_id, array $configuration = []) {
    $this->fixes[] = array_merge($configuration, [
      '_plugin_id' => $fixer_id,
    ]);
    $this
      ->setTag('fixable', TRUE);
    return $this;
  }

  /**
   * Stores a reference to an issue detector, if we don't already know about it,
   * for use by getDetectors().
   *
   * @param AnalyzerInterface $detector
   */
  protected function addDetector(AnalyzerInterface $detector) {
    if ($detector instanceof PluginInspectionInterface) {
      $this->detectors[] = $detector
        ->getPluginId();
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Issue::$detectors protected property
Issue::$documentation protected property
Issue::$fixes protected property
Issue::$parser protected property
Issue::$summary protected property
Issue::$tags protected property
Issue::$target protected property
Issue::$title protected property
Issue::$violations protected property
Issue::addAffectedFile public function Marks a particular file as being affected by this issue. Overrides IssueInterface::addAffectedFile
Issue::addDetector protected function Stores a reference to an issue detector, if we don't already know about it, for use by getDetectors().
Issue::addDocumentation public function Adds a piece of documentation relevant to the issue. Overrides IssueInterface::addDocumentation
Issue::addFix public function Adds a fix for this issue. Overrides IssueInterface::addFix
Issue::addViolation public function Flags a single violation of this issue in a particular syntax node. Overrides IssueInterface::addViolation
Issue::clearTag public function Clears all values for a tag. Overrides IssueInterface::clearTag
Issue::getDetectors public function Returns the fully qualified names of every plugin which detected violations, as set by addAffectedFile() and addViolation(). Overrides IssueInterface::getDetectors
Issue::getDocumentation public function Returns all documentation as an array of arrays, each containing 'url' and 'title' keys. Overrides IssueInterface::getDocumentation
Issue::getFixes public function Gets all fixes queued for this issue. Each fix will be an array with at least a _plugin_id element, containing the plugin ID of the fixer to use. Everything else will be given to the fixer as configuration. Overrides IssueInterface::getFixes
Issue::getSummary public function Returns the issue summary. Overrides IssueInterface::getSummary
Issue::getTag public function Returns the value set for a tag. The tag value can be anything; the meaning of the value depends on the tag. Overrides IssueInterface::getTag
Issue::getTitle public function Returns the title of the issue. Overrides IssueInterface::getTitle
Issue::getViolations public function Returns all violations as an array of arrays, each of which has a 'file' key (required), and an optional 'line_number' key. Overrides IssueInterface::getViolations
Issue::hasTag public function Returns if a tag is set on the issue. Overrides IssueInterface::hasTag
Issue::setSummary public function Sets the issue summary. Overrides IssueInterface::setSummary
Issue::setTag public function Sets the value for a tag. Any existing value for the tag will be blown away. Overrides IssueInterface::setTag
Issue::setTitle public function Sets the title of the issue. Overrides IssueInterface::setTitle
Issue::__construct public function