Passed
Push — master ( f58ad4...2006a7 )
by Florian
16:38 queued 11s
created

ProviderController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 29
ccs 0
cts 15
cp 0
rs 10
c 1
b 0
f 0
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B getResultUrls() 0 26 7
1
<?php
2
3
namespace App\Controller;
4
5
use App\Enum\PropertyType;
6
use App\Enum\Provider;
7
use App\Exception\UrlBuilderNotFoundException;
8
use App\Factory\ProviderUrlFactory;
9
use App\Formatter\DecimalFormatter;
10
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
11
use Symfony\Component\HttpFoundation\JsonResponse;
12
use Symfony\Component\HttpFoundation\Request;
13
use Symfony\Component\Routing\Annotation\Route;
14
15
#[Route("/provider")]
16
class ProviderController extends AbstractController
17
{
18
    #[Route("/result-urls", name: "provider_result_urls", options: ["expose" => true], methods: ["GET"])]
19
    public function getResultUrls(
20
        Request $request,
21
        ProviderUrlFactory $urlFactory,
22
        DecimalFormatter $formatter
23
    ): JsonResponse {
24
        $params = $request->query->all();
25
        $city = $params['city'];
26
        $types = isset($params['types']) ? array_keys($params['types']) : PropertyType::getAvailableValues();
27
        $minPrice = isset($params['min_price']) ? $formatter->parse($params['min_price']) : null;
28
        $maxPrice = $formatter->parse($params['max_price']);
29
        $minArea = isset($params['min_area']) ? $formatter->parse($params['min_area']) : null;
30
        $maxArea = isset($params['max_area']) ? $formatter->parse($params['max_area']) : null;
31
        $minRoomsCount = $params['min_rooms_count'];
32
        $urls = [];
33
34
        foreach (Provider::getAvailableValues() as $providerName) {
35
            try {
36
                $urls[] = $urlFactory->create($providerName, $city, $types, $minPrice, $maxPrice, $minArea, $maxArea, $minRoomsCount);
0 ignored issues
show
Bug introduced by
It seems like $minArea can also be of type double; however, parameter $minArea of App\Factory\ProviderUrlFactory::create() does only seem to accept integer|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

36
                $urls[] = $urlFactory->create($providerName, $city, $types, $minPrice, $maxPrice, /** @scrutinizer ignore-type */ $minArea, $maxArea, $minRoomsCount);
Loading history...
Bug introduced by
$maxPrice of type double is incompatible with the type integer expected by parameter $maxPrice of App\Factory\ProviderUrlFactory::create(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

36
                $urls[] = $urlFactory->create($providerName, $city, $types, $minPrice, /** @scrutinizer ignore-type */ $maxPrice, $minArea, $maxArea, $minRoomsCount);
Loading history...
Bug introduced by
It seems like $maxArea can also be of type double; however, parameter $maxArea of App\Factory\ProviderUrlFactory::create() does only seem to accept integer|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

36
                $urls[] = $urlFactory->create($providerName, $city, $types, $minPrice, $maxPrice, $minArea, /** @scrutinizer ignore-type */ $maxArea, $minRoomsCount);
Loading history...
Bug introduced by
It seems like $minPrice can also be of type double; however, parameter $minPrice of App\Factory\ProviderUrlFactory::create() does only seem to accept integer|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

36
                $urls[] = $urlFactory->create($providerName, $city, $types, /** @scrutinizer ignore-type */ $minPrice, $maxPrice, $minArea, $maxArea, $minRoomsCount);
Loading history...
37
            // TODO: process ParuVendu
38
            } catch (UrlBuilderNotFoundException) {
39
                continue;
40
            }
41
        }
42
43
        return $this->json($urls);
44
    }
45
}
46