Conditions | 9 |
Paths | 1 |
Total Lines | 60 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
80 | public static function init() |
||
81 | { |
||
82 | self::$identity = function($x) { return $x; }; |
||
83 | |||
84 | /** @noinspection PhpUnusedParameterInspection */ |
||
85 | self::$key = function($v, $k) { return $k; }; |
||
86 | |||
87 | /** @noinspection PhpUnusedParameterInspection */ |
||
88 | self::$value = function($v, $k) { return $v; }; |
||
89 | |||
90 | self::$true = function() { return true; }; |
||
91 | |||
92 | self::$false = function() { return false; }; |
||
93 | |||
94 | self::$blank = function() { }; |
||
95 | |||
96 | self::$compareStrict = function($a, $b) { |
||
97 | if ($a === $b) |
||
98 | return 0; |
||
99 | elseif ($a > $b) |
||
100 | return 1; |
||
101 | else |
||
102 | return -1; |
||
103 | }; |
||
104 | |||
105 | self::$compareStrictReversed = function($a, $b) { |
||
106 | if ($a === $b) |
||
107 | return 0; |
||
108 | elseif ($a > $b) |
||
109 | return -1; |
||
110 | else |
||
111 | return 1; |
||
112 | }; |
||
113 | |||
114 | self::$compareLoose = function($a, $b) { |
||
115 | if ($a == $b) |
||
116 | return 0; |
||
117 | elseif ($a > $b) |
||
118 | return 1; |
||
119 | else |
||
120 | return -1; |
||
121 | }; |
||
122 | |||
123 | self::$compareLooseReversed = function($a, $b) { |
||
124 | if ($a == $b) |
||
125 | return 0; |
||
126 | elseif ($a > $b) |
||
127 | return -1; |
||
128 | else |
||
129 | return 1; |
||
130 | }; |
||
131 | |||
132 | self::$compareInt = function($a, $b) { |
||
133 | return $a - $b; |
||
134 | }; |
||
135 | |||
136 | self::$compareIntReversed = function($a, $b) { |
||
137 | return $b - $a; |
||
138 | }; |
||
139 | } |
||
140 | |||
151 |