@param $server
@param $reason

@return \AMQPChannel
554749
private function _serverEnsureChannel(&$server, $reason)
    {
        $channel = isset($server[self::SERVER_CHANNELS][$reason]) ? $server[self::SERVER_CHANNELS][$reason] : null;
        
        if (!$channel) {
            $channel = $this->_setupChannel($server[self::SERVER_CONNECTION][$reason]);
            
            $server[self::SERVER_CHANNELS][$reason] = $channel;
        }
        
        return $channel;
    }
1374540
public function deactivate($reason = 'other', $explanation = '')
    {
        $userId = $this->id();

        if ($userId === null) {
            return false;
        }

        $request = [
            'user_id'     => $userId,
            'reason'      => $reason,
            'explanation' => $explanation,
        ];

        return $this->post(UrlBuilder::RESOURCE_DEACTIVATE_ACCOUNT, $request);
    }
36403
public static function create($reason): self
    {
        $arguments = func_get_args();

        switch ($reason) {
            case static::CLASS_DOES_NOT_EXIST:
                $message = sprintf('Class %s does not exist. Cannot retrieve its metadata', $arguments[1]);

                return new static($message);

            case static::VALUE_IS_NOT_AN_OBJECT:
                $message = sprintf('Cannot create metadata for non-objects. Got: "%s"', gettype($arguments[1]));

                return new static($message);

            case static::NOT_MERGEABLE_METADATA:
                $message = sprintf(
                    'Cannot merge metadata of class "%s" with "%s"',
                    is_object($arguments[2]) ? get_class($arguments[2]) : $arguments[2],
                    is_object($arguments[1]) ? get_class($arguments[1]) : $arguments[1]
                );

                return new static($message);

            case static::INVALID_METADATA_CLASS:
                $message = sprintf(
                    '"%s" is not a valid metadata object class',
                    is_object($arguments[1]) ? get_class($arguments[1]) : $arguments[1]
                );

                return new static($message);

            case static::INVALID_PROCESSOR_INTERFACE_CLASS:
                $message = sprintf(
                    '"%s" is not a valid ProcessorInterface class',
                    $arguments[1]
                );

                return new static($message);
        }

        return new static(call_user_func_array('sprintf', $arguments));
    }
833338
public static function build(ServerInterface $server)
    {
        if ($server instanceof SftpServer) {
            return new SftpFile($server);
        } elseif ($server instanceof FtpServer || $server instanceof SslServer) {
            return new FtpFile($server);
        } else {
            throw new \InvalidArgumentException('The argument is must instance of server class');
        }
    }
917087
protected function createClusterClient(string $server): Redis
	{
		[$server, $port] = explode(':', $server, 2);

		$isPersistent = $this->connection->isPersistent();

		$timeout = $this->connection->getTimeout();

		$name = $this->connection->getName();

		$connection = new Connection($server, $port, $isPersistent, $timeout, $name);

		return new static($connection, ['password' => $this->password, 'database' => $this->database]);
	}
1310484
function delete(string $reason = '') {
        return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($reason) {
            $method = 'deleteWebhook';
            $args = array($this->id, $reason);
            
            if(!empty($this->token)) {
                $method = 'deleteWebhookToken';
                $args = array($this->id, $this->token, $reason);
            }
            
            $this->client->apimanager()->endpoints->webhook->$method(...$args)->done(function () use ($resolve) {
                $resolve();
            }, $reject);
        }));
    }
573508
function delete(string $reason = '') {
        return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($reason) {
            $this->client->apimanager()->endpoints->channel->deleteChannel($this->id, $reason)->done(function () use ($resolve) {
                $resolve();
            }, $reject);
        }));
    }
792738
public function createClient(array $config = []): HttpClient
    {
        if (!class_exists(Adapter::class)) {
            throw new LogicException(
                'To use the Buzz adapter you need to install the "php-http/buzz-adapter" package.'
            );
        }

        $client = new FileGetContents();
        $options = $this->getOptions($config);

        $client->setTimeout($options['timeout']);
        $client->setVerifyPeer($options['verify_peer']);
        $client->setVerifyHost($options['verify_host']);
        $client->setProxy($options['proxy']);

        return new Adapter($client, $this->messageFactory);
    }
1127803
public function beforeSend(Server $server)
    {

        // Check to make sure we have a query_port because it is required
        if (!isset($this->options[Server::SERVER_OPTIONS_QUERY_PORT])
            || empty($this->options[Server::SERVER_OPTIONS_QUERY_PORT])
        ) {
            throw new Exception(__METHOD__ . " Missing required setting '" . Server::SERVER_OPTIONS_QUERY_PORT . "'.");
        }

        // Let's loop the packets and set the proper pieces
        foreach ($this->packets as $packet_type => $packet) {
            // Update with the client port for the server
            $this->packets[$packet_type] = sprintf($packet, $server->portClient());
        }
    }
