Completed
Push — master ( b4a6ad...e2bab1 )
by Andrii
13:50
created

src/controllers/GenerateController.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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) 2014-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;
29
        $this->file     = $file ?: static::template2file($template);
0 ignored issues
show
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
    public function actionMkdir($dir)
45
    {
46
        if (file_exists($dir)) {
47
            return;
48
        }
49
        mkdir($dir, 0777, true);
50
    }
51
}
52