ExactTextFilter::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 5
rs 10
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
            $this->text = $parameters[0];
16
        }
17
    }
18
19
    public static function getFunctionName(): string
20
    {
21
        return 'text';
22
    }
23
24
    public function filterNodes(Crawler $crawler): ?Crawler
25
    {
26
        if ($crawler->count() === 0) {
27
            return null;
28
        }
29
30
        $text = $this->text;
31
32
        return $crawler->reduce(function ($node) use ($text) {
33
            return $node->text() === $text;
34
        });
35
    }
36
}
37