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 | namespace carono\janitor\engines; |
||
5 | |||
6 | |||
7 | use carono\janitor\Cli; |
||
8 | use carono\janitor\File; |
||
9 | use carono\janitor\helpers\FileHelper; |
||
10 | use Symfony\Component\Cache\Adapter\FilesystemAdapter; |
||
11 | |||
12 | abstract class EngineAbstract implements EngineInterface |
||
13 | { |
||
14 | protected static $cacheClass = FilesystemAdapter::class; |
||
15 | protected static $cache; |
||
16 | |||
17 | public function getOptions() |
||
18 | { |
||
19 | return [ |
||
20 | 'ADD_YEAR' => 'Add year to movie, like "movie (2019).avi":1' |
||
21 | ]; |
||
22 | } |
||
23 | |||
24 | /** |
||
25 | * @return \Symfony\Component\Cache\Adapter\AbstractAdapter |
||
26 | */ |
||
27 | public static function getCache() |
||
28 | { |
||
29 | if (static::$cache) { |
||
30 | return static::$cache; |
||
31 | } |
||
32 | $cache = new static::$cacheClass(static::getShortName(), 3600, Cli::$temporaryDir); |
||
33 | static::$cache = $cache; |
||
34 | |||
35 | return $cache; |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * @param $name |
||
40 | * @return null |
||
41 | */ |
||
42 | View Code Duplication | public function getOptionDefaultValue($name) |
|
0 ignored issues
–
show
|
|||
43 | { |
||
44 | if (isset($this->getOptions()[$name])) { |
||
45 | return explode(':', $this->getOptions()[$name])[1]; |
||
46 | } |
||
47 | return null; |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * @param $name |
||
52 | * @return null |
||
53 | */ |
||
54 | View Code Duplication | public function getOptionDescription($name) |
|
0 ignored issues
–
show
This method seems to be duplicated in 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. ![]() |
|||
55 | { |
||
56 | if (isset($this->getOptions()[$name])) { |
||
57 | return explode(':', $this->getOptions()[$name])[0]; |
||
58 | } |
||
59 | return null; |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @param $name |
||
64 | * @return array|false|null|string |
||
65 | */ |
||
66 | public function getOption($name) |
||
67 | { |
||
68 | $key = 'ENGINE_OPTION_' . $name; |
||
69 | if (($value = getenv($key)) === null) { |
||
70 | return $this->getOptionDefaultValue($name); |
||
71 | } |
||
72 | return $value; |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * @return string |
||
77 | */ |
||
78 | protected static function getShortName() |
||
79 | { |
||
80 | $reflection = new \ReflectionClass(static::class); |
||
81 | return $reflection->getShortName(); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * @return bool|string |
||
86 | */ |
||
87 | protected static function getTemporaryDir() |
||
88 | { |
||
89 | $dir = Cli::$temporaryDir . DIRECTORY_SEPARATOR . static::getShortName(); |
||
90 | FileHelper::createDirectory($dir); |
||
91 | return realpath($dir); |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * @param $request |
||
96 | * @param $data |
||
97 | */ |
||
98 | public static function setCacheValue($request, $data) |
||
99 | { |
||
100 | $item = static::getCache()->getItem(md5($request)); |
||
101 | $item->set($data); |
||
102 | static::getCache()->save($item); |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * @param $request |
||
107 | * @return mixed |
||
108 | */ |
||
109 | public static function getCacheValue($request) |
||
110 | { |
||
111 | return static::getCache()->getItem(md5($request))->get(); |
||
112 | } |
||
113 | |||
114 | public function clearCache() |
||
115 | { |
||
116 | FileHelper::removeDirectory(static::getTemporaryDir()); |
||
0 ignored issues
–
show
It seems like
static::getTemporaryDir() targeting carono\janitor\engines\E...ract::getTemporaryDir() can also be of type boolean ; however, carono\janitor\helpers\F...lper::removeDirectory() does only seem to accept string , maybe add an additional type check?
This check looks at variables that are passed out again to other methods. If the outgoing method call has stricter type requirements than the method itself, an issue is raised. An additional type check may prevent trouble. ![]() |
|||
117 | } |
||
118 | |||
119 | /** |
||
120 | * @param $text |
||
121 | * @return int|null |
||
122 | */ |
||
123 | View Code Duplication | public function parseSerialSeason($text) |
|
0 ignored issues
–
show
This method seems to be duplicated in 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. ![]() |
|||
124 | { |
||
125 | $patterns = [ |
||
126 | 's(\d+)', |
||
127 | 'season.{1}(\d+)', |
||
128 | 'сезон.{1}(\d+)' |
||
129 | ]; |
||
130 | foreach ($patterns as $pattern) { |
||
131 | if (preg_match("/$pattern/iu", $text, $match)) { |
||
132 | return (int)$match[1]; |
||
133 | } |
||
134 | } |
||
135 | return null; |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * @param $text |
||
140 | * @return int|null |
||
141 | */ |
||
142 | View Code Duplication | public function parseSerialEpisodeNumber($text) |
|
0 ignored issues
–
show
This method seems to be duplicated in 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. ![]() |
|||
143 | { |
||
144 | $patterns = [ |
||
145 | 'e(\d+)', |
||
146 | ]; |
||
147 | foreach ($patterns as $pattern) { |
||
148 | if (preg_match("/$pattern/iu", $text, $match)) { |
||
149 | return (int)$match[1]; |
||
150 | } |
||
151 | } |
||
152 | return null; |
||
153 | } |
||
154 | |||
155 | /** |
||
156 | * @param File $file |
||
157 | * @param string $newName |
||
158 | * @param string $lastRequest |
||
159 | * @return string |
||
160 | */ |
||
161 | public function reformFilmName(File $file, $newName, $lastRequest) |
||
162 | { |
||
163 | $name = $newName; |
||
164 | if ($file->isSerial()) { |
||
165 | $name .= ' ' . $file->getSuffix(); |
||
166 | } |
||
167 | if ($this->getOption('ADD_YEAR')) { |
||
0 ignored issues
–
show
The expression
$this->getOption('ADD_YEAR') of type null|string is loosely compared to true ; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like For '' == false // true
'' == null // true
'ab' == false // false
'ab' == null // false
// It is often better to use strict comparison
'' === false // false
'' === null // false
![]() |
|||
168 | $years = []; |
||
169 | $years[] = Cli::extractYear($newName); |
||
170 | $years[] = Cli::extractYear($lastRequest); |
||
171 | $years[] = Cli::extractYear(FileHelper::prepareFileName($file->getFilePath())); |
||
172 | if ($year = current(array_filter($years))) { |
||
173 | $name .= " ($year)"; |
||
174 | } |
||
175 | } |
||
176 | |||
177 | return $name; |
||
178 | } |
||
179 | } |
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.