Conditions | 14 |
Paths | 28 |
Total Lines | 98 |
Code Lines | 46 |
Lines | 5 |
Ratio | 5.1 % |
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 |
||
47 | public function handle() |
||
48 | { |
||
49 | $this->info('Lade Gamefiles ohne index.json'); |
||
50 | |||
51 | //Get all game files |
||
52 | $gamefiles = GamesFile::all(); |
||
53 | |||
54 | $counter = 0; |
||
55 | $toindexed = []; |
||
56 | |||
57 | //loop all gamefiles |
||
58 | foreach ($gamefiles as $gamefile) { |
||
59 | echo $gamefile->id.PHP_EOL; |
||
60 | //Get the maker id |
||
61 | $makerid = $gamefile->game()->first()->maker_id; |
||
62 | |||
63 | //Run code only for rm2k(3) |
||
64 | //Todo: Engine filter can be done with Query |
||
65 | if ($makerid == 2 or $makerid == 3 or $makerid == 9) { |
||
66 | //Get path to uploaded files |
||
67 | $path = storage_path('app/public/'.$gamefile->filename); |
||
68 | |||
69 | //use only zip fiels |
||
70 | //Todo: ZIP filter can be done with Query |
||
71 | if ($gamefile->extension == 'zip') { |
||
72 | //Open the ZIP file |
||
73 | $zip = new \ZipArchive(); |
||
74 | $zip->open($path); |
||
75 | |||
76 | //Run through all files in ZIP |
||
77 | for ($i = 0; $i < $zip->numFiles; $i++) { |
||
78 | //Get the filename with fileindex |
||
79 | $filename = $zip->getNameIndex($i); |
||
80 | |||
81 | //Filter Directory and _MACOSX from index |
||
82 | if (! ends_with($filename, '/') and ! starts_with($filename, '_MACOSX')) { |
||
83 | |||
84 | //Get root path of the file |
||
85 | $phelper = new PlayerHelper(); |
||
86 | $imp = $phelper->getZipRootPath($filename); |
||
87 | |||
88 | //if root path not '' |
||
89 | if (! $imp == '') { |
||
90 | $rel = new PlayerFileGamefileRel(); |
||
91 | $rel->gamefile_id = $gamefile->id; |
||
92 | |||
93 | View Code Duplication | if (! ends_with(strtolower($imp), ['.exe', '.lmu', '.ldb', 'ini', '.dll', 'lmt', 'lsd'])) { |
|
94 | $rel->orig_filename = preg_replace('/(\.\w+$)/', '', strtolower($imp)); |
||
95 | } else { |
||
96 | $rel->orig_filename = strtolower($imp); |
||
97 | } |
||
98 | |||
99 | //Decompress data |
||
100 | $filedata = $zip->getFromIndex($i); |
||
101 | //create hash of the file |
||
102 | $filehash = hash('sha1', $filedata); |
||
103 | |||
104 | //get storage path to hashed directory |
||
105 | $newfilepath = storage_path('app/public/games_hashed/'.substr($filehash, 0, 2).'/'); |
||
106 | |||
107 | //check for directory existance |
||
108 | if (! file_exists($newfilepath)) { |
||
109 | mkdir($newfilepath); |
||
110 | } |
||
111 | |||
112 | //write decompressed data to a new file to the storage path |
||
113 | file_put_contents($newfilepath.$filehash, $filedata); |
||
114 | |||
115 | //check for Database existance of this file |
||
116 | $check = PlayerFileHash::whereFilehash($filehash)->first(); |
||
117 | if (! $check) { |
||
118 | //create a new record to player_file_hash table |
||
119 | $pfh = new PlayerFileHash(); |
||
120 | $pfh->filehash = $filehash; |
||
121 | $pfh->save(); |
||
122 | |||
123 | $rel->file_hash_id = $pfh->id; |
||
124 | } else { |
||
125 | $rel->file_hash_id = $check->id; |
||
126 | } |
||
127 | |||
128 | $rel->save(); |
||
129 | } |
||
130 | } |
||
131 | } |
||
132 | $zip->close(); |
||
133 | } else { |
||
134 | continue; |
||
135 | } |
||
136 | } |
||
137 | } |
||
138 | |||
139 | $this->info('Es wurden '.$counter.' Gamefiles gefunden.'); |
||
140 | |||
141 | $i = 0; |
||
142 | foreach ($toindexed as $toindex) { |
||
143 | } |
||
144 | } |
||
145 | } |
||
146 |
Adding a
@return
annotation 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.