Passed
Branch develop (eaaf06)
by Florian
04:36
created

PapParser::createCrawler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Parser;
4
5
use App\Enum\Provider;
6
use Symfony\Component\DomCrawler\Crawler;
7
8
class PapParser extends AbstractParser
0 ignored issues
show
Bug introduced by
The type App\Parser\AbstractParser was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
{
10
    protected const PROVIDER = Provider::PAP;
11
12
    protected const SELECTOR_AD_WRAPPER    = 'table tr:nth-child(n+3):not(:last-child)';
13
    protected const SELECTOR_LOCATION      = 'td:nth-child(2) b';
14
    protected const SELECTOR_BUILDING_NAME = 'td:nth-child(2)';
15
    protected const SELECTOR_DESCRIPTION   = 'td:nth-child(2)';
16
17
    /**
18
     * {@inheritDoc}
19
     */
20 1
    protected function createCrawler(string $html): Crawler
21
    {
22
        // Inject "border-collapse: collapse" on <table> to make <tr> selectable
23 1
        $crawler = new Crawler($html);
24 1
        $crawler->filter('table')->getNode(0)->setAttribute('style', 'border-collapse: collapse');
25
26 1
        return $crawler;
27
    }
28
29
    /**
30
     * {@inheritDoc}
31
     */
32 1
    protected function parsePrice(Crawler $crawler): ?float
33
    {
34 1
        return $this->formatter->parsePrice(str_replace('.', '', $crawler->html()));
35
    }
36
37
    /**
38
     * {@inheritDoc}
39
     */
40 1
    protected function parseBuildingName(Crawler $crawler): ?string
41
    {
42 1
        if (1 === preg_match('/\)(.+) -/', parent::parseBuildingName($crawler), $matches)) {
43 1
            return trim($matches[1]);
44
        }
45
46
        return null;
47
    }
48
}
49