Conditions | 13 |
Paths | 12 |
Total Lines | 34 |
Code Lines | 26 |
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 |
||
38 | } |
||
39 | $lastc = $data[$length - 1]; |
||
40 | if (';' !== $lastc && '}' !== $lastc) { |
||
41 | return false; |
||
42 | } |
||
43 | $token = $data[0]; |
||
44 | switch ($token) { |
||
45 | case 's': |
||
46 | return ('"' === $data[$length - 2]); |
||
47 | case 'a': |
||
48 | case 'O': |
||
49 | return (bool)preg_match("/^{$token}:[0-9]+:/s", $data); |
||
50 | case 'b': |
||
51 | case 'i': |
||
52 | case 'd': |
||
53 | return (bool)preg_match("/^{$token}:[0-9.E-]+;\$/", $data); |
||
54 | } |
||
55 | |||
56 | return false; |
||
57 | } |
||
58 | } |
||
59 | |||
60 | if (! function_exists('var_switch')) { |
||
61 | /** |
||
62 | * Поменять местами значения двух переменных |
||
63 | * |
||
64 | * @param $var1 |
||
65 | * @param $var2 |
||
66 | * @return void |
||
67 | */ |
||
68 | function var_switch(&$var1, &$var2) |
||
69 | { |
||
70 | list($var2, $var1) = [$var1, $var2]; |
||
|
|||
71 | } |
||
72 | } |
||
89 |