@throws RuntimeException

@return self New instance
558877
public function restoreReasonPhraseToDefault()
    {
        $cloned = clone $this;

        $cloned->reasonPhrase = isset(self::$phraseMap[$this->statusCode]) ? self::$phraseMap[$this->statusCode] : '';

        return $cloned;
    }
733672
protected function factory()
    {
        if ($this->factory === null) {
            throw new RuntimeException(
                sprintf('Model Factory is not defined for "%s"', get_class($this))
            );
        }

        return $this->factory;
    }
408570
public function toArray()
    {
        $data = array();

        foreach ($this as $key => $value) {
            if (is_object($value)) {
                if (!is_callable(array($value, 'toArray'))) {
                    throw new RuntimeException('Object does not implement toArray() method on key: ' . $key);
                }
                $data[$key] = $value->toArray();
            } else {
                $data[$key] = $value;
            }
        }

        return $data;
    }
695395
protected T createInstance() {
        try {
            Constructor<T> ctor = clazz.getDeclaredConstructor();
            ctor.setAccessible(true);
            return ctor.newInstance();
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (SecurityException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (IllegalArgumentException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        }
    }
931283
public function createEnvironment()
    {
        if (empty($this->containerName) && !$this->dataContainer) {
            throw new DcGeneralRuntimeException('Required container name or container is missing');
        }

        if (null === $this->eventDispatcher) {
            throw new DcGeneralRuntimeException('Required event dispatcher is missing');
        }

        if (null === $this->translator) {
            throw new DcGeneralRuntimeException('Required translator is missing');
        }

        if ($this->dataContainer) {
            $dataContainer = clone $this->dataContainer;
        } else {
            $dataContainer = $this->createContainer();
        }

        /** @var EnvironmentInterface $environment */
        $environment = (new \ReflectionClass($this->environmentClassName))->newInstance();
        $environment->setDataDefinition($dataContainer);
        $environment->setEventDispatcher($this->eventDispatcher);
        $environment->setTranslator($this->translator);

        // Backwards compatibility.
        $this->getEventDispatcher()->dispatch(
            PopulateEnvironmentEvent::NAME,
            new PopulateEnvironmentEvent($environment)
        );

        return $environment;
    }
826037
public T create() throws Exception {
        if (type == TYPE_DEFAULT) {
            if (args == null || args.length == 0) {
                return aClass.newInstance();
            }
        } else if (type == TYPE_CREATOR) {
            return creator.create();
        }

        throw new RuntimeException("Unsupported create method");
    }
1071465
public function useGlobally()
    {
        if (!isset($this->handle)) {
            throw new \RuntimeException("The stream is closed");
        }
        
        if ($this->isGlobal()) {
            return $this;
        }
        
        $this->assertOutputBuffering();
        
        $output = $this->createOutputStream();
        if ($output === false) {
            throw new \RuntimeException("Failed to create temp stream");
        }
        
        $this->obClean();
        $this->rewind();
        stream_copy_to_stream($this->handle, $output);
        
        parent::close();
        $this->handle = $output;
        
        return $this;
    }
73929
protected function sourceFactory()
    {
        if (!isset($this->sourceFactory)) {
            throw new RuntimeException(
                sprintf('Source factory is not set for "%s"', get_class($this))
            );
        }
        return $this->sourceFactory;
    }
76530
protected function cachePool()
    {
        if (!isset($this->cachePool)) {
            throw new RuntimeException(sprintf(
                'Cache Pool is not defined for "%s"',
                get_class($this)
            ));
        }

        return $this->cachePool;
    }
416648
public Runnable asRunnable() {
        return new Runnable() {
            @Override
            public void run() {
                try {
                    callable.call();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        };
    }
1236212
public function create(): self
    {
        $this->logger->info('create new queue ['.$this->name.']', [
            'category' => get_class($this),
        ]);

        try {
            $this->db->createCollection(
                $this->name,
                [
                    'capped' => true,
                    'size' => $this->size,
                ]
            );

            $this->db->{$this->name}->insertOne(['class' => 'dummy']);
        } catch (RuntimeException $e) {
            //ignore if code 48 (collection does already exist)
            if (48 !== $e->getCode()) {
                throw $e;
            }
        }

        return $this;
    }
1254737
public function load() : Persistable
    {
        $data = $this->connector->get($this->key) ?: '';

        $persistable = $this->serializer->unserialize($data);

        if (!$persistable instanceof Persistable) {
            throw new RuntimeException('Persistable could not be'
                . ' reconstituted.');
        }

        return $persistable;
    }
97386
public function init()
    {
        if (!$this->getQuery()) {
            throw new \RuntimeException('Uninitialized QueryBuilder');
        }

        $this->resetIterator();
        $this->setNbResults($this->computeNbResult());

        if (0 == $this->getPage() || 0 == $this->getMaxPerPage() || 0 == $this->getNbResults()) {
            $this->setLastPage(0);
            $this->getQuery()->setFirstResult(0);
            $this->getQuery()->setMaxResults(0);
        } else {
            $offset = ($this->getPage() - 1) * $this->getMaxPerPage();
            $this->setLastPage(ceil($this->getNbResults() / $this->getMaxPerPage()));
            $this->getQuery()->setFirstResult($offset);
            $this->getQuery()->setMaxResults($this->getMaxPerPage());
        }
    }
154742
public function initialize()
    {
        if ((false === $this->exists($this->localPath)) && false === $this->filesystem->createDir($this->localPath)) {
            throw new RuntimeException(
                'Unable to create a local storage for temporary filesystem operations.'
            );
        }

        $this->initialized = true;
    }
380729
public SupportProvider newDefaultInstance() {
        try {
            return clazz.newInstance();
        } catch (InstantiationException e) {
            throw new RuntimeException("Failed to instantiate " + clazz, e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException("Failed to instantiate " + clazz, e);
        }
    }
1050753
public function create()
    {
        if ($this->getIsNewRecord() == false) {
            throw new \RuntimeException('Calling "' . __CLASS__ . '::' . __METHOD__ . '" on existing user');
        }
        if ($this->scenario == self::SCENARIO_CREATE_MOBILE) {
            $this->mobile_confirmed_at = time();
        }

        $this->password = $this->password == null ? Password::generate(8) : $this->password;
        $this->trigger(self::BEFORE_CREATE);
        if (!$this->save()) {
            return false;
        }
        //$this->module->sendMessage($this->email, Yii::t('user', 'Welcome to {0}', Yii::$app->name), 'welcome', ['user' => $this, 'token' => null, 'module' => $this->module, 'showPassword' => true]);
        $this->trigger(self::AFTER_CREATE);
        return true;
    }
249319
public function collectionLoader()
    {
        if (!isset($this->collectionLoader)) {
            throw new RuntimeException(sprintf(
                'Collection Loader is not defined for "%s"',
                get_class($this)
            ));
        }

        return $this->collectionLoader;
    }