Test Failed
Push — feature-laravel-5.4 ( 556e60...89a18e )
by Kirill
03:48
created

DocsQuery::type()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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
10
namespace App\GraphQL\Queries;
11
12
use App\GraphQL\Serializers\DocsSerializer;
13
use App\Models\Docs;
14
use App\GraphQL\Types\DocsType;
15
use GraphQL\Type\Definition\Type;
16
use Illuminate\Support\Collection;
17
use Folklore\GraphQL\Support\Query;
18
use GraphQL\Type\Definition\ListOfType;
19
use App\GraphQL\Queries\Support\QueryLimit;
20
use App\GraphQL\Serializers\ArticleSerializer;
21
22
/**
23
 * Class DocsQuery.
24
 */
25
class DocsQuery extends Query
26
{
27
    use QueryLimit;
28
29
    /**
30
     * @var array
31
     */
32
    protected $attributes = [
33
        'name'        => 'Docs list query',
34
        'description' => 'Returns a list of available documentation repositories',
35
    ];
36
37
    /**
38
     * @return ListOfType
39
     */
40
    public function type(): ListOfType
41
    {
42
        return Type::listOf(\GraphQL::type(DocsType::getName()));
43
    }
44
45
    /**
46
     * @return array
47
     */
48
    public function args(): array
49
    {
50
        return $this->argumentsWithLimit([]);
51
    }
52
53
    /**
54
     * @param $root
55
     * @param  array      $args
56
     * @return Collection
57
     */
58
    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...
59
    {
60
        $query = Docs::with('pages');
61
62
        $query = $this->paginate($query, $args);
0 ignored issues
show
Bug introduced by
It seems like $query can also be of type object<Illuminate\Database\Eloquent\Model>; however, App\GraphQL\Queries\Support\QueryLimit::paginate() does only seem to accept object<Illuminate\Databa...Database\Query\Builder>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
63
64
        foreach ($args as $field => $value) {
65
            $query = $query->where($field, $value);
66
        }
67
68
        return DocsSerializer::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...
69
    }
70
}
71