SodaException   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A getJsonResponse() 0 4 1
1
<?php
2
3
/**
4
 * This file contains the SodaException
5
 *
6
 * @copyright 2015 Vladimir Jimenez
7
 * @license   https://github.com/allejo/PhpSoda/blob/master/LICENSE.md MIT
8
 */
9
10
namespace allejo\Socrata\Exceptions;
11
12
/**
13
 * An exception thrown if a SODA API error is encountered.
14
 *
15
 * A SODA API error is in the form of a JSON object with a boolean named 'error' set to true.
16
 *
17
 * @package allejo\Socrata\Exceptions
18
 * @since   0.1.0
19
 */
20
class SodaException extends \Exception
21
{
22
    /**
23
     * The JSON object response when a SODA error is thrown
24
     *
25
     * @var array
26
     */
27
    private $jsonResponse;
28
29
    /**
30
     * Create an exception
31
     *
32
     * @param array $jsonResponse The JSON object returned by Socrata with error information
33
     *
34
     * @since 0.1.0
35
     */
36
    public function __construct ($jsonResponse)
37
    {
38
        $this->jsonResponse = $jsonResponse;
39
40
        $this->code    = (isset($this->jsonResponse['code'])) ? $this->jsonResponse['code'] : 'error.unknown';
41
        $this->message = $this->jsonResponse['message'];
42
    }
43
44
    /**
45
     * Get an associative array of the error that was thrown by Socrata
46
     *
47
     * @since 0.1.2
48
     *
49
     * @return array An associative array of the error Socrata threw
50
     */
51
    public function getJsonResponse ()
52
    {
53
        return $this->jsonResponse;
54
    }
55
}
56