Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Plugin / DMU / Converter / Functions / VariableAPI.php
1 <?php
2
3 namespace Drupal\drupalmoduleupgrader\Plugin\DMU\Converter\Functions;
4
5 use Drupal\drupalmoduleupgrader\TargetInterface;
6 use Pharborist\Functions\FunctionCallNode;
7 use Pharborist\Types\StringNode;
8
9 /**
10  * Parent class of the VariableGet, VariableSet, and VariableDel plugins.
11  */
12 abstract class VariableAPI extends FunctionCallModifier {
13
14   /**
15    * Helper for subclasses' rewrite() methods. This checks if the call can
16    * be rewritten at all and leaves a FIXME if it can't. If the variable's
17    * key is not a string starting with MODULE_, the call will not be
18    * considered rewritable.
19    *
20    * @return boolean
21    */
22   protected function tryRewrite(FunctionCallNode $call, TargetInterface $target) {
23     $statement = $call->getStatement();
24     $arguments = $call->getArguments();
25
26     if ($arguments[0] instanceof StringNode) {
27       $key = $arguments[0]->toValue();
28
29       if (strPos($key, $target->id() . '_') === 0) {
30         return TRUE;
31       }
32       else {
33         $comment = <<<END
34 This looks like another module's variable. You'll need to rewrite this call
35 to ensure that it uses the correct configuration object.
36 END;
37         $this->buildFixMe($comment)->prependTo($statement);
38         return FALSE;
39       }
40     }
41     else {
42       $comment = <<<END
43 The correct configuration object could not be determined. You'll need to
44 rewrite this call manually.
45 END;
46       $this->buildFixMe($comment)->prependTo($statement);
47       return FALSE;
48     }
49   }
50
51 }