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 MigrationFulltextIndexDirective 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
25 1
        if (!count($indexFields)) {
26
            throw new Exception("You must provide at least one field to a full text index");
27
        }
28 1
        $generator->postCreateCode[] = "DB::statement('ALTER TABLE " .
29 1
            $generator->getLowerNamePlural() .
30 1
            " ADD FULLTEXT fulltext_index (\"" .
31 1
            implode('", "', $indexFields) .
32 1
            "\")');";
33 1
    }
34
35
    public static function processMigrationFieldDirective(
36
        MigrationGenerator $generator,
37
        \GraphQL\Type\Definition\FieldDefinition $field,
38
        \GraphQL\Language\AST\DirectiveNode $directive
39
    ): void {
40
        // nothing
41
    }
42
43
    public static function processModelTypeDirective(
44
        ModelGenerator $generator,
45
        \GraphQL\Language\AST\DirectiveNode $directive
46
    ): void {
47
        throw new Exception("Primary index is not implemented yet");
48
    }
49
50
    public static function processModelFieldDirective(
51
        ModelGenerator $generator,
52
        \GraphQL\Type\Definition\FieldDefinition $field,
53
        \GraphQL\Language\AST\DirectiveNode $directive
54
    ): void {
55
        // nothing
56
    }
57
58
    public static function processModelRelationshipDirective(
59
        ModelGenerator $generator,
60
        \GraphQL\Type\Definition\FieldDefinition $field,
61
        \GraphQL\Language\AST\DirectiveNode $directive
62
    ): string {
63
        // nothing
64
        return '';
65
    }
66
}
67