Passed
Push — master ( 484157...fe0dfb )
by Bas
04:30
created

SoapFaultException::getFaultCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace DMT\Soap\Serializer;
4
5
/**
6
 * Class SoapFaultException
7
 *
8
 * @package DMT\Soap
9
 */
10
class SoapFaultException extends \RuntimeException
11
{
12
    /**
13
     * @var string
14
     */
15
    public $code;
16
17
    /**
18
     * @var string
19
     */
20
    public $reason;
21
22
    /**
23
     * @var string
24
     */
25
    public $node;
26
27
    /**
28
     * @var array
29
     */
30
    public $detail;
31
32
    /**
33
     * SoapFaultException constructor.
34
     *
35
     * @param string $code
36
     * @param string $reason
37
     * @param string|null $node
38
     * @param array $detail
39
     */
40 6
    public function __construct(string $code, string $reason, string $node = null, array $detail = null)
41
    {
42 6
        $this->code = is_array($code) ? implode('.', $code) : $code;
0 ignored issues
show
introduced by
The condition is_array($code) is always false.
Loading history...
43 6
        $this->reason = $reason;
44 6
        $this->node = $node;
45 6
        $this->detail = $detail;
46
47 6
        if (class_exists(\SoapFault::class)) {
48 6
            $code = preg_replace(
49 6
                ['~^Receiver~', '~^Sender~', '~^DataEncodingUnknown~'],
50 6
                ['Server', 'Client', 'Client'],
51 6
                $this->code
52
            );
53 6
            $previous = new \SoapFault($code, $reason, $node, $detail);
0 ignored issues
show
Unused Code introduced by
The call to SoapFault::__construct() has too many arguments starting with $detail. ( Ignorable by Annotation )

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

53
            $previous = /** @scrutinizer ignore-call */ new \SoapFault($code, $reason, $node, $detail);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
Bug introduced by
$reason of type string is incompatible with the type integer expected by parameter $code of SoapFault::__construct(). ( Ignorable by Annotation )

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

53
            $previous = new \SoapFault($code, /** @scrutinizer ignore-type */ $reason, $node, $detail);
Loading history...
Bug introduced by
It seems like $node can also be of type string; however, parameter $previous of SoapFault::__construct() does only seem to accept Throwable|null, 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

53
            $previous = new \SoapFault($code, $reason, /** @scrutinizer ignore-type */ $node, $detail);
Loading history...
54
        }
55
56 6
        parent::__construct($reason, 0, $previous ?? null);
57 6
    }
58
59 6
    public function getFaultCode(): string
60
    {
61 6
        return $this->code;
62
    }
63
}
64