Error   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 33
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getError() 0 7 2
A process() 0 8 2
A setHardWay() 0 4 1
1
<?php
2
3
namespace kalanis\RemoteRequest\Protocols\Fsp\Answer;
4
5
6
use kalanis\RemoteRequest\Protocols\Fsp;
7
use kalanis\RemoteRequest\RequestException;
8
9
10
/**
11
 * Class Error
12
 * @package kalanis\RemoteRequest\Protocols\Fsp\Answer
13
 * Process default answer aka what did you send?!
14
 */
15
class Error extends AAnswer
16
{
17
    protected int $errorCode = 0;
18
    protected string $errorMessage = '';
19
    protected bool $hardWay = false;
20
21 1
    public function setHardWay(bool $hardWay): self
22
    {
23 1
        $this->hardWay = $hardWay;
24 1
        return $this;
25
    }
26
27 3
    public function process(): parent
28
    {
29 3
        $this->errorMessage = substr($this->answer->getContent(), 0, -1);
30 3
        $extra = $this->answer->getExtraData();
31 3
        if (!empty($extra)) {
32 1
            $this->errorCode = Fsp\Strings::mb_ord($extra);
33
        }
34 3
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type kalanis\RemoteRequest\Protocols\Fsp\Answer\Error which is incompatible with the type-hinted return parent.
Loading history...
35
    }
36
37
    /**
38
     * @throws RequestException
39
     * @return RequestException
40
     */
41 3
    public function getError(): RequestException
42
    {
43 3
        $ex = new RequestException($this->errorMessage, $this->errorCode);
44 3
        if ($this->hardWay) {
45 1
            throw $ex;
46
        }
47 2
        return $ex;
48
    }
49
}
50