Completed
Push — master ( c4a138...5d0a33 )
by Andrii
04:41
created

GenerateController::actionMkdir()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 6
1
<?php
2
3
/*
4
 * Task runner, code generator and build tool for easier continuos integration
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\controllers;
13
14
/**
15
 * Generate goal to build files by template and params.
16
 */
17
class GenerateController extends TemplateController
18
{
19
    public static function template2file($template, $extension = '.php')
20
    {
21
        $a = pathinfo($template);
22
23
        return $a['dirname'] . '/' . $a['filename'] . $extension;
24
    }
25
26
    public function actionPerform($template = null, $file = null)
27
    {
28
        $this->template = $template;
0 ignored issues
show
Bug introduced by
The property template does not seem to exist. Did you mean _template?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
29
        $this->file     = $file ?: static::template2file($template);
0 ignored issues
show
Documentation introduced by
The property file does not exist on object<hidev\controllers\GenerateController>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
30
31
        return parent::actionPerform();
32
    }
33
34
    public function actionOnce($template, $file = null)
35
    {
36
        $file = $file ?: static::template2file($template);
37
        if (file_exists($file)) {
38
            return;
39
        }
40
41
        return $this->actionPerform($template, $file);
42
    }
43
}
44