function Doubler::double
Creates double from specific class or/and list of interfaces.
@template T of object
Parameters
ReflectionClass<T>|null $class:
ReflectionClass<object>[] $interfaces Array of ReflectionClass instances:
array<mixed>|null $args Constructor arguments:
Return value
T&DoubleInterface
Throws
\Prophecy\Exception\InvalidArgumentException
File
-
vendor/
phpspec/ prophecy/ src/ Prophecy/ Doubler/ Doubler.php, line 90
Class
- Doubler
- Cached class doubler. Prevents mirroring/creation of the same structure twice.
Namespace
Prophecy\DoublerCode
public function double(?ReflectionClass $class, 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);
}