| Conditions | 19 |
| Paths | 50 |
| Total Lines | 105 |
| Code Lines | 71 |
| Lines | 5 |
| Ratio | 4.76 % |
| 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 |
||
| 45 | public function handle() |
||
| 46 | { |
||
| 47 | $this->info('Lade Gamefiles ohne index.json'); |
||
| 48 | |||
| 49 | $gamefiles = GamesFile::with('game')->get(); |
||
| 50 | |||
| 51 | $counter = 0; |
||
| 52 | $toindexed = []; |
||
| 53 | |||
| 54 | foreach ($gamefiles as $gamefile) { |
||
| 55 | if ($gamefile->game) { |
||
| 56 | $makerid = $gamefile->game->maker_id; |
||
| 57 | //echo $makerid.' - '.$gamefile->id.PHP_EOL; |
||
| 58 | if ($makerid == 2 or |
||
| 59 | $makerid == 3 or |
||
| 60 | $makerid == 6 or |
||
| 61 | $makerid == 9 or |
||
| 62 | $makerid == 11) { |
||
| 63 | // RPG2k/2k3/MV |
||
| 64 | if ($gamefile->playerIndex()->count() == 0) { |
||
| 65 | $toindexed[] = $gamefile; |
||
| 66 | $this->info('ADD '.$gamefile->game->title); |
||
| 67 | $counter += 1; |
||
| 68 | } |
||
| 69 | } |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | $this->info('Es wurden '.$counter.' Gamefiles gefunden.'); |
||
| 74 | |||
| 75 | $bar = $this->output->createProgressBar(count($toindexed)); |
||
| 76 | $bar->setFormat(" \033[44;37m %title:-37s% \033[0m\n %current%/%max% %bar% %percent:3s%%\n %remaining:-10s% %memory:37s%"); |
||
| 77 | $bar->setBarCharacter($done = "\033[32m●\033[0m"); |
||
| 78 | $bar->setEmptyBarCharacter($empty = "\033[31m●\033[0m"); |
||
| 79 | $bar->setProgressCharacter($progress = "\033[32m➤ \033[0m"); |
||
| 80 | $bar->setMessage('Starte indizierung der Gamefiles', 'title'); |
||
| 81 | $bar->start(); |
||
| 82 | |||
| 83 | $i = 0; |
||
| 84 | foreach ($toindexed as $toindex) { |
||
| 85 | $bar->setMessage('Entpacken von: '.$toindex->game_id.'/'.$toindex->id, 'title'); |
||
| 86 | \Log::info('Entpacken von '.$toindex->game_id.'/'.$toindex->id); |
||
| 87 | $path = storage_path('app/public/'.$toindex->filename); |
||
| 88 | if ($toindex->extension == 'zip') { |
||
| 89 | $zip = new \ZipArchive(); |
||
| 90 | $zip->open($path); |
||
| 91 | $makerid = $toindex->game->maker_id; |
||
| 92 | if ($makerid == 6) { |
||
| 93 | // RPG Maker MV |
||
| 94 | // Nur Pfad zum "www/" Ordner noetig |
||
| 95 | for ($i = 0; $i < $zip->numFiles; $i++) { |
||
| 96 | $filename = $zip->getNameIndex($i); |
||
| 97 | $this->info('Saved XXX basepath: '.$filename); |
||
| 98 | if (ends_with($filename, 'www/')) { |
||
| 99 | $pl = new PlayerIndexjson(); |
||
| 100 | $pl->gamefile_id = $toindex->id; |
||
| 101 | $pl->key = 'www'; |
||
| 102 | $pl->value = $filename; |
||
| 103 | $pl->filename = $filename; |
||
| 104 | $pl->save(); |
||
| 105 | |||
| 106 | \Log::info('Saved basepath: '.$filename); |
||
| 107 | break; |
||
| 108 | } |
||
| 109 | } |
||
| 110 | } else { |
||
| 111 | // RPG Maker 2k/2k3 |
||
| 112 | for ($i = 0; $i < $zip->numFiles; $i++) { |
||
| 113 | $filename = $zip->getNameIndex($i); |
||
| 114 | |||
| 115 | if (! ends_with($filename, '/') and ! starts_with($filename, '_MACOSX')) { |
||
| 116 | $imp = $this->search_for_base_path($filename); |
||
| 117 | |||
| 118 | if (! $imp == '') { |
||
| 119 | $pl = new PlayerIndexjson(); |
||
| 120 | $pl->gamefile_id = $toindex->id; |
||
| 121 | View Code Duplication | if (! ends_with(strtolower($imp), ['.exe', '.lmu', '.ldb', 'ini', '.dll', 'lmt', 'lsd'])) { |
|
| 122 | $pl->key = preg_replace('/(\.\w+$)/', '', strtolower($imp)); |
||
| 123 | } else { |
||
| 124 | $pl->key = strtolower($imp); |
||
| 125 | } |
||
| 126 | $pl->value = $imp; |
||
| 127 | $pl->filename = 'www'; |
||
| 128 | $pl->save(); |
||
| 129 | |||
| 130 | \Log::info('Saved basepath: '.$filename); |
||
| 131 | } else { |
||
| 132 | \Log::info('Empty basepath: '.$filename); |
||
| 133 | } |
||
| 134 | } |
||
| 135 | } |
||
| 136 | } |
||
| 137 | @$zip->close(); |
||
| 138 | } else { |
||
| 139 | continue; |
||
| 140 | } |
||
| 141 | |||
| 142 | //return; |
||
| 143 | $bar->advance(); |
||
| 144 | } |
||
| 145 | |||
| 146 | $bar->finish(); |
||
| 147 | |||
| 148 | $this->info('Fertig.'); |
||
| 149 | } |
||
| 150 | |||
| 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.