1352635
public function disconnect($reason = Protocol::CLOSE_NORMAL): bool
    {
        if ($this->connected === false) {
            return false;
        }

        $payload = $this->protocol->getClosePayload($reason);

        if ($this->socket) {
            if (!$payload->sendToSocket($this->socket)) {
                throw new FrameException("Unexpected exception when sending Close frame.");
            }
            // The client SHOULD wait for the server to close the connection
            $this->socket->receive();
            $this->socket->disconnect();
        }

        $this->connected = false;

        return true;
    }
717409
public function kick($channel, $nicknamearray, $reason = null,
        $priority = SMARTIRC_MEDIUM
    ) {
        if (!is_array($nicknamearray)) {
            $nicknamearray = array($nicknamearray);
        }

        $nicknamelist = implode(',', $nicknamearray);

        if ($reason !== null) {
            $this->send('KICK '.$channel.' '.$nicknamelist.' :'.$reason, $priority);
        } else {
            $this->send('KICK '.$channel.' '.$nicknamelist, $priority);
        }
        return $this;
    }
1093636
function setPosition(int $position, string $reason = '') {
        if($position < 0) {
            throw new \InvalidArgumentException('Position can not be below 0');
        }
        
        $newPositions = array();
        $newPositions[] = array('id' => $this->id, 'position' => $position);
        
        $count = $this->guild->channels->count();
        $channels = $this->guild->channels->sortCustom(function ($a, $b) {
            if($a->position === $b->position) {
                return $a->id <=> $b->id;
            }
            
            return $a->position <=> $b->position;
        })->values()->all();
        
        $pos = 0;
        for($i = 0; $i < $count; $i++) {
            if($pos === $position) {
                $pos++;
            }
            
            $channel = $channels[$i];
            
            if($pos === $channel->position) {
                continue;
            }
            
            $newPositions[] = array('id' => $channel, 'position' => $pos);
            $pos++;
        }
        
        return (new \React\Promise\Promise(function (callable $resolve, callable $reject) use ($newPositions, $reason) {
            $this->client->apimanager()->endpoints->guild->modifyGuildChannelPositions($this->guild->id, $newPositions, $reason)->done(function () use ($resolve) {
                $resolve($this);
            }, $reject);
        }));
    }
851915
public function close($fd, $code = self::CLOSE_NORMAL, $reason = '')
    {
        $this->send($fd, pack('n', $code).$reason, self::OPCODE_CONNECTION_CLOSE);
        $this->log("server close connection[$fd]. reason: $reason, close_code = $code");
        return $this->server->close($fd);
    }
1237756
function setServer($server)
    {
        $this->server = new DataEntity(
            $this->_normalizeServer($server)
        );
        
        return $this->server;
    }
942595
public function createFromServer(array $server = null){
        $server = $server ?? $_SERVER;

        $scheme     = $this->resolveScheme($server);
        $authority  = $this->resolveAuthority($server, $scheme);
        $path       = $this->resolvePathAndQuery($server);

        return new Uri("{$scheme}://{$authority}{$path}");
    }
419906
public function listen(ServerSocketContract $serverSocket)
    {
        if ($this->isRunning()) {
            throw new LogicException('Cannot add listening while the server is serving.');
        }

        if ($serverSocket->isBound()) {
            throw new LogicException('The server socket can be bound to server only once.');
        }

        $address = "{$serverSocket->getHost()}:{$serverSocket->getPort()}";

        if (isset($this->serverSockets[$address])) {
            throw new LogicException('The same address has been listened before.');
        }

        $swoolePort = $this->swooleServer->listen(
            $serverSocket->getHost(),
            $serverSocket->getPort(),
            $serverSocket->getSocketType()
        );

        if ($swoolePort == false) {
            $errorCode = $this->swooleServer->getLastError();

            throw new RuntimeException(sprintf(
                'Listen %s%s fail, error code %d', $serverSocket->getHost(),
                $serverSocket->getPort() ? ':'.$serverSocket->getPort() : '', $errorCode
            ), $errorCode);
        }

        $this->serverSockets[$address] = $serverSocket;

        $serverSocket->listen($this, $swoolePort);
    }
646200
public function dispatch($methodSig, $args, $content)
    {
        if (!array_key_exists($methodSig, $this->methodMap)) {
            throw new \Exception("Unknown AMQP method $methodSig");
        }

        $amqpMethod = $this->methodMap[$methodSig];

        if ($content == null) {
            return call_user_func(array($this, $amqpMethod), $args);
        } else {
            return call_user_func(
                array($this, $amqpMethod), $args, $content
            );
        }
    }