Passed
Push — master ( a41166...4c99b3 )
by Bruno
03:13
created

CastsDirective::processModelFieldDirective()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 16
ccs 0
cts 7
cp 0
rs 10
cc 3
nc 3
nop 3
crap 12
1
<?php declare(strict_types=1);
2
3
namespace Modelarium\Laravel\Directives;
4
5
use GraphQL\Language\AST\DirectiveNode;
6
use Modelarium\Laravel\Targets\ModelGenerator;
7
use Modelarium\Laravel\Targets\Interfaces\ModelDirectiveInterface;
8
9
class CastsDirective implements ModelDirectiveInterface
10
{
11
    public static function processModelTypeDirective(
12
        ModelGenerator $generator,
13
        \GraphQL\Language\AST\DirectiveNode $directive
14
    ): void {
15
    }
16
17
    public static function processModelFieldDirective(
18
        ModelGenerator $generator,
19
        \GraphQL\Type\Definition\FieldDefinition $field,
20
        \GraphQL\Language\AST\DirectiveNode $directive
21
    ): void {
22
        $fieldName = $field->name;
23
        foreach ($directive->arguments as $arg) {
24
            /**
25
             * @var \GraphQL\Language\AST\ArgumentNode $arg
26
             */
27
            /** @phpstan-ignore-next-line */
28
            $value = $arg->value->value;
0 ignored issues
show
Bug introduced by
Accessing value on the interface GraphQL\Language\AST\ValueNode suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
29
30
            switch ($arg->name->value) {
31
            case 'type':
32
                $generator->casts[$fieldName] = $value;
33
            }
34
        }
35
    }
36
37
    public function processModelRelationshipDirective(
38
        ModelGenerator $generator,
39
        \GraphQL\Type\Definition\FieldDefinition $field,
40
        \GraphQL\Language\AST\DirectiveNode $directive
41
    ): void {
42
    }
43
}
44