AbstractUrlBuilder::build()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 20
ccs 0
cts 7
cp 0
rs 10
cc 2
nc 2
nop 7
crap 6
1
<?php
2
3
namespace App\UrlBuilder;
4
5
use App\DataProvider\LocationProvider;
6
use App\DTO\City;
7
8
abstract class AbstractUrlBuilder implements UrlBuilderInterface
9
{
10
    public function __construct(
11
        protected LocationProvider $locationProvider
12
    ) {}
13
14
    /**
15
     * @param string[] $propertyTypes
16
     */
17
    public function build(
18
        string $cityName,
19
        array $propertyTypes,
20
        ?int $minPrice,
21
        int $maxPrice,
22
        ?int $minArea,
23
        ?int $maxArea,
24
        int $minRoomsCount
25
    ): string {
26
        $city = $this->locationProvider->find($cityName);
27
28
        $criteria = [$city, $propertyTypes, $minPrice, $maxPrice, $minArea, $maxArea, $minRoomsCount];
29
30
        $url = $this->buildPath(...$criteria);
31
32
        if (!empty($params = $this->buildQueryParameters(...$criteria))) {
33
            $url .= '?' . urldecode(http_build_query(array_merge(...$params)));
34
        }
35
36
        return $url;
37
    }
38
39
    /**
40
     * @param string[] $types
41
     */
42
    abstract protected function buildPath(
43
        City $city,
44
        array $types,
45
        ?int $minPrice,
46
        int $maxPrice,
47
        ?int $minArea,
48
        ?int $maxArea,
49
        int $minRoomsCount
50
    ): string;
51
52
    /**
53
     * @param string[] $types
54
     */
55
    abstract protected function buildQueryParameters(
56
        City $city,
57
        array $types,
58
        ?int $minPrice,
59
        int $maxPrice,
60
        ?int $minArea,
61
        ?int $maxArea,
62
        int $minRoomsCount
63
    ): array;
64
}
65