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

CastsDirective   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 7
c 1
b 0
f 0
dl 0
loc 33
ccs 0
cts 11
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A processModelRelationshipDirective() 0 5 1
A processModelTypeDirective() 0 4 1
A processModelFieldDirective() 0 16 3
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