Completed
Push — master ( f8702a...461e07 )
by Alexandr
04:08
created

NonNullType   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 65.22%

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 11
c 4
b 1
f 0
lcom 1
cbo 2
dl 0
loc 62
rs 10
ccs 15
cts 23
cp 0.6522

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A checkBuild() 0 3 1
A getName() 0 4 1
A getKind() 0 4 1
A resolve() 0 4 1
A isValidValue() 0 4 1
A isCompositeType() 0 4 1
A getNamedType() 0 4 1
A getNullableType() 0 4 1
A getTypeOf() 0 4 1
1
<?php
2
/*
3
 * This file is a part of GraphQL project.
4
 *
5
 * @author Alexandr Viniychuk <[email protected]>
6
 * created: 3:40 PM 4/29/16
7
 */
8
9
namespace Youshido\GraphQL\Type;
10
11
12
class NonNullType extends AbstractType implements CompositeTypeInterface
13
{
14
    private $_typeOf;
15
16
    /**
17
     * NonNullType constructor.
18
     * @param AbstractType|string $fieldType
19
     */
20 4
    public function __construct($fieldType)
21
    {
22 4
        if (TypeMap::isScalarType($fieldType)) {
23 4
            $fieldType = TypeMap::getScalarTypeObject($fieldType);
0 ignored issues
show
Bug introduced by
It seems like $fieldType defined by \Youshido\GraphQL\Type\T...rTypeObject($fieldType) on line 23 can also be of type object<Youshido\GraphQL\Type\AbstractType>; however, Youshido\GraphQL\Type\Ty...::getScalarTypeObject() does only seem to accept string, 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...
24
        }
25 4
        $this->_typeOf = $fieldType;
26 4
    }
27
28
    public function checkBuild()
29
    {
30
    }
31
32 3
    public function getName()
33
    {
34 3
        return null;
35
    }
36
37 4
    public function getKind()
38
    {
39 4
        return TypeMap::KIND_NON_NULL;
40
    }
41
42
    public function resolve($value)
43
    {
44
        return $value;
45
    }
46
47 1
    public function isValidValue($value)
48
    {
49 1
        return $value !== null;
50
    }
51
52
    public function isCompositeType()
53
    {
54
        return true;
55
    }
56
57
    public function getNamedType()
58
    {
59
        return $this->getTypeOf();
60
    }
61
62 4
    public function getNullableType()
63
    {
64 4
        return $this->getTypeOf();
65
    }
66
67 4
    public function getTypeOf()
68
    {
69 4
        return $this->_typeOf;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->_typeOf; of type Youshido\GraphQL\Type\AbstractType|string adds the type string to the return on line 69 which is incompatible with the return type declared by the interface Youshido\GraphQL\Type\Co...ypeInterface::getTypeOf of type Youshido\GraphQL\Type\AbstractType.
Loading history...
70
    }
71
72
73
}
74