Completed
Push — master ( 3204cd...9afd5c )
by Andrii
02:53
created

TemplateHandler::prepareData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1.008

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 5
cp 0.8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
crap 1.008
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 5
    public function renderPrepared(array $data)
24
    {
25
        return $this->getView()->render($this->template, $data);
26 5
    }
27
28
    public function renderTemplate($data)
29
    {
30
        return $this->renderPrepared(self::prepareData($data));
31
    }
32
33 5
    public function prepareData($data)
34
    {
35
        return array_merge([
36 5
            'config' => Yii::$app->config,
37 5
            'this'   => $this,
38 5
            'file'   => $data->file,
39
        ], parent::prepareData($data));
40
    }
41
42 2
    public function existsTemplate()
43
    {
44 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...
45
    }
46
}
47