Passed
Push — master ( 8ce43b...977552 )
by Adrien
13:23
created

AbstractSorting   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSortedQueryResult() 0 11 2
A getSorting() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApplicationTest\Api\Input\Sorting;
6
7
use PHPUnit\Framework\TestCase;
8
9
class AbstractSorting extends TestCase
10
{
11
    protected function getSortedQueryResult(string $class, string $field): array
12
    {
13
        $sorting = $this->getSorting($field);
14
        $qb = _types()->createFilteredQueryBuilder($class, [], $sorting);
15
16
        $result = [];
17
        foreach ($qb->getQuery()->getResult() as $item) {
18
            $result[] = $item->getId();
19
        }
20
21
        return $result;
22
    }
23
24
    private function getSorting(string $field): array
25
    {
26
        return [
27
            [
28
                'field' => $field,
29
                'order' => 'DESC',
30
            ],
31
            [
32
                'field' => 'id',
33
                'order' => 'ASC',
34
            ],
35
        ];
36
    }
37
}
38