Failed Conditions
Push — psr2-config ( de33cd...0a5b05 )
by Andreas
04:27
created

SettingRegex::update()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 3
nop 1
dl 0
loc 20
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace dokuwiki\plugin\config\core\Setting;
4
5
/**
6
 * Class setting_regex
7
 */
8
class SettingRegex extends SettingString {
9
10
    protected $delimiter = '/';    // regex delimiter to be used in testing input
11
    protected $pregflags = 'ui';   // regex pattern modifiers to be used in testing input
12
13
    /** @inheritdoc */
14
    public function update($input) {
15
16
        // let parent do basic checks, value, not changed, etc.
17
        $local = $this->local;
18
        if(!parent::update($input)) return false;
19
        $this->local = $local;
20
21
        // see if the regex compiles and runs (we don't check for effectiveness)
22
        $regex = $this->delimiter . $input . $this->delimiter . $this->pregflags;
23
        $lastError = error_get_last();
24
        @preg_match($regex, 'testdata');
1 ignored issue
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
25
        if(preg_last_error() != PREG_NO_ERROR || error_get_last() != $lastError) {
26
            $this->input = $input;
27
            $this->error = true;
28
            return false;
29
        }
30
31
        $this->local = $input;
32
        return true;
33
    }
34
}
35