ErrorDetector   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 29
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B detect() 0 21 5
1
<?php
2
3
/**
4
 * AnimeDb package.
5
 *
6
 * @author    Peter Gribanov <[email protected]>
7
 * @copyright Copyright (c) 2011, Peter Gribanov
8
 * @license   http://opensource.org/licenses/GPL-3.0 GPL v3
9
 */
10
11
namespace AnimeDb\Bundle\ShikimoriBrowserBundle\Service;
12
13
use AnimeDb\Bundle\ShikimoriBrowserBundle\Exception\ErrorException;
14
15
class ErrorDetector
16
{
17
    /**
18
     * @param string $content
19
     *
20
     * @return array
21
     */
22 5
    public function detect($content)
23
    {
24 5
        if ($content == '') {
25 1
            return [];
26
        }
27
28 4
        $data = json_decode($content, true);
29
30 4
        if (json_last_error() !== JSON_ERROR_NONE) {
31 1
            throw ErrorException::invalidResponse(json_last_error_msg(), json_last_error());
32
        }
33
34 3
        if (!empty($data['code'])) {
35 2
            throw ErrorException::failed(
36 2
                isset($data['message']) ? $data['message'] : '',
37 2
                $data['code']
38
            );
39
        }
40
41 1
        return (array) $data;
42
    }
43
}
44