Completed
Push — master ( 49324f...8a5a61 )
by Andrii
12:44
created

YamlHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 50%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
c 2
b 0
f 1
lcom 1
cbo 4
dl 0
loc 30
rs 10
ccs 2
cts 4
cp 0.5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A renderType() 0 5 2
A parse() 0 7 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\components\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
    public function __construct(Interpolator $interpolator, $options = [])
25
    {
26
        parent::__construct($options);
27
        $this->interpolator = $interpolator;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 2
    public function renderType($data)
34
    {
35 2
        /// XXX TODO fix getItems crutch
36
        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