These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * HiSite Yii2 base project |
||
4 | * |
||
5 | * @link https://github.com/hiqdev/hisite |
||
6 | * @package hisite |
||
7 | * @license BSD-3-Clause |
||
8 | * @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/) |
||
9 | */ |
||
10 | |||
11 | namespace hisite\actions; |
||
12 | |||
13 | use Closure; |
||
14 | use Yii; |
||
15 | use yii\base\Response; |
||
16 | use yii\helpers\Url; |
||
17 | |||
18 | /** |
||
19 | * Action to redirect to given url. |
||
20 | * |
||
21 | * @property array|string|Closure url the URL for redirect. Can be string, array or Closure |
||
22 | */ |
||
23 | class RedirectAction extends \yii\base\Action |
||
24 | { |
||
25 | /** |
||
26 | * @var string|array url to redirect to |
||
27 | */ |
||
28 | protected $_url; |
||
29 | |||
30 | /** |
||
31 | * Collects the URL array, executing callable functions. |
||
32 | * @return string|array default return to previous page (referer) |
||
33 | */ |
||
34 | public function getUrl() |
||
35 | { |
||
36 | if ($this->_url instanceof Closure) { |
||
37 | return call_user_func($this->_url, $this); |
||
38 | } |
||
39 | |||
40 | return $this->_url ?: Yii::$app->request->referrer; |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * @param $url |
||
45 | */ |
||
46 | public function setUrl($url) |
||
47 | { |
||
48 | $this->_url = $url; |
||
49 | } |
||
50 | |||
51 | public function run() |
||
52 | { |
||
53 | $url = $this->getUrl(); |
||
54 | |||
55 | return $url instanceof Response ? $url : $this->controller->redirect($url); |
||
0 ignored issues
–
show
|
|||
56 | } |
||
57 | } |
||
58 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: