function TraversablePatch::supports
Supports nodetree, that implement Traversable, but not Iterator or IteratorAggregate.
Parameters
ClassNode $node:
Return value
bool
Overrides ClassPatchInterface::supports
File
-
vendor/
phpspec/ prophecy/ src/ Prophecy/ Doubler/ ClassPatch/ TraversablePatch.php, line 33
Class
- TraversablePatch
- Traversable interface patch. Forces classes that implement interfaces, that extend Traversable to also implement Iterator.
Namespace
Prophecy\Doubler\ClassPatchCode
public function supports(ClassNode $node) {
if (in_array('Iterator', $node->getInterfaces())) {
return false;
}
if (in_array('IteratorAggregate', $node->getInterfaces())) {
return false;
}
foreach ($node->getInterfaces() as $interface) {
if ('Traversable' !== $interface && !is_subclass_of($interface, 'Traversable')) {
continue;
}
if ('Iterator' === $interface || is_subclass_of($interface, 'Iterator')) {
continue;
}
if ('IteratorAggregate' === $interface || is_subclass_of($interface, 'IteratorAggregate')) {
continue;
}
return true;
}
return false;
}