FaultException::createFromResponse()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 4
nop 1
crap 3
1
<?php
2
3
namespace Fxmlrpc\Serialization\Exception;
4
5
use Fxmlrpc\Serialization\Exception;
6
7
/**
8
 * Thrown when the response is a fault.
9
 *
10
 * @author Márk Sági-Kazár <[email protected]>
11
 */
12
final class FaultException extends \RuntimeException implements Exception
13
{
14
    /**
15
     * @param string $faultString
16
     * @param int    $faultCode
17
     */
18 6
    public function __construct($faultString, $faultCode)
19
    {
20 6
        parent::__construct($faultString, $faultCode);
21 6
    }
22
23
    /**
24
     * Creates a FaultException from XML-RPC response.
25
     *
26
     * @param array $response
27
     *
28
     * @return FaultException
29
     */
30 2
    public static function createFromResponse(array $response)
31
    {
32 2
        $faultString = isset($response['faultString']) ? $response['faultString'] : 'Unknown';
33 2
        $faultCode = isset($response['faultCode']) ? $response['faultCode'] : 0;
34
35 2
        return new self($faultString, $faultCode);
36
    }
37
}
38