CityService   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 13
c 1
b 0
f 1
dl 0
loc 31
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getSearchParams() 0 6 1
A __construct() 0 4 1
A getProperties() 0 3 1
A decorateOptions() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Service;
6
7
use App\Entity\City;
8
use App\Repository\FilterRepository;
9
use App\Transformer\RequestToArrayTransformer;
10
use Knp\Component\Pager\Pagination\PaginationInterface;
11
use Symfony\Component\HttpFoundation\Request;
12
13
final class CityService
14
{
15
    private RequestToArrayTransformer $transformer;
16
    private FilterRepository $repository;
17
18
    public function __construct(RequestToArrayTransformer $transformer, FilterRepository $repository)
19
    {
20
        $this->transformer = $transformer;
21
        $this->repository = $repository;
22
    }
23
24
    public function getSearchParams(Request $request, City $city): array
25
    {
26
        $searchParams = $this->transformer->transform($request);
27
        $searchParams['city'] = $city->getId();
28
29
        return $searchParams;
30
    }
31
32
    public function getProperties(array $searchParams): PaginationInterface
33
    {
34
        return $this->repository->findByFilter($searchParams);
35
    }
36
37
    public function decorateOptions(array $siteOptions, City $city): array
38
    {
39
        $siteOptions['title'] = $city->getTitle() ?? $siteOptions['title'];
40
        $siteOptions['meta_title'] = $city->getMetaTitle() ?? $city->getName();
41
        $siteOptions['meta_description'] = $city->getMetaDescription() ?? $siteOptions['meta_description'];
42
43
        return $siteOptions;
44
    }
45
}
46