grom358 / pharborist

A PHP library to query and transform source code via tree operations.
GNU General Public License v3.0
44 stars 10 forks source link

ArrayNode::getKeys, getValues, and hasKey #162

Closed phenaproxima closed 10 years ago

phenaproxima commented 10 years ago

The two getters return NodeCollections of the keys and values of an array, respectively. Each accepts a single boolean argument indicating whether or not to recurse into sub-arrays.

hasKey() is a bit confusing; it can accept either a scalar value (not a ScalarNode) or an ExpressionNode. If it's given a scalar, it'll first filter the array keys to the ones which implement ScalarNode, then strict-compare the value of each with the search key.

On the other hand, if hasKey() gets an ExpressionNode, it will strict-compare the getText() version of each key with the getText() version of the search key.

hasKey() accepts a $recursive boolean as well, which it passes to getKeys().

Thar of course be tests for all of this jiggery-pokery.

grom358 commented 10 years ago

For array [4, 2] should getKeys() return [0, 1] since they have implicit integer keys? That is make getKeys handle when there is no key specified, same as when using array_keys