| Conditions | 6 |
| Paths | 18 |
| Total Lines | 62 |
| Code Lines | 46 |
| Lines | 62 |
| Ratio | 100 % |
| 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 |
||
| 151 | View Code Duplication | public function search_for_base_path($filepath) |
|
| 152 | { |
||
| 153 | $dirarray = [ |
||
| 154 | 'backdrop', |
||
| 155 | 'battle', |
||
| 156 | 'battle2', |
||
| 157 | 'battlecharset', |
||
| 158 | 'battleweapon', |
||
| 159 | 'charset', |
||
| 160 | 'chipset', |
||
| 161 | 'faceset', |
||
| 162 | 'frame', |
||
| 163 | 'gameover', |
||
| 164 | 'monster', |
||
| 165 | 'panorama', |
||
| 166 | 'picture', |
||
| 167 | 'system', |
||
| 168 | 'system2', |
||
| 169 | 'title', |
||
| 170 | 'music', |
||
| 171 | 'sound', |
||
| 172 | ]; |
||
| 173 | |||
| 174 | $rootarray = [ |
||
| 175 | 'harmony.dll', |
||
| 176 | 'rpg_rt.exe', |
||
| 177 | 'rpg_rt.ini', |
||
| 178 | 'rpg_rt.ldb', |
||
| 179 | 'rpg_rt.lmt', |
||
| 180 | 'rpg_rt.dat', |
||
| 181 | ]; |
||
| 182 | |||
| 183 | $mapparray = []; |
||
| 184 | for ($i = 0; $i < 2000; $i++) { |
||
| 185 | $mapparray[] = 'map'.sprintf('%04d', $i).'.lmu'; |
||
| 186 | } |
||
| 187 | |||
| 188 | $filearray = array_merge($rootarray, $mapparray); |
||
| 189 | |||
| 190 | $searcharray = array_merge($dirarray, $filearray); |
||
| 191 | |||
| 192 | if (starts_with(strtolower($filepath), $searcharray)) { |
||
| 193 | $imp = str_replace('/', '\\/', $filepath); |
||
| 194 | } else { |
||
| 195 | if (str_contains(strtolower($filepath), $searcharray)) { |
||
| 196 | $exp = explode('/', $filepath); |
||
| 197 | $res = array_shift($exp); |
||
| 198 | $imp = implode('/', $exp); |
||
| 199 | $imp = $this->search_for_base_path($imp); |
||
| 200 | } else { |
||
| 201 | $imp = ''; |
||
| 202 | } |
||
| 203 | } |
||
| 204 | |||
| 205 | if ($imp != '') { |
||
| 206 | if (array_search(strtolower($imp), $filearray)) { |
||
| 207 | $imp = '.\\/'.$imp; |
||
| 208 | } |
||
| 209 | } |
||
| 210 | |||
| 211 | return $imp; |
||
| 212 | } |
||
| 213 | } |
||
| 214 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.