Eloquent\Phony\Mock\Builder\MockBuilder::like PHP Метод

like() публичный Метод

Each value in $types can be either a class name, or an ad hoc mock definition. If only a single type is being mocked, the class name or definition can be passed without being wrapped in an array.
public like ( mixed $type )
$type mixed A type, or types to add.
    public function like($type)
    {
        if ($this->isFinalized) {
            throw new FinalizedMockException();
        }
        $types = array();
        foreach (func_get_args() as $type) {
            if (is_array($type)) {
                if (!empty($type)) {
                    if (array_values($type) === $type) {
                        $types = array_merge($types, $type);
                    } else {
                        $types[] = $type;
                    }
                }
            } else {
                $types[] = $type;
            }
        }
        $toAdd = array();
        if (!$this->parentClassName) {
            $parentClassNames = array();
        } else {
            $parentClassNames = array($this->parentClassName);
        }
        $parentClassName = null;
        $definitions = array();
        foreach ($types as $type) {
            if (is_string($type)) {
                try {
                    $type = new ReflectionClass($type);
                } catch (ReflectionException $e) {
                    throw new InvalidTypeException($type, $e);
                }
            } elseif (is_array($type)) {
                foreach ($type as $name => $value) {
                    if (!is_string($name)) {
                        throw new InvalidDefinitionException($name, $value);
                    }
                }
                $definitions[] = $type;
                continue;
            } else {
                throw new InvalidTypeException($type);
            }
            if ($this->isAnonymousClassSupported && $type->isAnonymous()) {
                throw new AnonymousClassException();
            }
            $isTrait = $this->isTraitSupported && $type->isTrait();
            if (!$isTrait && $type->isFinal()) {
                throw new FinalClassException($type->getName());
            }
            if (!$isTrait && !$type->isInterface()) {
                $parentClassNames[] = $parentClassName = $type->getName();
            }
            $toAdd[] = $type;
        }
        $parentClassNames = array_unique($parentClassNames);
        $parentClassCount = count($parentClassNames);
        if ($parentClassCount > 1) {
            throw new MultipleInheritanceException($parentClassNames);
        }
        foreach ($toAdd as $type) {
            $name = strtolower($type->getName());
            if (!isset($this->types[$name])) {
                $this->types[$name] = $type;
            }
        }
        if ($parentClassCount > 0) {
            $this->parentClassName = $parentClassName;
        }
        foreach ($definitions as $definition) {
            $this->define($definition);
        }
        return $this;
    }