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 | * Get all rar gamefiles and repack with zip |
||
8 | */ |
||
9 | |||
10 | namespace App\Console\Commands; |
||
11 | |||
12 | use App\Models\GamesFile; |
||
13 | use Illuminate\Console\Command; |
||
14 | |||
15 | class PlayerRar2Zip extends Command |
||
16 | { |
||
17 | /** |
||
18 | * The name and signature of the console command. |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | protected $signature = 'player:rar2zip'; |
||
23 | |||
24 | /** |
||
25 | * The console command description. |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $description = 'convert rar files to zip'; |
||
30 | |||
31 | /** |
||
32 | * Create a new command instance. |
||
33 | * |
||
34 | * @return void |
||
0 ignored issues
–
show
|
|||
35 | */ |
||
36 | public function __construct() |
||
37 | { |
||
38 | parent::__construct(); |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * Execute the console command. |
||
43 | * |
||
44 | * @return mixed |
||
45 | */ |
||
46 | public function handle() |
||
47 | { |
||
48 | //get all rar files from database |
||
49 | $files = GamesFile::whereExtension('rar')->orderBy('filesize', 'asc')->get(); |
||
0 ignored issues
–
show
The method
orderBy does only exist in Illuminate\Database\Query\Builder , but not in App\Models\GamesFile .
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
50 | |||
51 | foreach ($files as $f) { |
||
52 | //Check for maker engine 2=rm2k, 3=rm2k3, 9=rm2k3 Steam Edition |
||
53 | if (! array_search($f->game->maker_id, [2, 3, 6, 9, 11]) === false) { |
||
54 | echo "Gamefile: $f->filename"; |
||
0 ignored issues
–
show
As per coding-style, please use concatenation or
sprintf for the variable $f instead of interpolation.
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings. // Instead of
$x = "foo $bar $baz";
// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
![]() |
|||
55 | |||
56 | //prepare the path variables |
||
57 | $pathrar = storage_path('app/public/'.$f->filename); // Path to original rar file |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 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. ![]() |
|||
58 | $pathzip = storage_path('app/public/'.str_replace('.rar', '.zip', $f->filename)); //Path to zip destination |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 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. ![]() |
|||
59 | $pathdest = storage_path('app/public/games/'.$f->id.'/'); //destination for unrared files |
||
60 | |||
61 | //delete old temp files (just in case.) |
||
62 | $this->Delete($pathdest); |
||
63 | |||
64 | // unrar the rar archive |
||
65 | $command = 'unrar x \''.$pathrar.'\' '.$pathdest; |
||
66 | exec($command); |
||
67 | |||
68 | $handle = opendir($pathdest); // erm?? |
||
0 ignored issues
–
show
$handle 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 ![]() |
|||
69 | |||
70 | //zip previous decompressed files |
||
71 | $this->Zip($pathdest, $pathzip); |
||
72 | |||
73 | // Check for zip file |
||
74 | if(!file_exists($pathzip)){ |
||
75 | // zip file does not exist. debug & die. |
||
76 | dd($pathzip); |
||
77 | } |
||
78 | |||
79 | //delete decomressed files |
||
80 | $this->Delete($pathdest); |
||
81 | |||
82 | //Update the Database |
||
83 | $upd = GamesFile::whereId($f->id)->first(); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 12 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. ![]() |
|||
84 | $upd->extension = 'zip'; |
||
85 | $upd->filename = str_replace('.rar', '.zip', $f->filename); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 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. ![]() |
|||
86 | $upd->save(); |
||
87 | |||
88 | //delete rar file |
||
89 | unlink($pathrar); |
||
90 | |||
91 | echo " - done\n"; |
||
92 | } |
||
93 | } |
||
94 | } |
||
95 | |||
96 | public function Delete($path) |
||
97 | { |
||
98 | // check for directory is not a file |
||
99 | if (is_dir($path) === true) { |
||
100 | // get all files and directorys recursive from all directorys |
||
101 | $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path), \RecursiveIteratorIterator::CHILD_FIRST); |
||
102 | |||
103 | foreach ($files as $file) { |
||
104 | // if file is . or .. skip |
||
105 | if (in_array($file->getBasename(), ['.', '..']) !== true) { |
||
106 | // if $file is a directory |
||
107 | if ($file->isDir() === true) { |
||
108 | // delete directory |
||
109 | rmdir($file->getPathName()); |
||
110 | } elseif (($file->isFile() === true) || ($file->isLink() === true)) { // or a file |
||
111 | // delete file |
||
112 | unlink($file->getPathname()); |
||
113 | } |
||
114 | } |
||
115 | } |
||
116 | |||
117 | return rmdir($path); |
||
118 | } elseif ((is_file($path) === true) || (is_link($path) === true)) { |
||
119 | return unlink($path); |
||
120 | } |
||
121 | |||
122 | return false; |
||
123 | } |
||
124 | |||
125 | public function Zip($source, $destination) |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
126 | { |
||
127 | // check for php_zip extension and file existance |
||
128 | if (! extension_loaded('zip') || ! file_exists($source)) { |
||
129 | return false; |
||
130 | } |
||
131 | |||
132 | // create ZipArchive Object |
||
133 | $zip = new \ZipArchive(); |
||
134 | |||
135 | // Create a new ZIP |
||
136 | if (! $zip->open($destination, \ZIPARCHIVE::CREATE)) { |
||
137 | return false; |
||
138 | } |
||
139 | |||
140 | $source = str_replace('\\', '/', realpath($source)); |
||
141 | |||
142 | if (is_dir($source) === true) { |
||
143 | $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source), \RecursiveIteratorIterator::SELF_FIRST); |
||
144 | |||
145 | foreach ($files as $file) { |
||
146 | $file = str_replace('\\', '/', $file); |
||
147 | |||
148 | // Ignore "." and ".." folders |
||
149 | if (in_array(substr($file, strrpos($file, '/') + 1), ['.', '..'])) { |
||
150 | continue; |
||
151 | } |
||
152 | |||
153 | $file = realpath($file); |
||
154 | |||
155 | if (is_dir($file) === true) { |
||
156 | $zip->addEmptyDir(str_replace($source.'/', '', $file.'/')); |
||
157 | } elseif (is_file($file) === true) { |
||
158 | $zip->addFromString(str_replace($source.'/', '', $file), file_get_contents($file)); |
||
159 | } |
||
160 | } |
||
161 | } elseif (is_file($source) === true) { |
||
162 | $zip->addFromString(basename($source), file_get_contents($source)); |
||
163 | } |
||
164 | |||
165 | return $zip->close(); |
||
166 | } |
||
167 | } |
||
168 |
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.