ContainsTextFilter::getFunctionName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Jerodev\Diglett\CssFilters;
4
5
use Symfony\Component\DomCrawler\Crawler;
6
7
class ContainsTextFilter 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 'containstext';
22
    }
23
24
    public function filterNodes(Crawler $crawler): ?Crawler
25
    {
26
        if ($crawler->count() === 0) {
27
            return null;
28
        }
29
30
        if (empty($this->text)) {
31
            return $crawler;
32
        }
33
34
        $text = $this->text;
35
36
        return $crawler->reduce(function ($node) use ($text) {
37
            return strpos($node->text(), $text) !== false;
38
        });
39
    }
40
}
41