Conditions | 11 |
Paths | 43 |
Total Lines | 32 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
60 | public function run() |
||
61 | { |
||
62 | if ($this->useSessionFlash) { |
||
63 | $session = Yii::$app->getSession(); |
||
|
|||
64 | $flashes = $session->getAllFlashes(); |
||
65 | $steps = []; |
||
66 | foreach ($flashes as $type => $data) { |
||
67 | $data = (array)$data; |
||
68 | foreach ($data as $message) { |
||
69 | array_push($steps, ['type' => $type, 'text' => $message]); |
||
70 | } |
||
71 | $session->removeFlash($type); |
||
72 | } |
||
73 | if (!empty($steps)) { |
||
74 | if (!is_array($steps[0]['text'])) { |
||
75 | $this->registerSwalQueue($steps); |
||
76 | } else { |
||
77 | $steps[0]['text']['type'] = isset($steps[0]['text']['type']) ? $steps[0]['text']['type'] : $steps[0]['type']; |
||
78 | if (isset($steps[0]['text']['animation']) && $steps[0]['text']['animation'] == false) { |
||
79 | if (isset($steps[0]['text']['customClass'])) { |
||
80 | $this->registerAnimate(); |
||
81 | } |
||
82 | } |
||
83 | $this->options = $steps[0]['text']; |
||
84 | $this->callback = isset($steps[1]['text']['callback']) ? $steps[1]['text']['callback'] : $this->callback; |
||
85 | $this->registerSwal($this->getOptions(), $this->callback); |
||
86 | } |
||
87 | } |
||
88 | } else { |
||
89 | $this->registerSwal($this->getOptions(), $this->callback); |
||
90 | } |
||
91 | } |
||
92 | |||
155 |
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: