CityService::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 2
dl 0
loc 4
rs 10
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