Conditions | 17 |
Paths | 384 |
Total Lines | 91 |
Code Lines | 29 |
Lines | 23 |
Ratio | 25.27 % |
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 namespace Anomaly\Streams\Platform\Ui\Table\Component\Action; |
||
40 | protected function process($prefix, $slug, $action) |
||
41 | { |
||
42 | /* |
||
43 | * If the slug is numeric and the action is |
||
44 | * a string then treat the string as both the |
||
45 | * action and the slug. This is OK as long as |
||
46 | * there are not multiple instances of this |
||
47 | * input using the same action which is not likely. |
||
48 | */ |
||
49 | View Code Duplication | if (is_numeric($slug) && is_string($action)) { |
|
50 | $action = [ |
||
51 | 'slug' => $action, |
||
52 | 'action' => $action, |
||
53 | ]; |
||
54 | } |
||
55 | |||
56 | /* |
||
57 | * If the slug is NOT numeric and the action is a |
||
58 | * string then use the slug as the slug and the |
||
59 | * action as the action. |
||
60 | */ |
||
61 | View Code Duplication | if (!is_numeric($slug) && is_string($action)) { |
|
62 | $action = [ |
||
63 | 'slug' => $slug, |
||
64 | 'action' => $action, |
||
65 | ]; |
||
66 | } |
||
67 | |||
68 | /* |
||
69 | * If the slug is not numeric and the action is an |
||
70 | * array without a slug then use the slug for |
||
71 | * the slug for the action. |
||
72 | */ |
||
73 | View Code Duplication | if (is_array($action) && !isset($action['slug']) && !is_numeric($slug)) { |
|
74 | $action['slug'] = $slug; |
||
75 | } |
||
76 | |||
77 | /* |
||
78 | * If the slug is not numeric and the action is an |
||
79 | * array without a action then use the slug for |
||
80 | * the action for the action. |
||
81 | */ |
||
82 | View Code Duplication | if (is_array($action) && !isset($action['action']) && !is_numeric($slug)) { |
|
83 | $action['action'] = $slug; |
||
84 | } |
||
85 | |||
86 | /* |
||
87 | * Make sure the attributes array is set. |
||
88 | */ |
||
89 | $action['attributes'] = array_get($action, 'attributes', []); |
||
90 | |||
91 | /* |
||
92 | * Move all data-* keys |
||
93 | * to attributes. |
||
94 | */ |
||
95 | foreach ($action as $attribute => $value) { |
||
96 | if (str_is('data-*', $attribute)) { |
||
97 | array_set($action, 'attributes.' . $attribute, array_pull($action, $attribute)); |
||
98 | } |
||
99 | } |
||
100 | |||
101 | /* |
||
102 | * If the HREF is present outside of the attributes |
||
103 | * then pull it and put it in the attributes array. |
||
104 | */ |
||
105 | if (isset($action['url'])) { |
||
106 | $action['attributes']['url'] = array_pull($action, 'url'); |
||
107 | } |
||
108 | |||
109 | /* |
||
110 | * Set defaults as expected for actions. |
||
111 | */ |
||
112 | $action['size'] = array_get($action, 'small', 'sm'); |
||
113 | $action['disabled'] = array_get($action, 'disabled', array_get($action, 'toggle', true)); |
||
114 | |||
115 | $action['attributes']['name'] = $prefix . 'action'; |
||
116 | $action['attributes']['value'] = $action['slug']; |
||
117 | |||
118 | // If not toggle add the ignore attribute. |
||
119 | if (array_get($action, 'toggle', true) === false) { |
||
120 | $action['attributes']['data-ignore'] = ''; |
||
121 | } |
||
122 | |||
123 | View Code Duplication | if (isset($action['dropdown'])) { |
|
124 | foreach ($action['dropdown'] as $key => &$dropdown) { |
||
125 | $dropdown = $this->process($prefix, $key, $dropdown); |
||
126 | } |
||
127 | } |
||
128 | |||
129 | return $action; |
||
130 | } |
||
131 | } |
||
132 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.