Completed
Push — master ( c7ee1c...c72239 )
by Eugene
06:35
created

RequestFailed::unknownSpace()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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
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
21
{
22
    /** @var Error|null */
23
    private $error;
24
25 18
    public function getError() : ?Error
26
    {
27 18
        return $this->error;
28
    }
29
30 81
    public static function fromErrorResponse(Response $response) : self
31
    {
32 81
        $self = new self(
33 81
            $response->getBodyField(Keys::ERROR_24),
34 81
            $response->getCode() & (Response::TYPE_ERROR - 1)
35
        );
36
37 81
        if ($error = $response->tryGetBodyField(Keys::ERROR)) {
38 81
            $self->error = Error::fromMap($error);
0 ignored issues
show
Documentation Bug introduced by
It seems like \Tarantool\Client\Error::fromMap($error) of type object<self> is incompatible with the declared type object<Tarantool\Client\Error>|null of property $error.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
39
        }
40
41 81
        return $self;
42
    }
43
44 6
    public static function unknownSpace(string $spaceName) : self
45
    {
46 6
        return new self(\sprintf("Space '%s' does not exist", $spaceName));
47
    }
48
49 6
    public static function unknownIndex(string $indexName, int $spaceId) : self
50
    {
51 6
        return new self(\sprintf("No index '%s' is defined in space #%d", $indexName, $spaceId));
52
    }
53
}
54