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

ExactTextFilter::getFunctionName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
}