LogicImmoUrlBuilder   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 98
ccs 0
cts 23
cp 0
rs 10
c 1
b 0
f 0
wmc 11

7 Methods

Rating   Name   Duplication   Size   Complexity  
A buildLocationParam() 0 3 1
A buildPriceParam() 0 3 1
A buildRoomsCountParam() 0 5 1
A buildPropertyTypeParam() 0 5 1
A buildAreaParam() 0 3 1
A buildQueryParameters() 0 11 1
A buildPath() 0 18 5
1
<?php
2
3
namespace App\UrlBuilder;
4
5
use App\DTO\City;
6
use App\Enum\PropertyType;
7
8
class LogicImmoUrlBuilder extends AbstractUrlBuilder
9
{
10
    private const MAX_ROOMS_COUNT = 6;
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 sprintf('https://www.logic-immo.com/%s/options/%s/%s%s/%s%s%s',
26
            $this->buildLocationParam($city),
27
            $this->buildPropertyTypeParam($propertyTypes),
28
            ((null !== $minPrice) ? $this->buildPriceParam('min', $minPrice) . '/' : ''),
29
            $this->buildPriceParam('max', $maxPrice),
30
            ((null !== $minArea) ? $this->buildAreaParam('min', $minArea) . '/' : ''),
31
            ((null !== $maxArea) ? $this->buildAreaParam('max', $maxArea) . '/' : ''),
32
            ($minRoomsCount > 1 ? $this->buildRoomsCountParam($minRoomsCount) : '')
33
        );
34
    }
35
36
    /**
37
     * {@inheritDoc}
38
     */
39
    protected function buildQueryParameters(
40
        City $city,
41
        array $propertyTypes,
42
        ?int $minPrice,
43
        int $maxPrice,
44
        ?int $minArea,
45
        ?int $maxArea,
46
        int $minRoomsCount
47
    ): array
48
    {
49
        return [];
50
    }
51
52
    /**
53
     * @param City $city
54
     *
55
     * @return string
56
     */
57
    private function buildLocationParam(City $city): string
58
    {
59
        return sprintf('vente-immobilier-%s-tous-codes-postaux,%d_99', $city->getName(), $city->getLogicImmoCode());
60
    }
61
62
    /**
63
     * @param string[] $types
64
     *
65
     * @return string
66
     */
67
    private function buildPropertyTypeParam(array $types): string
68
    {
69
        $types = str_replace([PropertyType::APARTMENT, PropertyType::HOUSE], [1, 2], $types);
70
71
        return 'groupprptypesids=' . implode(',', $types);
72
    }
73
74
    /**
75
     * @param string $bound
76
     * @param int    $price
77
     *
78
     * @return string
79
     */
80
    private function buildPriceParam(string $bound, int $price): string
81
    {
82
        return "price$bound=$price";
83
    }
84
85
    /**
86
     * @param string $bound
87
     * @param int    $area
88
     *
89
     * @return string
90
     */
91
    private function buildAreaParam(string $bound, int $area): string
92
    {
93
        return "area$bound=$area";
94
    }
95
96
    /**
97
     * @param int $minRoomsCount
98
     *
99
     * @return string
100
     */
101
    private function buildRoomsCountParam(int $minRoomsCount): string
102
    {
103
        $values = range($minRoomsCount, self::MAX_ROOMS_COUNT);
104
105
        return 'nbrooms=' . implode(',', $values);
106
    }
107
}
108