Completed
Pull Request — master (#16)
by Matthijs
02:15
created

UriFilter::match()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4286
cc 3
eloc 6
nc 3
nop 1
1
<?php
2
namespace VDB\Spider\Filter\Prefetch;
3
4
use VDB\Spider\Filter\PreFetchFilter;
5
use VDB\Spider\Uri\FilterableUri;
6
7
/**
8
 * @author matthijs
9
 */
10
class UriFilter implements PreFetchFilter
11
{
12
    /**
13
     * @var array An array of regexes
14
     */
15
    public $regexes = array();
16
17
    public function __construct(array $regexes = array())
18
    {
19
        $this->regexes = $regexes;
20
    }
21
22
    public function match(FilterableUri $uri)
23
    {
24
        foreach ($this->regexes as $regex) {
25
            if (preg_match($regex, $uri->toString())) {
26
                $uri->setFiltered(true, "Matched URI regex '$regex'");
27
                return true;
28
            }
29
        }
30
        return false;
31
    }
32
}
33