Completed
Push — 2.0 ( a5342d...dc219a )
by Kirill
04:04
created

PaginatorQuery   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A type() 0 4 1
A resolve() 0 18 2
A queryArguments() 0 9 1
1
<?php
2
/**
3
 * This file is part of laravel.su package.
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace App\GraphQL\Queries;
10
11
use GraphQL\Type\Definition\Type;
12
use GraphQL\Type\Definition\ObjectType;
13
use App\GraphQL\Kernel\Paginator\PaginatorConfiguration;
14
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
15
16
/**
17
 * Class PaginatorQuery
18
 * @package App\GraphQL\Queries
19
 */
20
class PaginatorQuery extends AbstractQuery
21
{
22
    /**
23
     * @var array
24
     */
25
    protected $attributes = [
26
        'name'        => 'Paginator query',
27
        'description' => 'Returns an info about query',
28
    ];
29
30
    /**
31
     * @return ObjectType
32
     */
33
    public function type(): ObjectType
34
    {
35
        return \GraphQL::type('Paginator');
36
    }
37
38
    /**
39
     * @param $root
40
     * @param array $args
41
     * @return array
42
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
43
     */
44
    public function resolve($root, array $args = []): array
0 ignored issues
show
Unused Code introduced by
The parameter $root is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
45
    {
46
        $paginator = PaginatorConfiguration::find($args['query']);
47
        if ($paginator === null) {
48
            throw new NotFoundHttpException('No info about ' . $args['query'] . ' query');
49
        }
50
51
        return [
52
            'total_count'   => $paginator->getCount(),
53
            'pages_count'   => $paginator->getPages(),
54
            'limit'         => $paginator->getLimit(),
55
            'skip'          => $paginator->getSkip(),
56
            'page'          => $paginator->getPage(),
57
            'per_page'      => $paginator->getPerPage(),
58
            'is_first_page' => $paginator->getSkip() === 0,
59
            'is_last_page'  => $paginator->getPage() >= $paginator->getPages(),
60
        ];
61
    }
62
63
    /**
64
     * @return array
65
     */
66
    protected function queryArguments(): array
67
    {
68
        return [
69
            'query' => [
70
                'name' => 'query',
71
                'type' => Type::nonNull(Type::string()),
72
            ],
73
        ];
74
    }
75
}