Completed
Push — master ( 4bb285...2f71f6 )
by Andrii
03:37
created

TemplateHandler   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 15.38%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 30
ccs 2
cts 13
cp 0.1538
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A existsTemplate() 0 4 2
A renderTemplate() 0 4 1
A renderPrepared() 0 4 1
A prepareData() 0 9 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 Yii;
14
15
/**
16
 * Handler for templated files.
17
 */
18
class TemplateHandler extends BaseHandler
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function renderPrepared(array $data)
24
    {
25
        return $this->getView()->render($this->template, $data);
26
    }
27
28
    public function renderTemplate($data)
29
    {
30
        return $this->renderPrepared(self::prepareData($data));
31
    }
32
33
    public function prepareData($data)
34
    {
35
        return array_merge([
36
            'app'     => Yii::$app,
37
            'config'  => Yii::$app, /// DEPRECATED
38
            'file'    => $data->file,
39
            'handler' => $this,
40
        ], parent::prepareData($data));
41
    }
42
43 3
    public function existsTemplate()
44
    {
45 3
        return $this->template && $this->getView()->existsTemplate($this->template);
46
    }
47
}
48