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 | namespace carono\janitor; |
||
4 | |||
5 | use carono\janitor\engines\EngineAbstract; |
||
6 | use carono\janitor\helpers\Console; |
||
7 | use carono\janitor\helpers\FileHelper; |
||
8 | |||
9 | /** |
||
10 | * Class Cli |
||
11 | * |
||
12 | * @package carono\janitor |
||
13 | */ |
||
14 | class Cli |
||
15 | { |
||
16 | public static $renamedFile = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'renamed.json'; |
||
17 | public static $cacheFile = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'cache.json'; |
||
18 | public static $temporaryDir = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'tmp'; |
||
19 | |||
20 | protected static function getFileTypeMessage(File $file) |
||
21 | { |
||
22 | $message = 'File type: '; |
||
23 | if ($file->isFilm()) { |
||
24 | $message .= 'Movie'; |
||
25 | } else { |
||
26 | $message .= 'Serial, Season ' . $file->getSeasonNumber() . ' Episode ' . $file->getEpisodeNumber(); |
||
27 | } |
||
28 | return $message; |
||
29 | } |
||
30 | |||
31 | protected static function out($text = '', $newLine = true) |
||
32 | { |
||
33 | echo $text . ($newLine ? "\n" : ''); |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * @param $dir |
||
38 | */ |
||
39 | public static function reformFiles($dir) |
||
40 | { |
||
41 | /** |
||
42 | * @var File $file |
||
43 | */ |
||
44 | $files = static::getFiles($dir); |
||
45 | $renameAll = false; |
||
46 | $fileModels = array_map(function ($path) { |
||
47 | return new File(static::getEngine(), $path); |
||
0 ignored issues
–
show
|
|||
48 | }, $files); |
||
49 | $i = 0; |
||
50 | $selectedName = null; |
||
0 ignored issues
–
show
$selectedName 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 ![]() |
|||
51 | $request = null; |
||
52 | while ($file = array_shift($fileModels)) { |
||
53 | $value = null; |
||
54 | if ($file->wasRenamed()) { |
||
55 | echo "{$file->getFilePath()} SKIP\n"; |
||
56 | continue; |
||
57 | } |
||
58 | |||
59 | $options = [ |
||
60 | 'r' => 'Confirm rename', |
||
61 | 's' => 'Skip file', |
||
62 | 'c' => 'Custom name for search', |
||
63 | 'n' => 'Next title', |
||
64 | 'i' => 'Ignore this file' |
||
65 | ]; |
||
66 | |||
67 | if ($file->isSerial()) { |
||
68 | $options['a'] = 'All rename for serial'; |
||
69 | } |
||
70 | |||
71 | $selectedName = $file->getStoredSerialName(); |
||
72 | |||
73 | if (!$renameAll || !$file->getStoredSerialName()) { |
||
74 | $renameAll = false; |
||
75 | $names = $file->searchFilmNames($request); |
||
76 | Console::clearScreen(); |
||
77 | |||
78 | if ($file->getStoredSerialName()) { |
||
79 | $file->restoreSerialData(); |
||
80 | if (($i = array_search($selectedName, $names)) === false) { |
||
81 | $i = []; |
||
82 | } |
||
83 | } else { |
||
84 | $selectedName = $names[$i]; |
||
85 | } |
||
86 | |||
87 | $reformedFileName = $file->getReformFileName($selectedName); |
||
88 | |||
89 | Console::selectBox('Select correct title:', $names, $i); |
||
90 | self::out(); |
||
91 | self::out("Original file: {$file->getFileName()}"); |
||
92 | self::out("New file name: {$reformedFileName}"); |
||
93 | if ($file->isSerial()) { |
||
94 | self::out('Files in directory: ' . count(FileHelper::findFiles($file->getFolder()))); |
||
95 | } |
||
96 | self::out(); |
||
97 | $value = Console::select('What do?', $options); |
||
98 | |||
99 | } else { |
||
100 | echo $file->getFilePath() . ' => ' . $file->getReformFilmName($selectedName) . ": Renamed\n"; |
||
101 | } |
||
102 | |||
103 | if ($value === 'i') { |
||
104 | $file->storeRename(); |
||
105 | continue; |
||
106 | } |
||
107 | |||
108 | if ($value === 'n') { |
||
109 | $i++; |
||
110 | if (!isset($names[$i])) { |
||
111 | $i = 0; |
||
112 | } |
||
113 | } |
||
114 | |||
115 | if ($value === 'a') { |
||
116 | $renameAll = true; |
||
117 | } |
||
118 | |||
119 | if ($value === 'r' || $value === 'a' || $renameAll) { |
||
120 | $file->renameFile($selectedName); |
||
121 | $i = 0; |
||
122 | continue; |
||
123 | } |
||
124 | |||
125 | if ($value === 'c') { |
||
126 | $request = Console::prompt('Write film name for searching:'); |
||
127 | } |
||
128 | |||
129 | array_unshift($fileModels, $file); |
||
130 | } |
||
131 | } |
||
132 | |||
133 | /** |
||
134 | * @param $dir |
||
135 | */ |
||
136 | public static function reform($dir) |
||
137 | { |
||
138 | static::reformFiles(realpath($dir)); |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * @param $name |
||
143 | * @param $season |
||
144 | * @return string |
||
145 | */ |
||
146 | public static function getSerialFolderName($name, $season) |
||
147 | { |
||
148 | $name = pathinfo($name, PATHINFO_FILENAME); |
||
149 | return $name . ' сезон ' . $season; |
||
150 | } |
||
151 | |||
152 | /** |
||
153 | * @param $dir |
||
154 | * @return array |
||
155 | */ |
||
156 | protected static function getFiles($dir) |
||
157 | { |
||
158 | return FileHelper::findFiles($dir); |
||
159 | } |
||
160 | |||
161 | /** |
||
162 | * @param $name |
||
163 | * @return bool |
||
164 | */ |
||
165 | public static function extractYear($name) |
||
166 | { |
||
167 | if (preg_match_all('/(\d{4})/', $name, $m)) { |
||
168 | foreach ($m[0] as $year) { |
||
169 | if ($year > 1900 && $year <= date('Y')) { |
||
170 | return $year; |
||
171 | } |
||
172 | } |
||
173 | } |
||
174 | return false; |
||
175 | } |
||
176 | |||
177 | /** |
||
178 | * @param null $season |
||
179 | * @param null $episode |
||
180 | * @return string |
||
181 | */ |
||
182 | public static function getEpisodeName($season = null, $episode = null) |
||
183 | { |
||
184 | $season = str_pad($season, 2, '0', STR_PAD_LEFT); |
||
185 | $episode = str_pad($episode, 2, '0', STR_PAD_LEFT); |
||
186 | return "s{$season}e{$episode}"; |
||
187 | } |
||
188 | |||
189 | /** |
||
190 | * @return EngineAbstract |
||
191 | */ |
||
192 | public static function getEngine() |
||
193 | { |
||
194 | $class = getenv('SEARCH_ENGINE'); |
||
195 | if (!class_exists($class)) { |
||
196 | die("Class $class not found\n"); |
||
197 | } |
||
198 | return new $class; |
||
199 | } |
||
200 | } |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: