Passed
Push — master ( 73a53e...f91dab )
by Bruno
07:25 queued 04:03
created

MigrationDefaultValueDirective   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 26
ccs 0
cts 8
cp 0
rs 10
c 2
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A processMigrationTypeDirective() 0 5 1
A processMigrationRelationshipDirective() 0 7 1
A processMigrationFieldDirective() 0 8 1
1
<?php declare(strict_types=1);
2
3
namespace Modelarium\Laravel\Directives;
4
5
use Modelarium\Exception\DirectiveException;
6
use Modelarium\Laravel\Targets\MigrationGenerator;
7
use Modelarium\Laravel\Targets\Interfaces\MigrationDirectiveInterface;
8
use Modelarium\Laravel\Targets\MigrationCodeFragment;
9
use Modelarium\Parser;
10
11
class MigrationDefaultValueDirective implements MigrationDirectiveInterface
12
{
13
    public static function processMigrationTypeDirective(
14
        MigrationGenerator $generator,
15
        \GraphQL\Language\AST\DirectiveNode $directive
16
    ): void {
17
        throw new DirectiveException("@defaultValue not allowed on types.");
18
    }
19
20
    public static function processMigrationFieldDirective(
21
        MigrationGenerator $generator,
22
        \GraphQL\Type\Definition\FieldDefinition $field,
23
        \GraphQL\Language\AST\DirectiveNode $directive,
24
        MigrationCodeFragment $code
25
    ): void {
26
        $x = Parser::getDirectiveArgumentByName($directive, 'value');
27
        $code->appendBase('->default(' . $x . ')');
28
    }
29
30
    public static function processMigrationRelationshipDirective(
31
        MigrationGenerator $generator,
32
        \GraphQL\Type\Definition\FieldDefinition $field,
33
        \GraphQL\Language\AST\DirectiveNode $directive,
34
        MigrationCodeFragment $code
35
    ): void {
36
        throw new DirectiveException("@defaultValue not allowed on relationships.");
37
    }
38
}
39