UniqueCompiler::compile()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 4
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Umbrellio\Postgres\Compilers;
6
7
use Illuminate\Database\Schema\Grammars\Grammar;
8
use Umbrellio\Postgres\Compilers\Traits\WheresBuilder;
9
use Umbrellio\Postgres\Schema\Blueprint;
10
use Umbrellio\Postgres\Schema\Builders\Indexes\Unique\UniqueBuilder;
11
use Umbrellio\Postgres\Schema\Builders\Indexes\Unique\UniquePartialBuilder;
12
13
class UniqueCompiler
14
{
15
    use WheresBuilder;
16
17 12
    public static function compile(
18
        Grammar $grammar,
19
        Blueprint $blueprint,
20
        UniqueBuilder $fluent,
21
        UniquePartialBuilder $command
22
    ): string {
23 12
        $wheres = static::build($grammar, $blueprint, $command);
24
25 12
        return sprintf(
26 12
            'CREATE UNIQUE INDEX %s ON %s (%s) WHERE %s',
27 12
            $fluent->get('index'),
28 12
            $blueprint->getTable(),
29 12
            implode(',', (array) $fluent->get('columns')),
30 12
            static::removeLeadingBoolean(implode(' ', $wheres))
31 12
        );
32
    }
33
}
34