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()); |
|
|
|
|
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)); |
|
|
|
|
67
|
9 |
|
$this->withDefinition($bool = (new BooleanScalar($this))->extends($string)); |
|
|
|
|
68
|
9 |
|
$this->withDefinition($float = (new FloatScalar($this))->extends($string)); |
|
|
|
|
69
|
9 |
|
$this->withDefinition($id = (new IdScalar($this))->extends($string)); |
|
|
|
|
70
|
9 |
|
$this->withDefinition($int = (new IntScalar($this))->extends($float)); |
|
|
|
|
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
|
|
|
|
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.