UniqueCompiler   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 9
c 1
b 0
f 0
dl 0
loc 18
ccs 8
cts 8
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A compile() 0 14 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