You are here

protected function VariableAPI::tryRewrite in Drupal 7 to 8/9 Module Upgrader 8

Helper for subclasses' rewrite() methods. This checks if the call can be rewritten at all and leaves a FIXME if it can't. If the variable's key is not a string starting with MODULE_, the call will not be considered rewritable.

Return value

bool

3 calls to VariableAPI::tryRewrite()
VariableDel::rewrite in src/Plugin/DMU/Converter/Functions/VariableDel.php
Tries to rewrite the original function call.
VariableGet::rewrite in src/Plugin/DMU/Converter/Functions/VariableGet.php
Tries to rewrite the original function call.
VariableSet::rewrite in src/Plugin/DMU/Converter/Functions/VariableSet.php
Tries to rewrite the original function call.

File

src/Plugin/DMU/Converter/Functions/VariableAPI.php, line 22

Class

VariableAPI
Parent class of the VariableGet, VariableSet, and VariableDel plugins.

Namespace

Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\Functions

Code

protected function tryRewrite(FunctionCallNode $call, TargetInterface $target) {
  $statement = $call
    ->getStatement();
  $arguments = $call
    ->getArguments();
  if ($arguments[0] instanceof StringNode) {
    $key = $arguments[0]
      ->toValue();
    if (strpos($key, $target
      ->id() . '_') === 0) {
      return TRUE;
    }
    else {
      $comment = <<<END
This looks like another module's variable. You'll need to rewrite this call
to ensure that it uses the correct configuration object.
END;
      $this
        ->buildFixMe($comment)
        ->prependTo($statement);
      return FALSE;
    }
  }
  else {
    $comment = <<<END
The correct configuration object could not be determined. You'll need to
rewrite this call manually.
END;
    $this
      ->buildFixMe($comment)
      ->prependTo($statement);
    return FALSE;
  }
}