Passed
Push — master ( 6bf22a...09030e )
by Bruno
04:28
created

processMigrationFieldDirective()   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
cc 1
eloc 1
nc 1
nop 4
dl 0
loc 7
ccs 0
cts 2
cp 0
crap 2
rs 10
c 1
b 0
f 0
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
use Modelarium\Parser;
13
14
class MigrationFulltextIndexDirective implements MigrationDirectiveInterface, ModelDirectiveInterface
15
{
16 1
    public static function processMigrationTypeDirective(
17
        MigrationGenerator $generator,
18
        \GraphQL\Language\AST\DirectiveNode $directive
19
    ): void {
20 1
        $indexFields = Parser::getDirectiveArgumentByName($directive, 'fields');
21
22 1
        if (!count($indexFields)) {
23
            throw new Exception("You must provide at least one field to a full text index");
24
        }
25 1
        $generator->postCreateCode[] = "DB::statement('ALTER TABLE " .
26 1
            $generator->getTableName()  .
27 1
            " ADD FULLTEXT fulltext_index (\"" .
28 1
            implode('", "', $indexFields) .
0 ignored issues
show
Bug introduced by
It seems like $indexFields can also be of type null; however, parameter $pieces of implode() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

28
            implode('", "', /** @scrutinizer ignore-type */ $indexFields) .
Loading history...
29 1
            "\")');";
30 1
    }
31
32
    public static function processMigrationFieldDirective(
33
        MigrationGenerator $generator,
34
        \GraphQL\Type\Definition\FieldDefinition $field,
35
        \GraphQL\Language\AST\DirectiveNode $directive,
36
        MigrationCodeFragment $code
37
    ): void {
38
        throw new DirectiveException("Directive not supported here");
39
    }
40
41
    public static function processMigrationRelationshipDirective(
42
        MigrationGenerator $generator,
43
        \GraphQL\Type\Definition\FieldDefinition $field,
44
        \GraphQL\Language\AST\DirectiveNode $directive,
45
        MigrationCodeFragment $code
46
    ): void {
47
        throw new DirectiveException("Directive not supported here");
48
    }
49
50
    public static function processModelTypeDirective(
51
        ModelGenerator $generator,
52
        \GraphQL\Language\AST\DirectiveNode $directive
53
    ): void {
54
        throw new Exception("Fulltext index model is not implemented yet");
55
    }
56
57
    public static function processModelFieldDirective(
58
        ModelGenerator $generator,
59
        \GraphQL\Type\Definition\FieldDefinition $field,
60
        \Formularium\Field $fieldFormularium,
61
        \GraphQL\Language\AST\DirectiveNode $directive
62
    ): void {
63
        // nothing
64
    }
65
66
    public static function processModelRelationshipDirective(
67
        ModelGenerator $generator,
68
        \GraphQL\Type\Definition\FieldDefinition $field,
69
        \GraphQL\Language\AST\DirectiveNode $directive
70
    ): string {
71
        // nothing
72
        return '';
73
    }
74
}
75