FunctionCalls.php in Drupal 7 to 8/9 Module Upgrader 8
File
src/Plugin/DMU/Indexer/FunctionCalls.php
View source
<?php
namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Indexer;
use Drupal\drupalmoduleupgrader\IndexerBase;
use Pharborist\Filter;
use Pharborist\Parser;
use Pharborist\Functions\FunctionCallNode;
use Pharborist\NodeCollection;
class FunctionCalls extends IndexerBase {
public function build() {
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',
]);
}
}
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;
}
public function addFile($path) {
$doc = Parser::parseFile($path);
$doc
->find(Filter::isInstanceOf('\\Pharborist\\Functions\\FunctionCallNode'))
->each([
$this,
'add',
]);
}
}
Classes
Name |
Description |
FunctionCalls |
Plugin annotation
@Indexer(
id = "function_call",
description = @Translation("Indexes all function calls in a target module."),
exclude = { "t" }
) |