CastsDirective   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 36
ccs 0
cts 12
cp 0
rs 10
c 1
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A processModelTypeDirective() 0 4 1
A processModelFieldDirective() 0 17 3
A processModelRelationshipDirective() 0 7 1
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
       \Formularium\Field $fieldFormularium,
21
        \GraphQL\Language\AST\DirectiveNode $directive
22
    ): void {
23
        $fieldName = $field->name;
24
        foreach ($directive->arguments as $arg) {
25
            /**
26
             * @var \GraphQL\Language\AST\ArgumentNode $arg
27
             */
28
            /** @phpstan-ignore-next-line */
29
            $value = $arg->value->value;
30
31
            switch ($arg->name->value) {
32
            case 'type':
33
                $generator->casts[$fieldName] = $value;
34
            }
35
        }
36
    }
37
38
    public static function processModelRelationshipDirective(
39
        ModelGenerator $generator,
40
        \GraphQL\Type\Definition\FieldDefinition $field,
41
        \GraphQL\Language\AST\DirectiveNode $directive,
42
        \Formularium\Datatype $datatype = null
43
    ): ?\Formularium\Datatype {
44
        return null;
45
    }
46
}
47