You are here

FunctionCallArgumentFilter.php in Drupal 7 to 8/9 Module Upgrader 8

File

src/Utility/Filter/FunctionCallArgumentFilter.php
View source
<?php

namespace Drupal\drupalmoduleupgrader\Utility\Filter;

use Pharborist\Functions\FunctionCallNode;
use Pharborist\Node;
use Pharborist\Variables\VariableNode;

/**
 * Filters for function calls which are passed a particular argument.
 */
class FunctionCallArgumentFilter {

  /**
   * @var string
   */
  protected $variable;
  public function __construct($variable) {
    $this->variable = $variable;
  }

  /**
   * @return bool
   */
  public function __invoke(Node $node) {
    if ($node instanceof FunctionCallNode) {
      return (bool) $node
        ->getArgumentList()
        ->children([
        $this,
        'hasArgument',
      ])
        ->count();
    }
    return FALSE;
  }

  /**
   * @return bool
   */
  public function hasArgument(Node $argument) {
    return $argument instanceof VariableNode && $argument
      ->getName() == $this->variable;
  }

}

Classes

Namesort descending Description
FunctionCallArgumentFilter Filters for function calls which are passed a particular argument.