Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Plugin / DMU / Indexer / FunctionCalls.php
1 <?php
2
3 namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Indexer;
4
5 use Drupal\drupalmoduleupgrader\IndexerBase;
6 use Pharborist\Filter;
7 use Pharborist\Parser;
8 use Pharborist\Functions\FunctionCallNode;
9 use Pharborist\NodeCollection;
10
11 /**
12  * @Indexer(
13  *  id = "function_call",
14  *  description = @Translation("Indexes all function calls in a target module."),
15  *  exclude = { "t" }
16  * )
17  */
18 class FunctionCalls extends IndexerBase {
19
20   /**
21    * {@inheritdoc}
22    */
23   public function build() {
24     /** @var \Symfony\Component\Finder\SplFileInfo $file */
25     foreach ($this->target->getFinder() as $file) {
26       $path = $file->getPathname();
27
28       $this->target
29         ->open($path)
30         ->find(Filter::isInstanceOf('\Pharborist\Functions\FunctionCallNode'))
31         ->not(function(FunctionCallNode $function_call) {
32           return in_array($function_call->getName()->getText(), $this->pluginDefinition['exclude']);
33         })
34         ->each([ $this, 'add' ]);
35     }
36   }
37
38   /**
39    * {@inheritdoc}
40    */
41   public function get($id) {
42     $all = new NodeCollection([]);
43
44     $files = $this
45       ->getQuery(['file'])
46       ->distinct(TRUE)
47       ->condition('id', $id)
48       ->execute()
49       ->fetchCol();
50
51     array_walk($files, function($file) use ($all, $id) {
52       $all->add($this->target->open($file)->find(Filter::isFunctionCall($id)));
53     });
54
55     return $all;
56   }
57
58   /**
59    * {@inheritdoc}
60    */
61   public function addFile($path) {
62     $doc = Parser::parseFile($path);
63
64     $doc
65       ->find(Filter::isInstanceOf('\Pharborist\Functions\FunctionCallNode'))
66       ->each([ $this, 'add' ]);
67   }
68
69 }