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

Parser   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 4
c 3
b 0
f 1
lcom 0
cbo 0
dl 0
loc 30
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A decode() 0 4 1
A get() 0 15 3
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