Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Doubler.php

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\Doubler

Code

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

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal