Further modules included.
[yaffs-website] / web / modules / contrib / drupalmoduleupgrader / src / Utility / Filter / FieldValueFilter.php
1 <?php
2
3 namespace Drupal\drupalmoduleupgrader\Utility\Filter;
4
5 use Pharborist\ArrayLookupNode;
6 use Pharborist\Node;
7 use Pharborist\Objects\ObjectPropertyNode;
8 use Pharborist\Variables\VariableNode;
9
10 /**
11  * Filters for things that *look like* field accesses, e.g.
12  * $foo->bar[LANGUAGE_NONE][0]['value']. This filter doesn't guarantee that
13  * matched nodes actually ARE field accesses -- just that they have the proper
14  * formation (S-foils in attack formation!...what, you don't like Star Wars?)
15  */
16 class FieldValueFilter {
17
18   /**
19    * @var string
20    */
21   protected $variable;
22
23   public function __construct($variable) {
24     $this->variable = $variable;
25   }
26
27   /**
28    * @return boolean
29    */
30   public function __invoke(Node $node) {
31     if ($node instanceof ArrayLookupNode) {
32       $root = $node->getRootArray();
33
34       if ($root instanceof ObjectPropertyNode) {
35         $object = $root->getObject();
36
37         if ($object instanceof VariableNode && $object->getName() == $this->variable) {
38           return (sizeof($node->getKeys()) >= 3);
39         }
40       }
41     }
42     return FALSE;
43   }
44
45 }