| Conditions | 8 |
| Paths | 14 |
| Total Lines | 33 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 15 |
| CRAP Score | 14.4058 |
| Changes | 0 | ||
| 1 | <?php |
||
| 20 | 8 | public function __construct($json) |
|
| 21 | { |
||
| 22 | 8 | $this->jsonObject = json_decode($json, true); |
|
| 23 | |||
| 24 | 8 | $lastError = json_last_error(); |
|
| 25 | switch ($lastError) { |
||
| 26 | 8 | case JSON_ERROR_NONE: |
|
| 27 | 7 | $lastErrorDesc = 'No errors'; |
|
| 28 | 7 | break; |
|
| 29 | 1 | case JSON_ERROR_DEPTH: |
|
| 30 | $lastErrorDesc = 'Maximum stack depth exceeded'; |
||
| 31 | break; |
||
| 32 | 1 | case JSON_ERROR_STATE_MISMATCH: |
|
| 33 | $lastErrorDesc = 'Underflow or the modes mismatch'; |
||
| 34 | break; |
||
| 35 | 1 | case JSON_ERROR_CTRL_CHAR: |
|
| 36 | $lastErrorDesc = 'Unexpected control character found'; |
||
| 37 | break; |
||
| 38 | 1 | case JSON_ERROR_SYNTAX: |
|
| 39 | 1 | $lastErrorDesc = 'Syntax error, malformed JSON'; |
|
| 40 | 1 | break; |
|
| 41 | case JSON_ERROR_UTF8: |
||
| 42 | $lastErrorDesc = 'Malformed UTF-8 characters, possibly incorrectly encoded'; |
||
| 43 | break; |
||
| 44 | default: |
||
| 45 | $lastErrorDesc = 'Unknown error'; |
||
| 46 | break; |
||
| 47 | } |
||
| 48 | |||
| 49 | 8 | if ($lastError != JSON_ERROR_NONE) { |
|
| 50 | 2 | throw new DatasetException("Invalid JSON string: " . $lastErrorDesc); |
|
| 51 | } |
||
| 52 | 7 | } |
|
| 53 | |||
| 66 |