Test Failed
Push — feature-laravel-5.4 ( 6f3b9a...66d75b )
by Kirill
03:40
created

UsersQuery::args()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 9
loc 9
rs 9.6666
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\GraphQL\Serializers\UserSerializer;
13
use App\GraphQL\Types\UserType;
14
use App\Models\User;
15
use GraphQL\Type\Definition\ListOfType;
16
use GraphQL\Type\Definition\Type;
17
use Illuminate\Support\Collection;
18
19
/**
20
 * Class UsersQuery.
21
 */
22 View Code Duplication
class UsersQuery extends AbstractQuery
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...
23
{
24
    /**
25
     * @var array
26
     */
27
    protected $attributes = [
28
        'name'        => 'Users list query',
29
        'description' => 'Returns a list of users',
30
    ];
31
32
    /**
33
     * @return ListOfType
34
     */
35
    public function type(): ListOfType
36
    {
37
        return Type::listOf(\GraphQL::type(UserType::getName()));
38
    }
39
40
    /**
41
     * @return array
42
     */
43
    protected function queryArguments(): array
44
    {
45
        return [];
46
    }
47
48
    /**
49
     * @param        $root
50
     * @param  array $args
51
     * @return Collection
52
     */
53
    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...
54
    {
55
        $query = $this->queryFor(User::class, $args);
56
57
        return UserSerializer::collection($query->get());
0 ignored issues
show
Bug introduced by
The method get does only exist in Illuminate\Database\Eloquent\Builder, but not in Illuminate\Database\Eloquent\Model.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
58
    }
59
}
60