RequestFailed   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 32
ccs 14
cts 14
cp 1
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getError() 0 3 1
A unknownSpace() 0 3 1
A unknownIndex() 0 3 1
A fromErrorResponse() 0 12 2
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
namespace Tarantool\Client\Exception;
15
16
use Tarantool\Client\Error;
17
use Tarantool\Client\Keys;
18
use Tarantool\Client\Response;
19
20
final class RequestFailed extends \RuntimeException implements ClientException
21
{
22
    /** @var Error|null */
23
    private $error;
24
25 24
    public function getError() : ?Error
26
    {
27 24
        return $this->error;
28
    }
29
30 112
    public static function fromErrorResponse(Response $response) : self
31
    {
32 112
        $self = new self(
33 112
            $response->getBodyField(Keys::ERROR_24),
34 112
            $response->getCode() & (Response::TYPE_ERROR - 1)
35 112
        );
36
37 112
        if ($error = $response->tryGetBodyField(Keys::ERROR)) {
38 112
            $self->error = Error::fromMap($error);
39
        }
40
41 112
        return $self;
42
    }
43
44 8
    public static function unknownSpace(string $spaceName) : self
45
    {
46 8
        return new self(\sprintf("Space '%s' does not exist", $spaceName));
47
    }
48
49 8
    public static function unknownIndex(string $indexName, int $spaceId) : self
50
    {
51 8
        return new self(\sprintf("No index '%s' is defined in space #%d", $indexName, $spaceId));
52
    }
53
}
54