Conditions | 15 |
Paths | 1280 |
Total Lines | 23 |
Code Lines | 12 |
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 |
||
43 | final protected function bootstrapGrid($lg, $md, $sm, $xs, $recopy, $prefix) { |
||
44 | |||
45 | // Recopy. |
||
46 | foreach ([&$lg, &$md, &$sm, &$xs] as &$current) { |
||
|
|||
47 | if (1 <= $current && $current <= 12) { |
||
48 | $found = $current; |
||
49 | } |
||
50 | if (null === $current && true === $recopy && true === (isset($found))) { |
||
51 | $current = $found; |
||
52 | } |
||
53 | } |
||
54 | |||
55 | // Initialize the columns. |
||
56 | $columns = []; |
||
57 | |||
58 | $columns[] = 1 <= $lg && $lg <= 12 ? "col-lg-" . $prefix . $lg : null; |
||
59 | $columns[] = 1 <= $md && $md <= 12 ? "col-md-" . $prefix . $md : null; |
||
60 | $columns[] = 1 <= $sm && $sm <= 12 ? "col-sm-" . $prefix . $sm : null; |
||
61 | $columns[] = 1 <= $xs && $xs <= 12 ? "col-xs-" . $prefix . $xs : null; |
||
62 | |||
63 | // Return the columns. |
||
64 | return trim(implode(" ", $columns)); |
||
65 | } |
||
66 | |||
68 |
Let?s assume that you have the following
foreach
statement:$itemValue
is assigned by reference. This is possible because the expression (in the example$array
) can be used as a reference target.However, if we were to replace
$array
with something different like the result of a function call as inthen assigning by reference is not possible anymore as there is no target that could be modified.
Available Fixes
1. Do not assign by reference
2. Assign to a local variable first
3. Return a reference