Test Setup Failed
Pull Request — master (#29)
by
unknown
04:19 queued 32s
created

NeighborhoodService   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 3
dl 0
loc 38
rs 10
c 0
b 0
f 0

4 Methods

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