SeLogerNeufUrlBuilder   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
dl 0
loc 107
ccs 0
cts 26
cp 0
rs 10
c 1
b 0
f 0
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A buildRoomsCountParam() 0 14 3
A buildPropertyTypesParam() 0 5 1
A buildPath() 0 11 1
A buildLocationParam() 0 3 1
A buildAreaParam() 0 3 1
A buildPriceParam() 0 3 1
A buildQueryParameters() 0 19 1
1
<?php
2
3
namespace App\UrlBuilder;
4
5
use App\DTO\City;
6
use App\Enum\PropertyType;
7
8
class SeLogerNeufUrlBuilder extends AbstractUrlBuilder
9
{
10
    private const MAX_ROOMS_COUNT = 4;
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.selogerneuf.com/recherche';
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
            $this->buildPropertyTypesParam($propertyTypes),
43
            $this->buildPriceParam($maxPrice),
44
            $this->buildRoomsCountParam($minRoomsCount),
45
            $this->buildAreaParam('min', $minArea),
46
            $this->buildAreaParam('max', $maxArea),
47
            ['idtt' => '9'],
48
            ['tri' => 'selection'],
49
            $this->buildLocationParam($city),
50
        ];
51
    }
52
53
    /**
54
     * @param City $city
55
     *
56
     * @return array
57
     */
58
    private function buildLocationParam(City $city): array
59
    {
60
        return ['localities' => $city->getSeLogerNeufCode()];
61
    }
62
63
    /**
64
     * @param string[] $types
65
     *
66
     * @return array
67
     */
68
    private function buildPropertyTypesParam(array $types): array
69
    {
70
        $types = str_replace([PropertyType::APARTMENT, PropertyType::HOUSE], [1, 2], $types);
71
72
        return ['idtypebien' => implode(',', $types)];
73
    }
74
75
    /**
76
     * @param int $maxPrice
77
     *
78
     * @return array
79
     */
80
    private function buildPriceParam(int $maxPrice): array
81
    {
82
        return ['pxmax' => $maxPrice];
83
    }
84
85
    /**
86
     * @param string   $bound
87
     * @param int|null $area
88
     *
89
     * @return array
90
     */
91
    private function buildAreaParam(string $bound, ?int $area): array
92
    {
93
        return ["surface$bound" => $area];
94
    }
95
96
    /**
97
     * @param int $minRoomsCount
98
     *
99
     * @return array
100
     */
101
    private function buildRoomsCountParam(int $minRoomsCount): array
102
    {
103
        if ($minRoomsCount > self::MAX_ROOMS_COUNT) {
104
            return ['nb_pieces' => '+4'];
105
        }
106
107
        $roomsCount = min($minRoomsCount, self::MAX_ROOMS_COUNT);
108
        $roomsList = implode(',', range(1, $roomsCount));
109
110
        if ($minRoomsCount > self::MAX_ROOMS_COUNT) {
111
            $roomsList .= ',+4';
112
        }
113
114
        return ['nb_pieces' => $roomsList];
115
    }
116
}
117