Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
85.71% covered (warning)
85.71%
6 / 7
75.00% covered (warning)
75.00%
3 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
OrderBySearchFilter
85.71% covered (warning)
85.71%
6 / 7
75.00% covered (warning)
75.00%
3 / 4
5.07
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getFilterName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getWhereCondition
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getOrderByCode
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
2.15
1<?php
2
3namespace Apie\DoctrineEntityDatalayer\Query;
4
5use Apie\Core\Datalayers\Search\QuerySearch;
6use Apie\DoctrineEntityDatalayer\Enums\SortingOrder;
7use Doctrine\DBAL\Connection;
8
9class OrderBySearchFilter implements OrderByFilterInterface
10{
11    private ?string $search = null;
12    public function __construct(
13        private readonly string $filterName,
14        private readonly string $propertyName
15    ) {
16    }
17
18    public function getFilterName(): string
19    {
20        return $this->filterName;
21    }
22
23    public function getWhereCondition(QuerySearch $querySearch, Connection $connection): string
24    {
25        $this->search = $querySearch->getOrderBy()[$this->filterName] ?? null;
26        return '1';
27    }
28
29    public function getOrderByCode(SortingOrder $sortingOrder): string
30    {
31        if ($this->search === null) {
32            return '';
33        }
34        return 'entity.' . $this->propertyName . ' ' . $sortingOrder->value;
35    }
36}