Passed
Push — master ( f71ccb...0ebae0 )
by Bruno
03:45
created

processModelFieldDirective()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 0
c 1
b 0
f 0
dl 0
loc 5
ccs 0
cts 1
cp 0
rs 10
cc 1
nc 1
nop 3
crap 2
1
<?php declare(strict_types=1);
2
3
namespace Modelarium\Laravel\Directives;
4
5
use Modelarium\Exception\Exception;
6
use Modelarium\Laravel\Targets\MigrationGenerator;
7
use Modelarium\Laravel\Targets\ModelGenerator;
8
use Modelarium\Laravel\Targets\Interfaces\MigrationDirectiveInterface;
9
use Modelarium\Laravel\Targets\Interfaces\ModelDirectiveInterface;
10
11
class MigrationIndexDirective implements MigrationDirectiveInterface, ModelDirectiveInterface
12
{
13 1
    public static function processMigrationTypeDirective(
14
        MigrationGenerator $generator,
15
        \GraphQL\Language\AST\DirectiveNode $directive
16
    ): void {
17
        /** @phpstan-ignore-next-line */
18 1
        $values = $directive->arguments[0]->value->values;
0 ignored issues
show
Bug introduced by
Accessing values on the interface GraphQL\Language\AST\ValueNode suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
19
20 1
        $indexFields = [];
21 1
        foreach ($values as $value) {
22 1
            $indexFields[] = $value->value;
23
        }
24 1
        if (!count($indexFields)) {
25
            throw new Exception("You must provide at least one field to an index");
26
        }
27 1
        $generator->createCode[] ='$table->index("' . implode('", "', $indexFields) .'");';
28 1
    }
29
30
    public static function processMigrationFieldDirective(
31
        MigrationGenerator $generator,
32
        \GraphQL\Type\Definition\FieldDefinition $field,
33
        \GraphQL\Language\AST\DirectiveNode $directive
34
    ): void {
35
        // nothing
36
    }
37
38
    public static function processModelTypeDirective(
39
        ModelGenerator $generator,
40
        \GraphQL\Language\AST\DirectiveNode $directive
41
    ): void {
42
        throw new Exception("Primary index is not implemented yet");
43
    }
44
45
    public static function processModelFieldDirective(
46
        ModelGenerator $generator,
47
        \GraphQL\Type\Definition\FieldDefinition $field,
48
        \GraphQL\Language\AST\DirectiveNode $directive
49
    ): void {
50
        // nothing
51
    }
52
53
    public static function processModelRelationshipDirective(
54
        ModelGenerator $generator,
55
        \GraphQL\Type\Definition\FieldDefinition $field,
56
        \GraphQL\Language\AST\DirectiveNode $directive
57
    ): string {
58
        // nothing
59
        return '';
60
    }
61
}
62