Test Failed
Push — master ( b79e07...d820d2 )
by Kirill
02:16
created

SchemaDefinition::isInputable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 0
cts 0
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
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 Railt\Reflection\Definition;
11
12
use Railt\Reflection\AbstractTypeDefinition;
13
use Railt\Reflection\Contracts\Definition\ObjectDefinition;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Railt\Reflection\Definition\ObjectDefinition.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
14
use Railt\Reflection\Contracts\Definition\SchemaDefinition as SchemaDefinitionInterface;
15
use Railt\Reflection\Contracts\Definition\TypeDefinition;
16
use Railt\Reflection\Contracts\Document;
17
use Railt\Reflection\Contracts\Type as TypeInterface;
18
use Railt\Reflection\Type;
19
20
/**
21
 * Class SchemaDefinition
22
 */
23
class SchemaDefinition extends AbstractTypeDefinition implements SchemaDefinitionInterface
24
{
25
    /**
26
     * @var string
27
     */
28
    protected $query;
29
30
    /**
31
     * @var string|null
32
     */
33
    protected $mutation;
34
35
    /**
36
     * @var string|null
37
     */
38
    protected $subscription;
39
40
    /**
41
     * SchemaDefinition constructor.
42
     * @param Document|\Railt\Reflection\Contracts\Document $document
43
     * @param string|null $name
44
     */
45
    public function __construct(Document $document, string $name = null)
46
    {
47
        parent::__construct($document, $name ?? self::DEFAULT_SCHEMA_NAME);
0 ignored issues
show
Compatibility introduced by
$document of type object<Railt\Reflection\Contracts\Document> is not a sub-type of object<Railt\Reflection\Document>. It seems like you assume a concrete implementation of the interface Railt\Reflection\Contracts\Document to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
48
    }
49
50
    /**
51
     * @return TypeInterface
52
     */
53
    public static function getType(): TypeInterface
54
    {
55
        return Type::of(Type::SCHEMA);
56
    }
57
58
    /**
59
     * @param TypeDefinition|string $query
60
     * @return SchemaDefinition
61
     * @throws \Railt\Io\Exception\ExternalFileException
62
     */
63
    public function withQuery($query): SchemaDefinition
64
    {
65
        $this->query = $this->nameOf($query);
66
67
        return $this;
68
    }
69
70
    /**
71
     * @return ObjectDefinition|TypeDefinition
72
     */
73
    public function getQuery(): ObjectDefinition
74
    {
75
        return $this->fetch($this->query);
76
    }
77
78
    /**
79
     * @param TypeDefinition|null $mutation
80
     * @return SchemaDefinition
81
     * @throws \Railt\Io\Exception\ExternalFileException
82
     */
83
    public function withMutation($mutation = null): SchemaDefinition
84
    {
85
        $this->mutation = $mutation ? $this->nameOf($mutation) : null;
86
87
        return $this;
88
    }
89
90
    /**
91
     * @return null|ObjectDefinition|TypeDefinition
92
     * @throws \Railt\Io\Exception\ExternalFileException
93
     */
94
    public function getMutation(): ?ObjectDefinition
95
    {
96
        return $this->fetchOrNull($this->mutation);
97
    }
98
99
    /**
100
     * @return bool
101
     */
102
    public function hasMutation(): bool
103
    {
104
        return $this->mutation !== null;
105
    }
106
107
    /**
108
     * @param ObjectDefinition|null $subscription
109
     * @return SchemaDefinition
110
     * @throws \Railt\Io\Exception\ExternalFileException
111
     */
112
    public function withSubscription($subscription = null): SchemaDefinition
113
    {
114
        $this->subscription = $subscription ? $this->nameOf($subscription) : null;
115
116
        return $this;
117
    }
118
119
    /**
120
     * @return null|ObjectDefinition|TypeDefinition
121
     * @throws \Railt\Io\Exception\ExternalFileException
122
     */
123
    public function getSubscription(): ?ObjectDefinition
124
    {
125
        return $this->fetchOrNull($this->subscription);
126
    }
127
128
    /**
129
     * @return bool
130
     */
131
    public function hasSubscription(): bool
132
    {
133
        return $this->subscription !== null;
134
    }
135
136
    /**
137
     * @return bool
138
     */
139
    public function isRenderable(): bool
140
    {
141
        return false;
142
    }
143
144
    /**
145
     * @return bool
146
     */
147
    public function isInputable(): bool
148
    {
149
        return false;
150
    }
151
}
152