| 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 |
||
| 30 | View Code Duplication | public function getZipRootPath($zipfilepath) |
|
| 31 | { |
||
| 32 | $dirarray = [ |
||
| 33 | 'backdrop', |
||
| 34 | 'battle', |
||
| 35 | 'battle2', |
||
| 36 | 'battlecharset', |
||
| 37 | 'battleweapon', |
||
| 38 | 'charset', |
||
| 39 | 'chipset', |
||
| 40 | 'faceset', |
||
| 41 | 'frame', |
||
| 42 | 'gameover', |
||
| 43 | 'monster', |
||
| 44 | 'panorama', |
||
| 45 | 'picture', |
||
| 46 | 'system', |
||
| 47 | 'system2', |
||
| 48 | 'title', |
||
| 49 | 'music', |
||
| 50 | 'sound', |
||
| 51 | ]; |
||
| 52 | |||
| 53 | $rootarray = [ |
||
| 54 | 'harmony.dll', |
||
| 55 | 'rpg_rt.exe', |
||
| 56 | 'rpg_rt.ini', |
||
| 57 | 'rpg_rt.ldb', |
||
| 58 | 'rpg_rt.lmt', |
||
| 59 | 'rpg_rt.dat', |
||
| 60 | ]; |
||
| 61 | |||
| 62 | $mapparray = []; |
||
| 63 | for ($i = 0; $i < 2000; $i++) { |
||
| 64 | $mapparray[] = 'map'.sprintf('%04d', $i).'.lmu'; |
||
| 65 | } |
||
| 66 | |||
| 67 | $filearray = array_merge($rootarray, $mapparray); |
||
| 68 | |||
| 69 | $searcharray = array_merge($dirarray, $filearray); |
||
| 70 | |||
| 71 | if (starts_with(strtolower($zipfilepath), $searcharray)) { |
||
| 72 | $imp = str_replace('/', '\\/', $zipfilepath); |
||
| 73 | } else { |
||
| 74 | if (str_contains(strtolower($zipfilepath), $searcharray)) { |
||
| 75 | $exp = explode('/', $zipfilepath); |
||
| 76 | $res = array_shift($exp); |
||
| 77 | $imp = implode('/', $exp); |
||
| 78 | $imp = $this->getZipRootPath($imp); |
||
| 79 | } else { |
||
| 80 | $imp = ''; |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | if ($imp != '') { |
||
| 85 | if (array_search(strtolower($imp), $filearray)) { |
||
| 86 | $imp = '.\\/'.$imp; |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | return $imp; |
||
| 91 | } |
||
| 92 | } |
||
| 93 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.