Failed Conditions
Push — psr2 ( 8eb28c...c68e26 )
by Andreas
28s queued 20s
created

SettingRegex   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A update() 0 20 4
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