Completed
Push — master ( 85c261...c36669 )
by Andrii
04:37 queued 02:08
created

YamlHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
/**
3
 * Automation tool mixed with code generator for easier continuous development.
4
 *
5
 * @link      https://github.com/hiqdev/hidev
6
 * @package   hidev
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hidev\handlers;
12
13
use hidev\base\Interpolator;
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
    protected $interpolator;
23
24 3
    public function __construct(Interpolator $interpolator, $options = [])
25
    {
26 3
        parent::__construct($options);
27 3
        $this->interpolator = $interpolator;
28 3
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 3
    public function renderType($data)
34
    {
35
        /// XXX TODO fix getItems crutch
36 3
        return Yaml::dump(ArrayHelper::toArray(method_exists($data, 'getItems') ? $data->getItems() : $data), 4);
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function parse($yaml)
43
    {
44
        $data = (array) Yaml::parse($yaml);
45
        $this->interpolator->interpolate($data);
46
47
        return $data;
48
    }
49
}
50