Completed
Push — master ( 62f786...e41aa3 )
by Andrii
02:37
created

TemplateHandler::renderPrepared()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.037

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 3
cp 0.6667
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1.037
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 Yii;
15
16
/**
17
 * Handler for templated files.
18
 */
19
class TemplateHandler extends BaseHandler
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24 5
    public function renderPrepared(array $data)
25
    {
26
        return $this->getView()->render($this->template, $data);
27 5
    }
28
29
    public function renderTemplate($data)
30
    {
31
        return $this->renderPrepared(self::prepareData($data));
32
    }
33
34 5
    public function prepareData($data)
35
    {
36
        return array_merge([
37 5
            'config' => Yii::$app->config,
38 5
            'this'   => $this,
39 5
            'file'   => $data->file,
40
        ], parent::prepareData($data));
41
    }
42
43 2
    public function existsTemplate()
44
    {
45 2
        return $this->template && $this->view->existsTemplate($this->template);
0 ignored issues
show
Documentation introduced by
The property view does not exist on object<hidev\handlers\TemplateHandler>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
46
    }
47
}
48