SuperimmoNeufUrlBuilder::buildRoomsCountParam()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace App\UrlBuilder;
4
5
use App\DTO\City;
6
use App\Enum\PropertyType;
7
8
class SuperimmoNeufUrlBuilder 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 sprintf('https://www.superimmoneuf.com/%s-%s',
26
            $this->buildPropertyTypesParam($propertyTypes),
27
            $this->buildLocationParam($city),
28
        );
29
    }
30
31
    /**
32
     * {@inheritDoc}
33
     */
34
    protected function buildQueryParameters(
35
        City $city,
36
        array $propertyTypes,
37
        ?int $minPrice,
38
        int $maxPrice,
39
        ?int $minArea,
40
        ?int $maxArea,
41
        int $minRoomsCount
42
    ): array
43
    {
44
        return [
45
            $this->buildPriceParam($maxPrice),
46
            $this->buildRoomsCountParam($minRoomsCount)
47
        ];
48
    }
49
50
    /**
51
     * @param City $city
52
     *
53
     * @return string
54
     */
55
    private function buildLocationParam(City $city): string
56
    {
57
        return sprintf('%s-%s', $city->getName(), $city->getDepartmentCode());
58
    }
59
60
    /**
61
     * @param string[] $types
62
     *
63
     * @return string
64
     */
65
    private function buildPropertyTypesParam(array $types): string
66
    {
67
        if (2 === count($types)) {
68
            return 'immobilier-neuf';
69
        }
70
71
        return str_replace([PropertyType::APARTMENT, PropertyType::HOUSE], ['appartement-neuf', 'maison-neuve'], $types[0]);
72
    }
73
74
    /**
75
     * @param int $maxPrice
76
     *
77
     * @return array
78
     */
79
    private function buildPriceParam(int $maxPrice): array
80
    {
81
        return ['_search[price_max]' => $maxPrice];
82
    }
83
84
    /**
85
     * @param int $minRoomsCount
86
     *
87
     * @return array
88
     */
89
    private function buildRoomsCountParam(int $minRoomsCount): array
90
    {
91
        return ['_search[rooms][]' => min($minRoomsCount, self::MAX_ROOMS_COUNT)];
92
    }
93
}
94