SeLogerUrlBuilder   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 24
dl 0
loc 107
ccs 0
cts 25
cp 0
rs 10
c 2
b 0
f 0
wmc 12

7 Methods

Rating   Name   Duplication   Size   Complexity  
A buildLocationParam() 0 3 1
A buildRoomsCountParam() 0 3 1
A buildPriceParam() 0 5 2
A buildPath() 0 11 1
A buildAreaParam() 0 10 5
A buildPropertyTypesParam() 0 5 1
A buildQueryParameters() 0 20 1
1
<?php
2
3
namespace App\UrlBuilder;
4
5
use App\DTO\City;
6
use App\Enum\PropertyType;
7
8
class SeLogerUrlBuilder extends AbstractUrlBuilder
9
{
10
    private const MAX_ROOMS_COUNT = 5;
11
12
    /**
13
     * {@inheritDoc}
14
     */
15
    protected function buildPath(
16
        City $city,
17
        array $propertyTypes,
18
        ?int $minPrice,
19
        int $maxPrice,
20
        ?int $minArea,
21
        ?int $maxArea,
22
        int $minRoomsCount
23
    ): string
24
    {
25
        return 'https://www.seloger.com/list.html';
26
    }
27
28
    /**
29
     * {@inheritDoc}
30
     */
31
    protected function buildQueryParameters(
32
        City $city,
33
        array $propertyTypes,
34
        ?int $minPrice,
35
        int $maxPrice,
36
        ?int $minArea,
37
        ?int $maxArea,
38
        int $minRoomsCount
39
    ): array
40
    {
41
        return [
42
            ['projects' => '2,5'],
43
            $this->buildPropertyTypesParam($propertyTypes),
44
            ['natures' => '1,2,4'],
45
            $this->buildLocationParam($city),
46
            $this->buildPriceParam($minPrice, $maxPrice),
47
            $this->buildAreaParam($minArea, $maxArea),
48
            $this->buildRoomsCountParam($minRoomsCount),
49
            ['enterprise' => 0],
50
            ['qsVersion' => '1.0']
51
        ];
52
    }
53
54
    /**
55
     * @param City $city
56
     *
57
     * @return array
58
     */
59
    private function buildLocationParam(City $city): array
60
    {
61
        return ['places' => sprintf('[{ci:%s}]', substr_replace($city->getInseeCode(), '0', 2, 0))];
0 ignored issues
show
Bug introduced by
It seems like substr_replace($city->getInseeCode(), '0', 2, 0) can also be of type array; however, parameter $values of sprintf() does only seem to accept double|integer|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

61
        return ['places' => sprintf('[{ci:%s}]', /** @scrutinizer ignore-type */ substr_replace($city->getInseeCode(), '0', 2, 0))];
Loading history...
62
    }
63
64
    /**
65
     * @param string[] $types
66
     *
67
     * @return array
68
     */
69
    private function buildPropertyTypesParam(array $types): array
70
    {
71
        $types = str_replace([PropertyType::APARTMENT, PropertyType::HOUSE], [1, 2], $types);
72
73
        return ['types' => implode(',', $types)];
74
    }
75
76
    /**
77
     * @param int|null $minPrice
78
     * @param int      $maxPrice
79
     *
80
     * @return array
81
     */
82
    private function buildPriceParam(?int $minPrice, int $maxPrice): array
83
    {
84
        $minPrice = $minPrice ?: 'NaN';
85
86
        return ['price' => "$minPrice/$maxPrice"];
87
    }
88
89
    /**
90
     * @param int|null $minArea
91
     * @param int|null $maxArea
92
     *
93
     * @return array
94
     */
95
    private function buildAreaParam(?int $minArea, ?int $maxArea): array
96
    {
97
        if (null === $minArea && null === $maxArea) {
98
            return [];
99
        }
100
101
        $minArea = $minArea ?: 'NaN';
102
        $maxArea = $maxArea ?: 'NaN';
103
104
        return ['surface' => "$minArea/$maxArea"];
105
    }
106
107
    /**
108
     * @param int $minRoomsCount
109
     *
110
     * @return array
111
     */
112
    private function buildRoomsCountParam(int $minRoomsCount): array
113
    {
114
        return ['rooms' => min($minRoomsCount, self::MAX_ROOMS_COUNT)];
115
    }
116
}
117