Test Failed
Push — master ( 3b7232...dbe410 )
by Kirill
02:20
created

GraphQLDocument::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
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\Stdlib;
11
12
use Railt\Io\Exception\NotReadableException;
13
use Railt\Io\File;
14
use Railt\Io\Readable;
15
use Railt\Reflection\Contracts\Reflection;
16
use Railt\Reflection\Document;
17
use Railt\Reflection\Stdlib\Directive\DeprecatedDirective;
18
use Railt\Reflection\Stdlib\Directive\IncludeDirective;
19
use Railt\Reflection\Stdlib\Directive\SkipDirective;
20
use Railt\Reflection\Stdlib\Scalar\BooleanScalar;
21
use Railt\Reflection\Stdlib\Scalar\DateTimeScalar;
22
use Railt\Reflection\Stdlib\Scalar\FloatScalar;
23
use Railt\Reflection\Stdlib\Scalar\IdScalar;
24
use Railt\Reflection\Stdlib\Scalar\IntScalar;
25
use Railt\Reflection\Stdlib\Scalar\StringScalar;
26
27
/**
28
 * Class GraphQLDocument
29
 */
30
class GraphQLDocument extends Document
31
{
32
    /**
33
     * @var string
34
     */
35
    public const STDLIB_SCHEMA_PATH = __DIR__ . '/../../resources/stdlib.graphqls';
36
37
    /**
38
     * GraphQLDocument constructor.
39
     * @param Reflection $parent
40
     */
41 9
    public function __construct(Reflection $parent)
42
    {
43 9
        parent::__construct($parent, $this->getSchemaFile());
0 ignored issues
show
Compatibility introduced by
$parent of type object<Railt\Reflection\Contracts\Reflection> is not a sub-type of object<Railt\Reflection\Reflection>. It seems like you assume a concrete implementation of the interface Railt\Reflection\Contracts\Reflection 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...
44
45 9
        $this->boot();
46 9
    }
47
48
    /**
49
     * @return Readable
50
     */
51 9
    private function getSchemaFile(): Readable
52
    {
53
        try {
54 9
            return File::fromPathname(static::STDLIB_SCHEMA_PATH);
55
        } catch (NotReadableException $e) {
56
            return File::fromSources('');
57
        }
58
    }
59
60
    /**
61
     * @return void
62
     */
63 9
    private function boot(): void
64
    {
65 9
        $this->withDefinition($string = new StringScalar($this));
66 9
        $this->withDefinition($date = (new DateTimeScalar($this))->extends($string));
0 ignored issues
show
Documentation introduced by
$date = (new \Railt\Refl...his))->extends($string) is of type object<Railt\Reflection\...haviour\HasInheritance>, but the function expects a object<Railt\Reflection\...inition\TypeDefinition>.

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...
67 9
        $this->withDefinition($bool = (new BooleanScalar($this))->extends($string));
0 ignored issues
show
Documentation introduced by
$bool = (new \Railt\Refl...his))->extends($string) is of type object<Railt\Reflection\...haviour\HasInheritance>, but the function expects a object<Railt\Reflection\...inition\TypeDefinition>.

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...
68 9
        $this->withDefinition($float = (new FloatScalar($this))->extends($string));
0 ignored issues
show
Documentation introduced by
$float = (new \Railt\Ref...his))->extends($string) is of type object<Railt\Reflection\...haviour\HasInheritance>, but the function expects a object<Railt\Reflection\...inition\TypeDefinition>.

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...
69 9
        $this->withDefinition($id = (new IdScalar($this))->extends($string));
0 ignored issues
show
Documentation introduced by
$id = (new \Railt\Reflec...his))->extends($string) is of type object<Railt\Reflection\...haviour\HasInheritance>, but the function expects a object<Railt\Reflection\...inition\TypeDefinition>.

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...
70 9
        $this->withDefinition($int = (new IntScalar($this))->extends($float));
0 ignored issues
show
Documentation introduced by
$int = (new \Railt\Refle...this))->extends($float) is of type object<Railt\Reflection\...haviour\HasInheritance>, but the function expects a object<Railt\Reflection\...inition\TypeDefinition>.

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...
71
72 9
        $this->withDefinition($any = new AnyType($this));
73
74 9
        $this->withDefinition($deprecated = new DeprecatedDirective($this));
75 9
        $this->withDefinition($include = new IncludeDirective($this));
76 9
        $this->withDefinition($skip = new SkipDirective($this));
77 9
    }
78
}
79