Completed
Push — master ( 2977a7...5955f6 )
by Andrii
03:40
created

YamlHandler::renderType()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 0
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 2
nc 1
nop 1
crap 6
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