| Conditions | 2 |
| Paths | 2 |
| Total Lines | 89 |
| Code Lines | 81 |
| 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 |
||
| 96 | private function renameIfPhpReservedWord($name) |
||
| 97 | { |
||
| 98 | $keywords = [ |
||
| 99 | //PHP7 |
||
| 100 | 'int', |
||
| 101 | 'float', |
||
| 102 | 'bool', |
||
| 103 | 'string', |
||
| 104 | 'true', |
||
| 105 | 'false', |
||
| 106 | 'null', |
||
| 107 | 'resource', |
||
| 108 | 'object', |
||
| 109 | 'mixed', |
||
| 110 | 'numeric', |
||
| 111 | //PHP7 and under |
||
| 112 | '__halt_compiler', |
||
| 113 | 'abstract', |
||
| 114 | 'and', |
||
| 115 | 'array', |
||
| 116 | 'as', |
||
| 117 | 'break', |
||
| 118 | 'callable', |
||
| 119 | 'case', |
||
| 120 | 'catch', |
||
| 121 | 'class', |
||
| 122 | 'clone', |
||
| 123 | 'const', |
||
| 124 | 'continue', |
||
| 125 | 'declare', |
||
| 126 | 'default', |
||
| 127 | 'die', |
||
| 128 | 'do', |
||
| 129 | 'echo', |
||
| 130 | 'else', |
||
| 131 | 'elseif', |
||
| 132 | 'empty', |
||
| 133 | 'enddeclare', |
||
| 134 | 'endfor', |
||
| 135 | 'endforeach', |
||
| 136 | 'endif', |
||
| 137 | 'endswitch', |
||
| 138 | 'endwhile', |
||
| 139 | 'eval', |
||
| 140 | 'exit', |
||
| 141 | 'extends', |
||
| 142 | 'final', |
||
| 143 | 'for', |
||
| 144 | 'foreach', |
||
| 145 | 'function', |
||
| 146 | 'global', |
||
| 147 | 'goto', |
||
| 148 | 'if', |
||
| 149 | 'implements', |
||
| 150 | 'include', |
||
| 151 | 'include_once', |
||
| 152 | 'instanceof', |
||
| 153 | 'insteadof', |
||
| 154 | 'interface', |
||
| 155 | 'isset', |
||
| 156 | 'list', |
||
| 157 | 'namespace', |
||
| 158 | 'new', |
||
| 159 | 'or', |
||
| 160 | 'print', |
||
| 161 | 'private', |
||
| 162 | 'protected', |
||
| 163 | 'public', |
||
| 164 | 'require', |
||
| 165 | 'require_once', |
||
| 166 | 'return', |
||
| 167 | 'static', |
||
| 168 | 'switch', |
||
| 169 | 'throw', |
||
| 170 | 'trait', |
||
| 171 | 'try', |
||
| 172 | 'unset', |
||
| 173 | 'use', |
||
| 174 | 'var', |
||
| 175 | 'while', |
||
| 176 | 'xor', |
||
| 177 | ]; |
||
| 178 | |||
| 179 | if (in_array(strtolower($name), $keywords, true)) { |
||
| 180 | $name = $name.'Type'; |
||
| 181 | } |
||
| 182 | |||
| 183 | return $name; |
||
| 184 | } |
||
| 185 | |||
| 243 |