Completed
Push — master ( edb2b9...da334f )
by Dmitry
13:12
created

src/actions/ProxyAction.php (1 issue)

Check for undocumented magic property with read access

Documentation Informational

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
 * HiPanel core package
4
 *
5
 * @link      https://hipanel.com/
6
 * @package   hipanel-core
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2014-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\actions;
12
13
use Yii;
14
use yii\helpers\Url;
15
16
/**
17
 * Class ProxyAction.
18
 *
19
 * @property mixed pjaxUrl the url, which will be set to the `X-PJAX-URL` HTTP header, if request is PJAX.
20
 * Boolean (default true) - whether to set to the header URL, which is based on [[action]] and [[params]]
21
 * Array - direct
22
 * @property array|callable params params, that will be passed to [[action]] arguments when it will be called
23
 */
24
class ProxyAction extends Action
25
{
26
    /**
27
     * @var string|\Closure action to run
28
     */
29
    public $action;
30
31
    /**
32
     * @var array
33
     * @see params
34
     */
35
    public $_params = [];
36
37
    /**
38
     * @var boolean
39
     * @see pjaxUrl
40
     */
41
    public $_pjaxUrl = true;
42
43
    /**
44
     * @return array
45
     */
46
    public function getParams()
47
    {
48
        if ($this->_params instanceof \Closure) {
49
            return call_user_func($this->_params, $this, $this->getModel());
50
        }
51
52
        return $this->_params;
53
    }
54
55
    /**
56
     * @return bool|string
57
     */
58
    public function getPjaxUrl()
59
    {
60
        if ($this->_pjaxUrl instanceof \Closure) {
61
            $url = call_user_func($this->_pjaxUrl, $this);
62
        } elseif ($this->_pjaxUrl === true) {
63
            $url = (array) $this->action;
64
        } elseif (is_array($this->_pjaxUrl) || is_string($this->_pjaxUrl)) {
65
            $url = $this->_pjaxUrl;
66
        } else {
67
            return false;
68
        }
69
70
        return Url::to($url);
71
    }
72
73
    /**
74
     * @param $params
75
     */
76
    public function setParams($params)
77
    {
78
        $this->_params = $params;
79
    }
80
81
    /**
82
     * @return mixed
83
     */
84
    public function run()
85
    {
86
        if ($this->pjaxUrl && $this->parent->rule->requestType === 'pjax') {
0 ignored issues
show
The property rule does not exist on object<hipanel\actions\Action>. 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...
87
            Yii::$app->response->getHeaders()->add('X-PJAX-URL', $this->pjaxUrl);
88
        }
89
        $action = $this->action instanceof \Closure ? call_user_func($this->action, $this) : $this->action;
90
91
        return $this->controller->runAction($action, $this->params);
92
    }
93
94
    /**
95
     * @param mixed $pjaxUrl
96
     */
97
    public function setPjaxUrl($pjaxUrl)
98
    {
99
        $this->_pjaxUrl = $pjaxUrl;
100
    }
101
}
102