Conditions | 11 |
Paths | 11 |
Total Lines | 31 |
Code Lines | 17 |
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 |
||
24 | public static function hash($value) |
||
25 | { |
||
26 | $typeIdentifier = gettype($value)[0]; |
||
27 | |||
28 | switch ($typeIdentifier) { |
||
29 | |||
30 | case 's': //string |
||
31 | |||
32 | return 's' . (strlen($value) > 32 ? md5($value) : $value); |
||
33 | |||
34 | case 'i': //integer |
||
35 | case 'b': //boolean |
||
36 | case 'd': //double |
||
37 | case 'r': //resource |
||
38 | case 'u': //unknown type |
||
39 | |||
40 | return $typeIdentifier . $value; |
||
41 | |||
42 | case 'N': //NULL |
||
43 | |||
44 | return 'N'; |
||
45 | |||
46 | case 'o': //object |
||
47 | |||
48 | return 'o' . spl_object_hash($value); |
||
49 | |||
50 | case 'a': //array |
||
51 | |||
52 | return self::arrayHash($value); |
||
53 | } |
||
54 | } |
||
55 | |||
80 |