Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Plugin / DMU / Indexer / FunctionCalls.php
diff --git a/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Indexer/FunctionCalls.php b/web/modules/contrib/drupalmoduleupgrader/src/Plugin/DMU/Indexer/FunctionCalls.php
new file mode 100644 (file)
index 0000000..cc5ac78
--- /dev/null
@@ -0,0 +1,69 @@
+<?php
+
+namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Indexer;
+
+use Drupal\drupalmoduleupgrader\IndexerBase;
+use Pharborist\Filter;
+use Pharborist\Parser;
+use Pharborist\Functions\FunctionCallNode;
+use Pharborist\NodeCollection;
+
+/**
+ * @Indexer(
+ *  id = "function_call",
+ *  description = @Translation("Indexes all function calls in a target module."),
+ *  exclude = { "t" }
+ * )
+ */
+class FunctionCalls extends IndexerBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function build() {
+    /** @var \Symfony\Component\Finder\SplFileInfo $file */
+    foreach ($this->target->getFinder() as $file) {
+      $path = $file->getPathname();
+
+      $this->target
+        ->open($path)
+        ->find(Filter::isInstanceOf('\Pharborist\Functions\FunctionCallNode'))
+        ->not(function(FunctionCallNode $function_call) {
+          return in_array($function_call->getName()->getText(), $this->pluginDefinition['exclude']);
+        })
+        ->each([ $this, 'add' ]);
+    }
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function get($id) {
+    $all = new NodeCollection([]);
+
+    $files = $this
+      ->getQuery(['file'])
+      ->distinct(TRUE)
+      ->condition('id', $id)
+      ->execute()
+      ->fetchCol();
+
+    array_walk($files, function($file) use ($all, $id) {
+      $all->add($this->target->open($file)->find(Filter::isFunctionCall($id)));
+    });
+
+    return $all;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function addFile($path) {
+    $doc = Parser::parseFile($path);
+
+    $doc
+      ->find(Filter::isInstanceOf('\Pharborist\Functions\FunctionCallNode'))
+      ->each([ $this, 'add' ]);
+  }
+
+}