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

NonNullType::isCompositeType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
ccs 0
cts 2
cp 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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