Parser::decode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
namespace Kwkm\MkLiveStatusClient;
3
4
/**
5
 * Class Parser
6
 *
7
 * @package Kwkm\MkLiveStatusClient
8
 * @author Takehiro Kawakami <[email protected]>
9
 * @license MIT
10
 */
11
class Parser
12
{
13 2
    public function decode($response)
14
    {
15 2
        return json_decode($response, true);
16
    }
17
18
    /**
19
     * ヘッダをキーとした配列として読み込む
20
     *
21
     * @param string $response
22
     * @return array
23
     */
24 1
    public function get($response)
25
    {
26 1
        $json = $this->decode($response);
27 1
        $header = array_shift($json);
28 1
        $result = array();
29 1
        foreach ($json as $row) {
30 1
            $work = array();
31 1
            foreach ($row as $key => $value) {
32 1
                $work[$header[$key]] = $value;
33 1
            }
34 1
            $result[] = $work;
35 1
        }
36
37 1
        return $result;
38
    }
39
}
40