Completed
Push — master ( 5f528b...a6b26f )
by Andrii
03:24
created

JsonHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 18
ccs 0
cts 2
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A renderType() 0 4 1
A parse() 0 4 2
1
<?php
2
3
/*
4
 * Automation tool mixed with code generator for easier continuous development
5
 *
6
 * @link      https://github.com/hiqdev/hidev
7
 * @package   hidev
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hidev\handlers;
13
14
use yii\helpers\Json;
15
16
/**
17
 * Handler for JSON files.
18
 */
19
class JsonHandler extends TypeHandler
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function renderType($data)
25
    {
26
        return Json::encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . "\n";
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function parse($json)
33
    {
34
        return $json ? Json::decode($json) : [];
35
    }
36
}
37