ProviderUrlFactory::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 17
ccs 0
cts 5
cp 0
rs 10
cc 1
nc 1
nop 8
crap 2

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace App\Factory;
4
5
use App\DataProvider\ProviderProvider;
6
use App\DTO\Provider;
7
use App\DTO\Url;
8
use App\Exception\UrlBuilderNotFoundException;
9
use App\UrlBuilder\UrlBuilderLocator;
10
11
class ProviderUrlFactory
12
{
13
    public function __construct(
14
        private ProviderProvider $providerProvider,
15
        private UrlBuilderLocator $urlBuilderLocator
16
    ) {}
17
18
    /**
19
     * @throws UrlBuilderNotFoundException
20
     */
21
    public function create(
22
        string $providerName,
23
        string $city,
24
        array $propertyTypes,
25
        ?int $minPrice,
26
        int $maxPrice,
27
        ?int $minArea,
28
        ?int $maxArea,
29
        int $minRoomsCount
30
    ): Url {
31
        /** @var Provider $provider */
32
        $provider = $this->providerProvider->find($providerName);
33
34
        $urlBuilder = $this->urlBuilderLocator->get($provider->getName());
35
        $url = $urlBuilder->build($city, $propertyTypes, $minPrice, $maxPrice, $minArea, $maxArea, $minRoomsCount);
36
37
        return new Url($provider->getName(), $provider->getLogo(), $url);
38
    }
39
}
40