Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Plugin / DMU / Analyzer / InfoFile.php
1 <?php
2
3 namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Analyzer;
4
5 use Drupal\drupalmoduleupgrader\AnalyzerBase;
6 use Drupal\drupalmoduleupgrader\Issue;
7 use Drupal\drupalmoduleupgrader\TargetInterface;
8
9 /**
10  * @Analyzer(
11  *  id = "info",
12  *  description = @Translation("Analyzes Drupal 7 info files."),
13  *  documentation = {
14  *    {
15  *      "url" = "https://www.drupal.org/node/1935708",
16  *      "title" = @Translation("`.info` files are now `.info.yml` files")
17  *    }
18  *  }
19  * )
20  */
21 class InfoFile extends AnalyzerBase {
22
23   /**
24    * {@inheritdoc}
25    */
26   public function analyze(TargetInterface $target) {
27     $issues = [];
28     $info_file = $target->getPath('.info');
29     if (! file_exists($info_file)) {
30       return $issues;
31     }
32
33     $info = \Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\InfoToYAML::parseInfo($info_file);
34     if (empty($info)) {
35       throw new \RuntimeException('Cannot parse info file ' . $info_file);
36     }
37
38     $doc = $this->pluginDefinition['documentation'][0];
39     if ($info['core'] != '8.x') {
40       $issues['core'] = new Issue($target, $this->t("Module info files' `core` key must have a value of `8.x`."));
41       $issues['core']->addDocumentation($doc['url'], $doc['title']);
42     }
43     if (empty($info['type'])) {
44       $issues['type'] = new Issue($target, $this->t('Info files must contain a `type` key.'));
45       $issues['type']->addDocumentation($doc['url'] . '#type', $doc['title']);
46     }
47     if (isset($info['dependencies'])) {
48       $issues['dependencies'] = new Issue($target, $this->t('Many common dependencies have moved into core.'));
49       $issues['dependencies']->addDocumentation($doc['url'], $doc['title']);
50     }
51     if (isset($info['files'])) {
52       $issues['files'] = new Issue($target, $this->t('Modules no longer declare classes in their info file.'));
53       $issues['files']->addDocumentation($doc['url'] . '#files', $doc['title']);
54     }
55     if (isset($info['configure'])) {
56       $issues['configure'] = new Issue($target, $this->t("Module info files' `configure` key must be a route name, not a path."));
57       $issues['configure']->addDocumentation($doc['url'] . '#configure', $doc['title']);
58     }
59
60     /** @var \Drupal\drupalmoduleupgrader\IssueInterface $issue */
61     foreach ($issues as $key => $issue) {
62       $issue->setTag('error_level', 'error');
63       $issue->setTag('category', ['info']);
64       $issue->addAffectedFile($info_file, $this);
65     }
66
67     return $issues;
68   }
69
70 }