Issues (40)

src/Parser/LeBonCoinParser.php (1 issue)

Labels
Severity
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
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