TemplateHandler::prepareData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 1
eloc 6
c 3
b 1
f 0
nc 1
nop 1
dl 0
loc 8
ccs 0
cts 7
cp 0
crap 2
rs 10
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-2018, 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));
0 ignored issues
show
Bug Best Practice introduced by
The method hidev\handlers\TemplateHandler::prepareData() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
        return $this->renderPrepared(self::/** @scrutinizer ignore-call */ prepareData($data));
Loading history...
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