Test Failed
Push — feature-laravel-5.4 ( d62334...6d0d6f )
by Kirill
04:24
created

TipsQuery::type()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 4
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of laravel.su package.
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace App\GraphQL\Queries;
11
12
use App\Models\Tip;
13
use App\GraphQL\Types\TipType;
14
use GraphQL\Type\Definition\Type;
15
use Illuminate\Database\Query\Builder;
16
use Illuminate\Support\Collection;
17
use Folklore\GraphQL\Support\Query;
18
use GraphQL\Type\Definition\ListOfType;
19
use App\GraphQL\Serializers\TipSerializer;
20
use App\GraphQL\Queries\Support\QueryLimit;
21
22
/**
23
 * Class TipsQuery.
24
 */
25 View Code Duplication
class TipsQuery extends Query
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
{
27
    use QueryLimit;
28
29
    /**
30
     * @var array
31
     */
32
    protected $attributes = [
33
        'name'        => 'Tips list query',
34
        'description' => 'Returns a list of available tips',
35
    ];
36
37
    /**
38
     * @return ListOfType
39
     */
40
    public function type(): ListOfType
41
    {
42
        return Type::listOf(\GraphQL::type(TipType::getName()));
43
    }
44
45
    /**
46
     * @return array
47
     */
48
    public function args(): array
49
    {
50
        return $this->argumentsWithLimit([
51
            'id' => [
52
                'type'        => Type::id(),
53
                'description' => 'Tip identifier',
54
            ],
55
        ]);
56
    }
57
58
    /**
59
     * @param        $root
60
     * @param  array $args
61
     * @return Collection
62
     */
63
    public function resolve($root, array $args = []): Collection
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...
64
    {
65
        /** @var Builder $query */
66
        $query = Tip::with('likes', 'dislikes', 'user');
67
68
        $query = $this->paginate($query, $args);
69
70
        foreach ($args as $field => $value) {
71
            $query = $query->where($field, $value);
72
        }
73
74
        return TipSerializer::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\Support\Collection>, 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...
75
    }
76
}
77