LeBonCoinParser   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 57.14%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 13
c 1
b 0
f 0
dl 0
loc 24
ccs 4
cts 7
cp 0.5714
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A parsePhoto() 0 12 3
1
<?php
2
3
namespace App\Parser;
4
5
use App\Enum\Provider;
6
use App\Exception\ParseException;
7
use Exception;
8
use Symfony\Component\DomCrawler\Crawler;
9
10
class LeBonCoinParser extends AbstractParser
11
{
12
    protected const PROVIDER = Provider::LEBONCOIN;
13
14
    protected const SELECTOR_AD_WRAPPER  = 'table[style*="border: solid 1px #e6ebef"]';
15
    protected const SELECTOR_TITLE       = 'td:nth-child(2) > a > span:first-of-type';
16
    protected const SELECTOR_LOCATION    = 'td:nth-child(2) > a > div > span';
17
    protected const SELECTOR_PHOTO       = 'td:nth-child(1) div';
18
19
    /**
20
     * {@inheritDoc}
21
     */
22 1
    protected function parsePhoto(Crawler $crawler): ?string
23
    {
24
        try {
25 1
            $backgroundImage = $crawler->filter(static::SELECTOR_PHOTO)->attr('style');
26
27 1
            if (1 === preg_match('/background-image: url\((.*)\)/', $backgroundImage, $matches)) {
0 ignored issues
show
Bug introduced by
It seems like $backgroundImage can also be of type null; however, parameter $subject of preg_match() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

27
            if (1 === preg_match('/background-image: url\((.*)\)/', /** @scrutinizer ignore-type */ $backgroundImage, $matches)) {
Loading history...
28 1
                return $matches[1];
29
            }
30
31
            throw new ParseException('Error while parsing the photo: no property "background-image" found');
32
        } catch (Exception $e) {
33
            throw new ParseException('Error while parsing the photo: ' . $e->getMessage());
34
        }
35
    }
36
}
37