Purchases   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
eloc 22
dl 0
loc 40
ccs 34
cts 34
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 38 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Api\Field\Query;
6
7
use Application\Api\Helper;
8
use Application\Model\OrderLine;
9
use Application\Model\Product;
10
use Application\Repository\OrderLineRepository;
11
use Ecodev\Felix\Api\Field\FieldInterface;
12
use Ecodev\Felix\Api\Input\PaginationInputType;
13
use GraphQL\Type\Definition\Type;
14
15
abstract class Purchases implements FieldInterface
16
{
17 1
    public static function build(): iterable
18
    {
19 1
        yield 'purchases' => fn () => [
20 1
            'type' => Type::nonNull(_types()->get('OrderLinePagination')),
21 1
            'description' => 'Get purchases of a given user',
22 1
            'args' => [
23 1
                [
24 1
                    'name' => 'filter',
25 1
                    'type' => _types()->getFilter(Product::class),
26 1
                ],
27 1
                [
28 1
                    'name' => 'sorting',
29 1
                    'type' => _types()->getSorting(Product::class),
30 1
                    'defaultValue' => [
31 1
                        [
32 1
                            'field' => 'releaseDate',
33 1
                            'order' => 'ASC',
34 1
                        ],
35 1
                        [
36 1
                            'field' => 'code',
37 1
                            'order' => 'DESC',
38 1
                        ],
39 1
                        [
40 1
                            'field' => 'id',
41 1
                            'order' => 'ASC',
42 1
                        ],
43 1
                    ],
44 1
                ],
45 1
                PaginationInputType::build(_types()),
46 1
            ],
47 1
            'resolve' => function ($root, array $args): array {
48
                /** @var OrderLineRepository $orderLineRepository */
49 1
                $orderLineRepository = _em()->getRepository(OrderLine::class);
50 1
                $qb = $orderLineRepository->createPurchaseQueryBuilder($args['filter'] ?? [], $args['sorting'] ?? []);
51
52 1
                $items = Helper::paginate($args['pagination'], $qb);
53
54 1
                return $items;
55 1
            },
56 1
        ];
57
    }
58
}
59