You are here

public function Constants::getUsages in Drupal 7 to 8/9 Module Upgrader 8

Overrides IndexerUsageInterface::getUsages

File

src/Plugin/DMU/Indexer/Constants.php, line 68

Class

Constants
Plugin annotation @Indexer( id = "constant" )

Namespace

Drupal\drupalmoduleupgrader\Plugin\DMU\Indexer

Code

public function getUsages($identifier) {
  $files = $this
    ->getQuery([
    'file',
  ])
    ->distinct()
    ->condition('id', $identifier)
    ->execute()
    ->fetchCol();
  $usages = new NodeCollection();
  foreach ($files as $file) {
    $this->target
      ->open($file)
      ->find(Filter::isInstanceOf('\\Pharborist\\Constants\\ConstantNode'))
      ->filter(function (ConstantNode $node) use ($identifier) {
      return $node
        ->getConstantName() == $identifier;
    })
      ->addTo($usages);
  }
  return $usages;
}