Passed
Push — 2.0 ( 3cd779...fe8057 )
by Kirill
03:09
created

DocsType   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
dl 0
loc 81
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fields() 0 47 1
A resolvePagesField() 0 12 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\Types;
10
11
use App\Models\DocsPage;
12
use GraphQL\Type\Definition\ResolveInfo;
13
use GraphQL\Type\Definition\Type;
14
use App\GraphQL\Serializers\DocsPageSerializer;
15
use App\GraphQL\Queries\Support\WhereInSelection;
16
17
/**
18
 * Class DocsType.
19
 */
20
class DocsType extends AbstractType
21
{
22
    use WhereInSelection;
23
24
    /**
25
     * @var array
26
     */
27
    protected $attributes = [
28
        'name'        => 'Docs',
29
        'description' => 'Documentation repository',
30
    ];
31
32
    /**
33
     * @return array
34
     */
35
    public function fields(): array
36
    {
37
        return [
38
            'id'          => [
39
                'type'        => Type::nonNull(Type::id()),
40
                'description' => 'Docs identifier',
41
            ],
42
            'project'     => [
43
                'type'        => Type::nonNull(Type::string()),
44
                'description' => 'Docs project name',
45
            ],
46
            'pages'       => [
47
                'args'        => $this->argumentsWithWhereIn([
48
                    'slug' => [
49
                        'type'        => Type::string(),
50
                        'description' => 'Docs page slug',
51
                    ],
52
                ]),
53
                'type'        => Type::listOf(\GraphQL::type(DocsPageType::getName())),
54
                'description' => '',
55
            ],
56
            'title'       => [
57
                'type'        => Type::nonNull(Type::string()),
58
                'description' => '',
59
            ],
60
            'image'       => [
61
                'type'        => Type::nonNull(Type::string()),
62
                'description' => '',
63
            ],
64
            'version'     => [
65
                'type'        => Type::nonNull(Type::string()),
66
                'description' => '',
67
            ],
68
            'description' => [
69
                'type'        => Type::nonNull(Type::string()),
70
                'description' => '',
71
            ],
72
            'created_at'  => [
73
                'type'        => Type::nonNull(Type::string()),
74
                'description' => '',
75
            ],
76
            'updated_at'  => [
77
                'type'        => Type::nonNull(Type::string()),
78
                'description' => '',
79
            ],
80
        ];
81
    }
82
83
    /**
84
     * @param $root
85
     * @param array $args
86
     * @return \Illuminate\Support\Collection
87
     */
88
    public function resolvePagesField(array $root, array $args)
89
    {
90
        $query = DocsPage::whereDocsId($root['id']);
91
92
        $query = $this->queryWithWhereIn($query, $args);
93
94
        $this->whenExists($args, 'slug', function (string $slug) use ($query) {
95
            return $query->where('slug', $slug);
96
        });
97
98
        return DocsPageSerializer::collection($query->get());
0 ignored issues
show
Bug introduced by
It seems like $query->get() targeting Illuminate\Database\Eloquent\Builder::get() can also be of type array<integer,object<Ill...base\Eloquent\Builder>>; however, App\GraphQL\Serializers\...erializer::collection() does only seem to accept object<Illuminate\Suppor...e\Eloquent\Model>>|null, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
99
    }
100
}
101