3 namespace Drupal\drupalmoduleupgrader;
5 use cebe\markdown\Markdown;
6 use Drupal\Component\Plugin\PluginInspectionInterface;
9 class Issue implements IssueInterface {
12 * @var TargetInterface
29 protected $documentation = [];
34 protected $violations = [];
37 * @var AnalyzerInterface[]
39 protected $detectors = [];
49 protected $fixes = [];
52 * @var \cebe\markdown\Markdown
56 public function __construct(Target $target, $title, $summary = NULL) {
57 $this->target = $target;
58 $this->setTitle($title);
60 if (isset($summary)) {
61 $this->setSummary($summary);
64 $this->parser = new Markdown();
65 $this->parser->html5 = TRUE;
71 public function getTitle() {
72 return $this->parser->parseParagraph($this->title);
78 public function setTitle($title) {
79 $this->title = (string) $title;
86 public function getSummary() {
87 return $this->parser->parse($this->summary);
93 public function setSummary($summary) {
94 $this->summary = (string) $summary;
101 public function addDocumentation($url, $title) {
102 $this->documentation[] = [
104 'title' => $this->parser->parseParagraph($title),
112 public function getDocumentation() {
113 return $this->documentation;
119 public function addAffectedFile($file, AnalyzerInterface $detector) {
120 if (empty($this->violations[$file])) {
121 $this->violations[$file] = [];
123 $this->addDetector($detector);
130 public function addViolation(Node $node, AnalyzerInterface $detector) {
131 $file = $node->getFilename();
133 $this->violations[$file][] = [
134 'line_number' => $node->getLineNumber(),
138 throw new \DomainException('Cannot record an issue violation from a detached node.');
140 $this->addDetector($detector);
148 public function getViolations() {
149 $return_violations = [];
151 foreach ($this->violations as $file => $file_violations) {
152 if ($file_violations) {
153 foreach ($file_violations as $violation) {
154 $violation['file'] = $file;
155 $return_violations[] = $violation;
159 $return_violations[] = ['file' => $file];
163 return $return_violations;
169 public function getDetectors() {
170 return array_unique($this->detectors);
176 public function hasTag($tag) {
177 return array_key_exists($tag, $this->tags);
183 public function getTag($tag) {
184 return $this->tags[$tag];
190 public function setTag($tag, $value) {
191 $this->tags[$tag] = $value;
198 public function clearTag($tag) {
199 unset($this->tags[$tag]);
206 public function getFixes() {
213 public function addFix($fixer_id, array $configuration = []) {
214 $this->fixes[] = array_merge($configuration, ['_plugin_id' => $fixer_id]);
215 $this->setTag('fixable', TRUE);
220 * Stores a reference to an issue detector, if we don't already know about it,
221 * for use by getDetectors().
223 * @param AnalyzerInterface $detector
225 protected function addDetector(AnalyzerInterface $detector) {
226 if ($detector instanceof PluginInspectionInterface) {
227 $this->detectors[] = $detector->getPluginId();