JsonResponse::encode()   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
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php namespace KamranAhmed\Smasher;
2
3
use KamranAhmed\Smasher\Contracts\ResponseContract;
4
5
/**
6
 * JsonResponse
7
 *
8
 * Helps encoding and decoding arrays to JSON
9
 */
10
class JsonResponse implements ResponseContract
11
{
12
    /**
13
     * Formats the passed data/array to json
14
     * @param  array $data The data which is to be encoded
15
     * @return string
16
     */
17 2
    public function encode($data)
18
    {
19 2
        return json_encode($data);
20
    }
21
22
    /**
23
     * Decodes the passed string and creates array from it
24
     * @param  string $response The existing response which is to be decoded to array
25
     * @return array
26
     */
27 3
    public function decode($response)
28
    {
29 3
        return json_decode($response, true);
30
    }
31
}
32