PaginationResolver   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A resolveSize() 0 3 2
A resolveFrom() 0 11 2
1
<?php
2
3
namespace Digia\Lumen\GraphQL\Fields;
4
5
use Digia\Lumen\GraphQL\Models\Page;
6
7
class PaginationResolver
8
{
9
10
    /**
11
     * @param array $args
12
     *
13
     * @return int
14
     */
15
    public static function resolveFrom(array $args)
16
    {
17
        if (isset($args['after'])) {
18
            $index = (int)NodeIdResolver::idFromGlobalId($args['after']);
19
20
            // Logic: 19 (index) + 1 (next) = 20 (from)
21
            return $index + 1;
22
        }
23
24
        // Otherwise from is 0
25
        return 0;
26
    }
27
28
    /**
29
     * @param array $args
30
     *
31
     * @return int
32
     */
33
    public static function resolveSize(array $args): int
34
    {
35
        return isset($args['first']) ? (int)$args['first'] : Page::DEFAULT_SIZE;
36
    }
37
}
38