You are here

public function Doubler::double in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpspec/prophecy/src/Prophecy/Doubler/Doubler.php \Prophecy\Doubler\Doubler::double()

Creates double from specific class or/and list of interfaces.

Parameters

ReflectionClass $class:

ReflectionClass[] $interfaces Array of ReflectionClass instances:

array $args Constructor arguments:

Return value

DoubleInterface

Throws

\Prophecy\Exception\InvalidArgumentException

File

vendor/phpspec/prophecy/src/Prophecy/Doubler/Doubler.php, line 93

Class

Doubler
Cached class doubler. Prevents mirroring/creation of the same structure twice.

Namespace

Prophecy\Doubler

Code

public function double(ReflectionClass $class = null, array $interfaces, array $args = null) {
  foreach ($interfaces as $interface) {
    if (!$interface instanceof ReflectionClass) {
      throw new InvalidArgumentException(sprintf("[ReflectionClass \$interface1 [, ReflectionClass \$interface2]] array expected as\n" . "a second argument to `Doubler::double(...)`, but got %s.", is_object($interface) ? get_class($interface) . ' class' : gettype($interface)));
    }
  }
  $classname = $this
    ->createDoubleClass($class, $interfaces);
  $reflection = new ReflectionClass($classname);
  if (null !== $args) {
    return $reflection
      ->newInstanceArgs($args);
  }
  if (null === ($constructor = $reflection
    ->getConstructor()) || $constructor
    ->isPublic() && !$constructor
    ->isFinal()) {
    return $reflection
      ->newInstance();
  }
  if (!$this->instantiator) {
    $this->instantiator = new Instantiator();
  }
  return $this->instantiator
    ->instantiate($classname);
}