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

MigrationSpatialIndexDirective   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 27.27%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 4
c 1
b 0
f 0
dl 0
loc 40
ccs 3
cts 11
cp 0.2727
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A processModelFieldDirective() 0 5 1
A processModelTypeDirective() 0 5 1
A processMigrationFieldDirective() 0 5 1
A processMigrationTypeDirective() 0 6 1
A processModelRelationshipDirective() 0 7 1
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 MigrationSpatialIndexDirective 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
        $generator->createCode[] = '$table->spatialIndex("' . $directive->arguments[0]->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...
19 1
    }
20
21
    public static function processMigrationFieldDirective(
22
        MigrationGenerator $generator,
23
        \GraphQL\Type\Definition\FieldDefinition $field,
24
        \GraphQL\Language\AST\DirectiveNode $directive
25
    ): void {
26
        // nothing
27
    }
28
29
    public static function processModelTypeDirective(
30
        ModelGenerator $generator,
31
        \GraphQL\Language\AST\DirectiveNode $directive
32
    ): void {
33
        throw new Exception("Primary index is not implemented yet");
34
    }
35
36
    public static function processModelFieldDirective(
37
        ModelGenerator $generator,
38
        \GraphQL\Type\Definition\FieldDefinition $field,
39
        \GraphQL\Language\AST\DirectiveNode $directive
40
    ): void {
41
        // nothing
42
    }
43
44
    public static function processModelRelationshipDirective(
45
        ModelGenerator $generator,
46
        \GraphQL\Type\Definition\FieldDefinition $field,
47
        \GraphQL\Language\AST\DirectiveNode $directive
48
    ): string {
49
        // nothing
50
        return '';
51
    }
52
}
53