Passed
Push — master ( 8469c3...6954c8 )
by Jeroen
02:44
created

ExactTextFilter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A filterNodes() 0 11 2
A getFunctionName() 0 3 1
1
<?php
2
3
namespace Jerodev\Diglett\CssFilters;
4
5
use Symfony\Component\DomCrawler\Crawler;
6
7
class ExactTextFilter implements ICssFilter
8
{
9
    private $text;
10
11
    public function __construct(array $parameters)
12
    {
13
        $this->text = null;
14
        if (count($parameters) > 0)
15
        {
16
            $this->text = $parameters[0];
17
        }
18
    }
19
20
    public static function getFunctionName(): string
21
    {
22
        return 'text';
23
    }
24
25
    public function filterNodes(Crawler $crawler): ?Crawler {
26
27
        if ($crawler->count() === 0)
28
        {
29
            return null;
30
        }
31
        else
32
        {
33
            $text = $this->text;
34
            return $crawler->reduce(function ($node) use ($text) {
35
                return $node->text() === $text;
36
            });
37
        }
38
39
    }
40
}