Conditions | 11 |
Paths | 10 |
Total Lines | 28 |
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 |
||
33 | public static function import($id) |
||
34 | { |
||
35 | if ($id instanceof static) { |
||
36 | return $id; |
||
37 | } elseif ($id instanceof \MongoId) { |
||
38 | $id = (string)$id; |
||
39 | } elseif (!is_string($id)) { |
||
40 | if (is_array($id) && isset($id['$id'])) { |
||
41 | return static::import($id['$id']); |
||
42 | } |
||
43 | return false; |
||
44 | } elseif (mb_orig_strlen($id) === 24) { |
||
45 | if (!ctype_xdigit($id)) { |
||
46 | return false; |
||
47 | } |
||
48 | } elseif (ctype_alnum($id)) { |
||
49 | $id = gmp_strval(gmp_init(strrev($id), 62), 16); |
||
50 | if (mb_orig_strlen($id) > 24) { |
||
51 | return false; |
||
52 | } |
||
53 | if (mb_orig_strlen($id) < 24) { |
||
54 | $id = str_pad($id, 24, '0', STR_PAD_LEFT); |
||
55 | } |
||
56 | } else { |
||
57 | return false; |
||
58 | } |
||
59 | return new static($id); |
||
60 | } |
||
61 | |||
89 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.