Conditions | 2 |
Paths | 2 |
Total Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 9 |
CRAP Score | 2.004 |
Changes | 0 |
1 | <?php |
||
36 | 1 | public static function fromBadResponse(BadResponseException $previous) |
|
37 | { |
||
38 | 1 | $statusCode = $previous->getResponse()->getStatusCode(); |
|
39 | 1 | $message = sprintf( |
|
40 | 1 | static::$messageTemplate, |
|
41 | 1 | $previous->getMessage(), |
|
42 | 1 | \GuzzleHttp\Psr7\str($previous->getRequest()), |
|
43 | 1 | \GuzzleHttp\Psr7\str($previous->getResponse()) |
|
|
|||
44 | ); |
||
45 | 1 | if (array_key_exists($statusCode, static::$exceptions)) { |
|
46 | 1 | return new static::$exceptions[$statusCode]($message, 0, $previous); |
|
47 | } |
||
48 | |||
49 | return new self($message, 0, $previous); |
||
50 | } |
||
51 | } |
||
52 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: