This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
|||||||||||
2 | ||||||||||||
3 | /* |
|||||||||||
4 | * rmarchiv.tk |
|||||||||||
5 | * (c) 2016-2017 by Marcel 'ryg' Hering |
|||||||||||
6 | */ |
|||||||||||
7 | ||||||||||||
8 | namespace App\Console\Commands; |
|||||||||||
9 | ||||||||||||
10 | use App\Models\GamesFile; |
|||||||||||
11 | use App\Helpers\PlayerHelper; |
|||||||||||
12 | use App\Models\PlayerFileHash; |
|||||||||||
13 | use Illuminate\Console\Command; |
|||||||||||
14 | use App\Models\PlayerFileGamefileRel; |
|||||||||||
15 | ||||||||||||
16 | class PT extends Command |
|||||||||||
17 | { |
|||||||||||
18 | /** |
|||||||||||
19 | * The name and signature of the console command. |
|||||||||||
20 | * |
|||||||||||
21 | * @var string |
|||||||||||
22 | */ |
|||||||||||
23 | protected $signature = 'player:test'; |
|||||||||||
24 | ||||||||||||
25 | /** |
|||||||||||
26 | * The console command description. |
|||||||||||
27 | * |
|||||||||||
28 | * @var string |
|||||||||||
29 | */ |
|||||||||||
30 | protected $description = 'creates the hash table for all rm2k(3) files'; |
|||||||||||
31 | ||||||||||||
32 | /** |
|||||||||||
33 | * Create a new command instance. |
|||||||||||
34 | * |
|||||||||||
35 | * @return void |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
36 | */ |
|||||||||||
37 | public function __construct() |
|||||||||||
38 | { |
|||||||||||
39 | parent::__construct(); |
|||||||||||
40 | } |
|||||||||||
41 | ||||||||||||
42 | /** |
|||||||||||
43 | * Execute the console command. |
|||||||||||
44 | * |
|||||||||||
45 | * @return mixed |
|||||||||||
46 | */ |
|||||||||||
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; |
|||||||||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space
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 $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
||||||||||||
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 |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
65 | if ($makerid == 2 or $makerid == 3 or $makerid == 9) { |
|||||||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Using logical operators such as
or instead of || is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. ![]() |
||||||||||||
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 |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
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')) { |
|||||||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Using logical operators such as
and instead of && is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. ![]() |
||||||||||||
83 | ||||||||||||
84 | //Get root path of the file |
|||||||||||
85 | $phelper = new PlayerHelper(); |
|||||||||||
86 | $imp = $phelper->getZipRootPath($filename); |
|||||||||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space
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 $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
||||||||||||
87 | ||||||||||||
88 | //if root path not '' |
|||||||||||
89 | if (! $imp == '') { |
|||||||||||
90 | $rel = new PlayerFileGamefileRel(); |
|||||||||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 14 spaces but found 1 space
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 $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
||||||||||||
91 | $rel->gamefile_id = $gamefile->id; |
|||||||||||
92 | ||||||||||||
93 | View Code Duplication | if (! ends_with(strtolower($imp), ['.exe', '.lmu', '.ldb', 'ini', '.dll', 'lmt', 'lsd'])) { |
||||||||||
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
||||||||||||
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(); |
|||||||||||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space
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 $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
||||||||||||
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; |
|||||||||||
0 ignored issues
–
show
$i is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
||||||||||||
142 | foreach ($toindexed as $toindex) { |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
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.