You are here

public function TraversablePatch::supports in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpspec/prophecy/src/Prophecy/Doubler/ClassPatch/TraversablePatch.php \Prophecy\Doubler\ClassPatch\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 32

Class

TraversablePatch
Traversable interface patch. Forces classes that implement interfaces, that extend Traversable to also implement Iterator.

Namespace

Prophecy\Doubler\ClassPatch

Code

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;
}