PapParser::createCrawler()   A
last analyzed

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 App\Util\NumericUtil;
7
use Symfony\Component\DomCrawler\Crawler;
8
9
class PapParser extends AbstractParser
10
{
11
    protected const PROVIDER = Provider::PAP;
12
13
    protected const SELECTOR_AD_WRAPPER    = 'table tr:nth-child(n+3):not(:last-child)';
14
    protected const SELECTOR_LOCATION      = 'td:nth-child(2) b';
15
    protected const SELECTOR_BUILDING_NAME = 'td:nth-child(2)';
16
    protected const SELECTOR_DESCRIPTION   = 'td:nth-child(2)';
17
18
    /**
19
     * {@inheritDoc}
20
     */
21 1
    protected function createCrawler(string $html): Crawler
22
    {
23
        // Inject "border-collapse: collapse" on <table> to make <tr> selectable
24 1
        $crawler = new Crawler($html);
25 1
        $crawler->filter('table')->getNode(0)->setAttribute('style', 'border-collapse: collapse');
26
27 1
        return $crawler;
28
    }
29
30
    /**
31
     * {@inheritDoc}
32
     */
33 1
    protected function parsePrice(Crawler $crawler): ?float
34
    {
35 1
        return NumericUtil::parsePrice(str_replace('.', '', $crawler->html()));
36
    }
37
38
    /**
39
     * {@inheritDoc}
40
     */
41 1
    protected function parseBuildingName(Crawler $crawler): ?string
42
    {
43 1
        if (1 === preg_match('/\)(.+) -/', parent::parseBuildingName($crawler), $matches)) {
0 ignored issues
show
Bug introduced by
parent::parseBuildingName($crawler) of type null is incompatible with the type string expected by parameter $subject of preg_match(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

43
        if (1 === preg_match('/\)(.+) -/', /** @scrutinizer ignore-type */ parent::parseBuildingName($crawler), $matches)) {
Loading history...
Bug introduced by
Are you sure the usage of parent::parseBuildingName($crawler) targeting App\Parser\AbstractParser::parseBuildingName() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
44 1
            return trim($matches[1]);
45
        }
46
47
        return null;
48
    }
49
}
50