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

processModelRelationshipDirective()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 7
ccs 0
cts 2
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\DirectiveException;
6
use Modelarium\Exception\Exception;
7
use Modelarium\Laravel\Targets\MigrationGenerator;
8
use Modelarium\Laravel\Targets\ModelGenerator;
9
use Modelarium\Laravel\Targets\Interfaces\MigrationDirectiveInterface;
10
use Modelarium\Laravel\Targets\Interfaces\ModelDirectiveInterface;
11
use Modelarium\Laravel\Targets\MigrationCodeFragment;
12
13
class MigrationFulltextIndexDirective implements MigrationDirectiveInterface, ModelDirectiveInterface
14
{
15 1
    public static function processMigrationTypeDirective(
16
        MigrationGenerator $generator,
17
        \GraphQL\Language\AST\DirectiveNode $directive
18
    ): void {
19
        /** @phpstan-ignore-next-line */
20 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...
21
22 1
        $indexFields = [];
23 1
        foreach ($values as $value) {
24 1
            $indexFields[] = $value->value;
25
        }
26
27 1
        if (!count($indexFields)) {
28
            throw new Exception("You must provide at least one field to a full text index");
29
        }
30 1
        $generator->postCreateCode[] = "DB::statement('ALTER TABLE " .
31 1
            $generator->getLowerNamePlural() .
32 1
            " ADD FULLTEXT fulltext_index (\"" .
33 1
            implode('", "', $indexFields) .
34 1
            "\")');";
35 1
    }
36
37
    public static function processMigrationFieldDirective(
38
        MigrationGenerator $generator,
39
        \GraphQL\Type\Definition\FieldDefinition $field,
40
        \GraphQL\Language\AST\DirectiveNode $directive,
41
        MigrationCodeFragment $code
42
    ): void {
43
        throw new DirectiveException("Directive not supported here");
44
    }
45
46
    public static function processMigrationRelationshipDirective(
47
        MigrationGenerator $generator,
48
        \GraphQL\Type\Definition\FieldDefinition $field,
49
        \GraphQL\Language\AST\DirectiveNode $directive,
50
        MigrationCodeFragment $code
51
    ): void {
52
        throw new DirectiveException("Directive not supported here");
53
    }
54
55
    public static function processModelTypeDirective(
56
        ModelGenerator $generator,
57
        \GraphQL\Language\AST\DirectiveNode $directive
58
    ): void {
59
        throw new Exception("Fulltext index model is not implemented yet");
60
    }
61
62
    public static function processModelFieldDirective(
63
        ModelGenerator $generator,
64
        \GraphQL\Type\Definition\FieldDefinition $field,
65
        \Formularium\Field $fieldFormularium,
66
        \GraphQL\Language\AST\DirectiveNode $directive
67
    ): void {
68
        // nothing
69
    }
70
71
    public static function processModelRelationshipDirective(
72
        ModelGenerator $generator,
73
        \GraphQL\Type\Definition\FieldDefinition $field,
74
        \GraphQL\Language\AST\DirectiveNode $directive
75
    ): string {
76
        // nothing
77
        return '';
78
    }
79
}
80