Passed
Pull Request — master (#63)
by Eugene
03:00
created

get_server_version()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
/**
4
 * This file is part of the Tarantool Client package.
5
 *
6
 * (c) Eugene Leonovich <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
use Tarantool\Client\Client;
15
use Tarantool\Client\Connection\StreamConnection;
16
use Tarantool\Client\Handler\DefaultHandler;
17
use Tarantool\Client\Packer\PackerFactory;
18
19
return require __DIR__.'/../vendor/autoload.php';
20
21
function create_client() : Client
22
{
23
    $connection = isset($_SERVER['argv'][1])
24
        ? StreamConnection::create($_SERVER['argv'][1])
25
        : StreamConnection::createTcp();
26
27
    return new Client(new DefaultHandler($connection, PackerFactory::create()));
28
}
29
30
function get_server_version_id(Client $client) : int
31
{
32
    $connection = $client->getHandler()->getConnection();
33
    if (!$greeting = $connection->open()) {
34
        throw new \RuntimeException('Failed to retrieve the server version.');
35
    }
36
37
    return $greeting->getServerVersionId();
38
}
39