PaginationType   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 25
c 1
b 0
f 0
dl 0
loc 45
ccs 0
cts 33
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 38 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ecodev\Felix\Api\Output;
6
7
use Ecodev\Felix\Model\Model;
8
use GraphQL\Type\Definition\ObjectType;
9
10
final class PaginationType extends ObjectType
11
{
12
    /**
13
     * PaginationType constructor.
14
     *
15
     * @param class-string $class
16
     */
17
    public function __construct(string $class, string $name, array $extraFields)
18
    {
19
        $config = [
20
            'name' => $name,
21
            'description' => 'Describe available pages',
22
            'fields' => function () use ($class, $extraFields): array {
23
                $itemType = is_a($class, Model::class, true) ? _types()->getOutput($class) : _types()->get($class);
24
25
                $fields = [
26
                    'offset' => [
27
                        'type' => self::int(),
28
                        'description' => 'The zero-based index of the displayed list of items',
29
                    ],
30
                    'pageIndex' => [
31
                        'type' => self::nonNull(self::int()),
32
                        'description' => 'The zero-based page index of the displayed list of items',
33
                    ],
34
                    'pageSize' => [
35
                        'type' => self::nonNull(self::int()),
36
                        'description' => 'Number of items to display on a page',
37
                    ],
38
                    'length' => [
39
                        'type' => self::nonNull(self::int()),
40
                        'description' => 'The length of the total number of items that are being paginated',
41
                    ],
42
                    'items' => [
43
                        'type' => self::nonNull(self::listOf(self::nonNull($itemType))),
44
                        'description' => 'Paginated items',
45
                    ],
46
                ];
47
48
                $fields = array_merge($fields, $extraFields);
49
50
                return $fields;
51
            },
52
        ];
53
54
        parent::__construct($config);
55
    }
56
}
57