Issues (50)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/engines/EngineAbstract.php (6 issues)

Upgrade to new PHP Analysis Engine

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
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.

Loading history...
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.

Loading history...
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.

Loading history...
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.

Loading history...
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.

Loading history...
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
Bug Best Practice introduced by
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 ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
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
}