Passed
Push — master ( 81686d...1595cb )
by Kirill
04:41
created

ScalarTypeDefinitionContext   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 8
dl 0
loc 32
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A resolve() 0 13 2
1
<?php
2
3
/**
4
 * This file is part of Railt package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Railt\SDL\Backend\Context;
13
14
use GraphQL\Contracts\TypeSystem\Type\ScalarTypeInterface;
15
use Railt\SDL\Backend\Context;
16
use Railt\SDL\Frontend\Ast\Definition\Type\ScalarTypeDefinitionNode;
17
use Railt\TypeSystem\Schema;
18
use Railt\TypeSystem\Type\ScalarType;
19
20
/**
21
 * @property-read ScalarTypeDefinitionNode $ast
22
 * @method ScalarTypeDefinitionNode getAst()
23
 */
24
class ScalarTypeDefinitionContext extends NamedTypeContext
25
{
26
    /**
27
     * ScalarTypeDefinitionContext constructor.
28
     *
29
     * @param Context $context
30
     * @param Schema $schema
31
     * @param ScalarTypeDefinitionNode $ast
32
     */
33
    public function __construct(Context $context, Schema $schema, ScalarTypeDefinitionNode $ast)
34
    {
35
        parent::__construct($context, $schema, $ast);
36
    }
37
38
    /**
39
     * @param array $variables
40
     * @return ScalarTypeInterface
41
     * @throws \Throwable
42
     */
43
    public function resolve(array $variables = []): ScalarTypeInterface
44
    {
45
        $ast = $this->precompile($this->ast, $variables);
46
47
        $scalar = new ScalarType($ast->name->value, [
48
            'description' => $this->descriptionOf($ast),
49
        ]);
50
51
        foreach ($ast->directives as $directive) {
52
            $this->executeDirective($scalar, $directive);
53
        }
54
55
        return $scalar;
56
    }
57
}
58