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

YamlHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A renderType() 0 5 2
A parse() 0 4 1
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 Symfony\Component\Yaml\Yaml;
15
use yii\helpers\ArrayHelper;
16
17
/**
18
 * Handler for YAML files.
19
 */
20
class YamlHandler extends TypeHandler
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function renderType($data)
26
    {
27
        /// XXX TODO fix getItems crutch
28
        return Yaml::dump(ArrayHelper::toArray(method_exists($data, 'getItems') ? $data->getItems() : $data), 4);
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function parse($yaml)
35
    {
36
        return (array) Yaml::parse($yaml);
37
    }
38
}
39