SoapFaultException::getFaultCode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace DMT\Soap\Serializer;
4
5
use RuntimeException;
6
use SoapFault;
7
8
/**
9
 * Class SoapFaultException
10
 *
11
 * @package DMT\Soap
12
 */
13
class SoapFaultException extends RuntimeException
14
{
15
    /**
16
     * @var string
17
     */
18
    public $code;
19
20
    /**
21
     * @var string
22
     */
23
    public $reason;
24
25
    /**
26
     * @var string
27
     */
28
    public $node;
29
30
    /**
31
     * @var array
32
     */
33
    public $detail;
34
35
    /**
36
     * SoapFaultException constructor.
37
     *
38
     * @param string $code
39
     * @param string $reason
40
     * @param string|null $node
41
     * @param array|null $detail
42
     */
43 7
    public function __construct(string $code, string $reason, string $node = null, array $detail = null)
44
    {
45 7
        $this->code = $code;
46 7
        $this->reason = $reason;
47 7
        $this->node = $node;
48 7
        $this->detail = $detail;
49
50 7
        $previous = null;
51 7
        if (class_exists(SoapFault::class)) {
52 7
            $code = preg_replace(
53 7
                ['~^Receiver~', '~^Sender~', '~^DataEncodingUnknown~'],
54 7
                ['Server', 'Client', 'Client'],
55 7
                $this->code
56
            );
57 7
            $previous = new SoapFault($code, $reason, $node, $detail);
0 ignored issues
show
Bug introduced by
It seems like $detail can also be of type array; however, parameter $details of SoapFault::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
            $previous = new SoapFault($code, $reason, $node, /** @scrutinizer ignore-type */ $detail);
Loading history...
58
        }
59
60 7
        parent::__construct($reason, 0, $previous);
61 7
    }
62
63 7
    public function getFaultCode(): string
64
    {
65 7
        return $this->code;
66
    }
67
}
68