PapNeufParser   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 11
c 1
b 0
f 0
dl 0
loc 38
ccs 8
cts 10
cp 0.8
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parsePrice() 0 3 1
A parseLocation() 0 7 2
A parseBuildingName() 0 7 2
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
use function preg_match;
9
10
class PapNeufParser extends AbstractParser
11
{
12
    protected const PROVIDER = Provider::PAP_NEUF;
13
14
    protected const SELECTOR_AD_WRAPPER    = '#email-body tr:nth-child(n+2):not(:nth-last-child(-n+2))';
15
    protected const SELECTOR_LOCATION      = '.box-text-content';
16
    protected const SELECTOR_BUILDING_NAME = '.box-text-content';
17
18
    /**
19
     * {@inheritDoc}
20
     */
21 1
    protected function parsePrice(Crawler $crawler): ?float
22
    {
23 1
        return NumericUtil::parsePrice(str_replace('.', '', $crawler->html()));
24
    }
25
26
    /**
27
     * {@inheritDoc}
28
     */
29 1
    protected function parseLocation(Crawler $crawler): ?string
30
    {
31 1
        if (1 === preg_match('/Adresse : (.+) (?:A partir de|Voir le programme)/U', parent::parseLocation($crawler), $matches)) {
0 ignored issues
show
Bug introduced by
parent::parseLocation($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

31
        if (1 === preg_match('/Adresse : (.+) (?:A partir de|Voir le programme)/U', /** @scrutinizer ignore-type */ parent::parseLocation($crawler), $matches)) {
Loading history...
Bug introduced by
Are you sure the usage of parent::parseLocation($crawler) targeting App\Parser\AbstractParser::parseLocation() 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...
32 1
            return $matches[1];
33
        }
34
35
        return null;
36
    }
37
38
    /**
39
     * {@inheritDoc}
40
     */
41 1
    protected function parseBuildingName(Crawler $crawler): ?string
42
    {
43 1
        if (1 === preg_match('/\) (.+) Adresse/', parent::parseBuildingName($crawler), $matches)) {
0 ignored issues
show
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...
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('/\) (.+) Adresse/', /** @scrutinizer ignore-type */ parent::parseBuildingName($crawler), $matches)) {
Loading history...
44 1
            return $matches[1];
45
        }
46
47
        return null;
48
    }
49
}
50