Completed
Push — master ( b626c0...1ad737 )
by Camilo
03:37
created

ClientException   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 56.25%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 36
ccs 9
cts 16
cp 0.5625
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 2
A setError() 0 8 1
A getError() 0 4 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace unreal4u\TelegramAPI\Exceptions;
6
7
use Throwable;
8
use unreal4u\TelegramAPI\Telegram\Types\Custom\UnsuccessfulRequest;
9
10
class ClientException extends \RuntimeException
11
{
12
    /**
13
     * @var UnsuccessfulRequest
14
     */
15
    protected $errorRequest;
16
17 2
    public function __construct(string $message = '', int $code = 0, Throwable $previous = null)
18
    {
19 2
        parent::__construct($message, $code, $previous);
20
21 2
        if ($previous !== null) {
22
            $this->file = $previous->getFile();
23
            $this->line = $previous->getLine();
24
25
            $this->setError(new UnsuccessfulRequest([
26
                'description' => $previous->getMessage(),
27
                'error_code' => $previous->getCode(),
28
            ]));
29
        }
30 2
    }
31
32 2
    public function setError(UnsuccessfulRequest $unsuccessfulRequest): ClientException
33
    {
34 2
        $this->errorRequest = $unsuccessfulRequest;
35
36 2
        $this->message = $unsuccessfulRequest->description;
37 2
        $this->code = $unsuccessfulRequest->error_code;
38 2
        return $this;
39
    }
40
41
    public function getError(): UnsuccessfulRequest
42
    {
43
        return $this->errorRequest;
44
    }
45
}
46