Completed
Push — master ( c02837...734e06 )
by Portey
03:28
created

AbstractUnionType::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 4
loc 4
ccs 0
cts 3
cp 0
rs 10
cc 1
eloc 1
nc 1
nop 1
crap 2
1
<?php
2
/*
3
* This file is a part of GraphQL project.
4
*
5
* @author Alexandr Viniychuk <[email protected]>
6
* created: 12/5/15 12:12 AM
7
*/
8
9
namespace Youshido\GraphQL\Type\Object;
10
11
12
use Youshido\GraphQL\Type\AbstractType;
13
use Youshido\GraphQL\Type\Config\Object\InterfaceTypeConfig;
14
use Youshido\GraphQL\Type\Config\Object\UnionTypeConfig;
15
use Youshido\GraphQL\Type\TypeMap;
16
17 View Code Duplication
abstract class AbstractUnionType extends AbstractType
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...
18
{
19
20
21
    /**
22
     * ObjectType constructor.
23
     * @param $config
24
     */
25
    public function __construct($config = [])
26
    {
27
        if (empty($config)) {
28
            $config['name']  = $this->getName();
29
            $config['types'] = $this->getTypes();
30
        }
31
32
        $this->config = new UnionTypeConfig($config, $this);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Youshido\GraphQL\Ty...eConfig($config, $this) of type object<Youshido\GraphQL\...Object\UnionTypeConfig> is incompatible with the declared type object<Youshido\GraphQL\...\InputObjectTypeConfig> of property $config.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
33
    }
34
35
    public function getName()
36
    {
37
        return $this->getConfig()->get('name', 'UnionType');
38
    }
39
40
    abstract public function resolveType($object);
41
42
    abstract public function getTypes();
43
44
    public function checkBuild()
45
    {
46
        if (!$this->isBuild) {
47
            $this->isBuild = true;
48
            $this->build($this->config);
0 ignored issues
show
Documentation introduced by
$this->config is of type object<Youshido\GraphQL\...\InputObjectTypeConfig>, but the function expects a object<Youshido\GraphQL\...Object\UnionTypeConfig>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
49
        }
50
    }
51
52
    protected function build(UnionTypeConfig $config)
0 ignored issues
show
Unused Code introduced by
The parameter $config 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...
53
    {
54
55
    }
56
57
    public function getKind()
58
    {
59
        return TypeMap::KIND_UNION;
60
    }
61
62
    public function isValidValue($value)
63
    {
64
        return true;
65
    }
66
67
}