Completed
Push — 2.0-dev ( 69bb11...1c6990 )
by Takehiro
02:55
created

Parser::decode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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
    public function decode($response)
14
    {
15
        return json_decode($response);
16
    }
17
18
    /**
19
     * ヘッダをキーとした配列として読み込む
20
     *
21
     * @param string $response
22
     * @return array
23
     */
24
    public function get($response)
25
    {
26
        $json = $this->decode($response);
27
        $header = array_shift($json);
28
        $result = array();
29
        foreach ($json as $row) {
30
            $work = array();
31
            foreach ($row as $key => $value) {
32
                $work[$header[$key]] = $value;
33
            }
34
            $result[] = $work;
35
        }
36
37
        return $result;
38
    }
39
40
}
41