You are here

protected function Generic::getExpressions in Drupal 7 to 8/9 Module Upgrader 8

Finds every rewritable expression in the function body.

Parameters

\Pharborist\Functions\ParameterNode $parameter: The parameter on which the rewrite is based.

Return value

\Pharborist\NodeCollection

File

src/Plugin/DMU/Rewriter/Generic.php, line 127

Class

Generic
Plugin annotation @Rewriter( id = "_rewriter", deriver = "\Drupal\drupalmoduleupgrader\Plugin\DMU\Rewriter\GenericDeriver" )

Namespace

Drupal\drupalmoduleupgrader\Plugin\DMU\Rewriter

Code

protected function getExpressions(ParameterNode $parameter) {
  $filter = Filter::isInstanceOf('\\Pharborist\\ArrayLookupNode', '\\Pharborist\\Objects\\ObjectPropertyNode');
  $expressions = new NodeCollection();
  $parameter
    ->getFunction()
    ->find(Filter::isInstanceOf('\\Pharborist\\Variables\\VariableNode'))
    ->filter(function (VariableNode $variable) use ($parameter) {
    return $variable
      ->getName() == $parameter
      ->getName();
  })
    ->each(function (VariableNode $variable) use ($filter, $expressions) {
    $root = $variable
      ->furthest($filter);
    if ($root) {
      $expressions
        ->add($root);
    }
  });
  return $expressions;
}