DefaultRule   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 33
c 1
b 0
f 0
dl 0
loc 46
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A check() 0 11 2
1
<?php
2
3
namespace Tleckie\InjectorDetect\Rules;
4
5
use InvalidArgumentException;
6
use Tleckie\InjectorDetect\RulesInterface;
7
8
/**
9
 * Class DefaultRule
10
 *
11
 * @package Tleckie\InjectorDetect\Rules
12
 * @author  Teodoro Leckie Westberg <[email protected]>
13
 */
14
class DefaultRule implements RulesInterface
15
{
16
    /** @var array */
17
    private array $rules = [
18
        'phpinfo\(',
19
        'system\(',
20
        'exec\(',
21
        'shell_exec\(',
22
        'passthru\(',
23
        'proc_open\(',
24
        'proc_nice\(',
25
        'proc_terminate\(',
26
        'proc_get_status\(',
27
        'proc_close\(',
28
        'pfsockopen\(',
29
        'apache_child_terminate\(',
30
        'posix_kill\(',
31
        'popen\(',
32
        'curl_exec\(',
33
        'curl_multi_exec\(',
34
        'parse_ini_file\(',
35
        'show_source\(',
36
        'eval\(',
37
        'gzinflate\(',
38
        'str_rot13\(',
39
        'base64_decode\(',
40
        'str_replace\(',
41
        'error_reporting\(',
42
        'set_time_limit\(',
43
        'gzuncompress\(',
44
    ];
45
46
    /**
47
     * @inheritdoc
48
     */
49
    public function check(mixed $valueToCheck): RulesInterface
50
    {
51
        $rules = implode('|', $this->rules);
52
53
        if (preg_match("#$rules#i", $valueToCheck, $matches)) {
54
            throw new InvalidArgumentException(
55
                sprintf('Insecure parameter detected with value [%s]', $valueToCheck)
56
            );
57
        }
58
59
        return $this;
60
    }
61
}
62