AbstractSorting   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 13
c 1
b 0
f 0
dl 0
loc 30
ccs 0
cts 17
cp 0
rs 10

2 Methods

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