Passed
Push — master ( 0971b0...b7d7cf )
by Kirill
03:21
created

IntrospectionDocument::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 10
cts 10
cp 1
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\Introspection;
11
12
use Railt\Io\Exception\NotReadableException;
13
use Railt\Io\File;
14
use Railt\Io\Readable;
15
use Railt\Reflection\Document;
16
use Railt\Reflection\Introspection\Enum\DirectiveLocationEnum;
17
use Railt\Reflection\Introspection\Enum\TypeKindEnum;
18
use Railt\Reflection\Introspection\Object\DirectiveObject;
19
use Railt\Reflection\Introspection\Object\EnumValueObject;
20
use Railt\Reflection\Introspection\Object\FieldObject;
21
use Railt\Reflection\Introspection\Object\InputValueObject;
22
use Railt\Reflection\Introspection\Object\SchemaObject;
23
use Railt\Reflection\Introspection\Object\TypeObject;
24
use Railt\Reflection\Reflection;
25
26
/**
27
 * Class IntrospectionDocument
28
 */
29
class IntrospectionDocument extends Document
30
{
31
    /**
32
     * @var string
33
     */
34
    public const INTROSPECTION_SCHEMA_PATH = __DIR__ . '/../../resources/introspection.graphqls';
35
36
    /**
37
     * IntrospectionDocument constructor.
38
     * @param Reflection $parent
39
     */
40 9
    public function __construct(Reflection $parent)
41
    {
42 9
        parent::__construct($parent, $this->getSchemaFile());
43
44 9
        $this->boot();
45 9
    }
46
47
    /**
48
     * @return Readable
49
     */
50 9
    private function getSchemaFile(): Readable
51
    {
52
        try {
53 9
            return File::fromPathname(static::INTROSPECTION_SCHEMA_PATH);
54
        } catch (NotReadableException $e) {
55
            return File::fromSources('');
56
        }
57
    }
58
59
    /**
60
     * @return void
61
     */
62 9
    private function boot(): void
63
    {
64 9
        $this->withDefinition(new SchemaObject($this));
65 9
        $this->withDefinition(new TypeObject($this));
66 9
        $this->withDefinition(new FieldObject($this));
67 9
        $this->withDefinition(new InputValueObject($this));
68 9
        $this->withDefinition(new DirectiveObject($this));
69 9
        $this->withDefinition(new EnumValueObject($this));
70 9
        $this->withDefinition(new TypeKindEnum($this));
71 9
        $this->withDefinition(new DirectiveLocationEnum($this));
72 9
    }
73
}
74