Filter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
c 2
b 0
f 1
lcom 1
cbo 2
dl 0
loc 39
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A matches() 0 8 3
A checkAgainstRule() 0 4 1
1
<?php
2
3
namespace Ionut\Sylar\Filters\PHPIDS;
4
5
use Ionut\Sylar\Filters\FilterInterface;
6
use Ionut\Sylar\Filters\FilterReportInterface;
7
use Ionut\Sylar\NormalizedValueVariant;
8
9
class Filter implements FilterInterface
10
{
11
12
    /**
13
     * @var array
14
     */
15
    protected $filters;
16
17
    public function __construct()
18
    {
19
        $contents = json_decode(file_get_contents(__DIR__.'/_filters.json'));
20
        $this->filters = $contents->filters->filter;
21
    }
22
23
    /**
24
     * Check a given value against this set of filters.
25
     *
26
     * @param NormalizedValueVariant|string $value
27
     * @return FilterReportInterface|null
28
     */
29
    public function matches(NormalizedValueVariant $value)
30
    {
31
        foreach ($this->filters as $filter) {
32
            if ($this->checkAgainstRule($filter->rule, $value->getValue())) {
33
                return new Report($filter, $value);
34
            }
35
        }
36
    }
37
38
    /**
39
     * @param  string $rule
40
     * @param  string $value
41
     * @return boolean
42
     */
43
    protected function checkAgainstRule($rule, $value)
44
    {
45
        return preg_match('/'.$rule.'/', $value);
46
    }
47
}