Conditions | 4 |
Paths | 2 |
Total Lines | 57 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 2 | Features | 1 |
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 |
||
53 | private static function transcript(array $errorInfo): array |
||
54 | { |
||
55 | list($state, $code, $message) = $errorInfo; |
||
56 | $functs = [ |
||
57 | // violation: column cannot be null |
||
58 | 1048 => function ($message) { |
||
59 | preg_match("#Column '(.+)' cannot be null#", $message, $m); |
||
60 | return ['FIELD_REQUIRED', $m[1]]; |
||
61 | }, |
||
62 | |||
63 | 1054 => function ($message) { |
||
64 | return ['COLUMN_DOES_NOT_EXIST', $message]; |
||
65 | }, |
||
66 | |||
67 | // violation: duplicate key |
||
68 | 1062 => function ($message) { |
||
69 | if (preg_match("#'([^']+)' for key '([^']+)'#", $message, $m)) { |
||
70 | $entry = $m[1]; |
||
71 | $key = $m[2]; |
||
72 | return ["DUPLICATE_KEY:$key:$entry"]; |
||
73 | } |
||
74 | |||
75 | if (preg_match("#for key '[a-z]+\.(.+)'$#", $message, $m) !== 1) { |
||
76 | preg_match("#for key '(.+)'$#", $message, $m); |
||
77 | } |
||
78 | |||
79 | return ["DUPLICATE_KEY:".$m[1]]; |
||
80 | }, |
||
81 | |||
82 | 1064 => function ($message) { |
||
83 | preg_match("#right syntax to use near '(.+)'#", $message, $m); |
||
84 | return ['SYNTAX_ERROR', $m[1]]; |
||
85 | }, |
||
86 | |||
87 | 1146 => function ($message) { |
||
88 | return ['TABLE_DOES_NOT_EXIST', $message]; |
||
89 | }, |
||
90 | |||
91 | 1264 => function ($message) { |
||
92 | preg_match("#for column '(.+)'#", $message, $m); |
||
93 | return ['VALUE_OUT_OF_RANGE', $m[1]]; |
||
94 | }, |
||
95 | |||
96 | 1364 => function ($message) { |
||
97 | return ['FIELD_REQUIRED', $message]; |
||
98 | }, |
||
99 | |||
100 | 1451 => function ($message) { |
||
101 | preg_match("#CONSTRAINT `(.+)` FOREIGN#", $message, $m); |
||
102 | return ['RELATIONAL_INTEGRITY', $m[1]]; |
||
103 | }, |
||
104 | |||
105 | ]; |
||
106 | if (isset($functs[$code])) |
||
107 | return [call_user_func($functs[$code], $message), $code]; |
||
108 | |||
109 | return ['FUBAR #' . $state . '-' . $code . '-' . $message, $code]; |
||
110 | } |
||
112 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.