Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Plugin / DMU / Analyzer / DB.php
1 <?php
2
3 namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Analyzer;
4
5 use Drupal\drupalmoduleupgrader\AnalyzerBase;
6 use Drupal\drupalmoduleupgrader\TargetInterface;
7 use Pharborist\Functions\FunctionCallNode;
8 use Pharborist\Types\StringNode;
9
10 /**
11  * @Analyzer(
12  *  id = "_db",
13  *  message = @Translation("Certain database tables have been removed."),
14  *  tags = {
15  *    "category" = { "db" }
16     },
17  *  deriver = "\Drupal\drupalmoduleupgrader\Plugin\DMU\Analyzer\DBDeriver"
18  * )
19  */
20 class DB extends AnalyzerBase {
21
22   /**
23    * Tables which will cause the function call to be commented out.
24    *
25    * @var string[]
26    */
27   protected static $forbiddenTables = ['variable'];
28
29   /**
30    * {@inheritdoc}
31    */
32   public function analyze(TargetInterface $target) {
33     $function_calls = $target
34       ->getIndexer('function_call')
35       ->get($this->pluginDefinition['function'] ?: $this->getPluginId())
36       ->filter(function(FunctionCallNode $function_call) {
37         $arguments = $function_call->getArguments();
38         return $arguments[0] instanceof StringNode && in_array($arguments[0]->toValue(), self::$forbiddenTables);
39       });
40
41     $issues = [];
42     if ($function_calls->count() > 0) {
43       $issue = $this->buildIssue($target);
44       $function_calls->each(function(FunctionCallNode $function_call) use ($issue) {
45         $issue->addViolation($function_call, $this);
46       });
47       $issues[] = $issue;
48     }
49
50     return $issues;
51   }
52
53 }