Passed
Push — master ( 41d019...4608a5 )
by Eugene
05:43
created

server_version_at_least()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 8
rs 10
c 0
b 0
f 0
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 server_version_at_least(Client $client, string $version) : bool
31
{
32
    $connection = $client->getHandler()->getConnection();
33
    if (!$greeting = $connection->open()) {
34
        throw new \RuntimeException('Failed to retrieve server version.');
35
    }
36
37
    return version_compare($greeting->getServerVersion(), $version, '>=');
38
}
39