Error::setHardWay()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 3
cts 3
cp 1
crap 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