Completed
Push — master ( 461e07...b4459a )
by Alexandr
03:37
created

NonNullType::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
ccs 2
cts 2
cp 1
cc 1
eloc 2
nc 1
nop 0
crap 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
use Youshido\GraphQL\Type\Config\TypeConfigInterface;
13
14
class NonNullType extends AbstractType implements CompositeTypeInterface
15
{
16
    private $_typeOf;
17
18
    /**
19
     * NonNullType constructor.
20
     * @param AbstractType|string $fieldType
21
     */
22 4
    public function __construct($fieldType)
23
    {
24 4
        if (TypeMap::isScalarType($fieldType)) {
25 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 25 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...
26
        }
27 4
        $this->_typeOf = $fieldType;
28 4
    }
29
30
    public function build($config) {}
31
32
33 3
    public function getName()
34
    {
35 3
        return null;
36
    }
37
38 4
    public function getKind()
39
    {
40 4
        return TypeMap::KIND_NON_NULL;
41
    }
42
43
    public function resolve($value)
44
    {
45
        return $value;
46
    }
47
48 1
    public function isValidValue($value)
49
    {
50 1
        return $value !== null;
51
    }
52
53
    public function isCompositeType()
54
    {
55
        return true;
56
    }
57
58
    public function getNamedType()
59
    {
60
        return $this->getTypeOf();
61
    }
62
63 4
    public function getNullableType()
64
    {
65 4
        return $this->getTypeOf();
66
    }
67
68 4
    public function getTypeOf()
69
    {
70 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 70 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...
71
    }
72
73
74
}
75