CheckCompiler::compile()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 9
ccs 7
cts 7
cp 1
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Umbrellio\Postgres\Compilers;
6
7
use Illuminate\Database\Schema\Blueprint;
8
use Illuminate\Database\Schema\Grammars\Grammar;
9
use Umbrellio\Postgres\Compilers\Traits\WheresBuilder;
10
use Umbrellio\Postgres\Schema\Builders\Constraints\Check\CheckBuilder;
11
12
class CheckCompiler
13
{
14
    use WheresBuilder;
15
16 3
    public static function compile(Grammar $grammar, Blueprint $blueprint, CheckBuilder $command): string
17
    {
18 3
        $wheres = static::build($grammar, $blueprint, $command);
19
20 3
        return sprintf(
21 3
            'ALTER TABLE %s ADD CONSTRAINT %s CHECK (%s)',
22 3
            $blueprint->getTable(),
23 3
            $command->get('index'),
24 3
            static::removeLeadingBoolean(implode(' ', $wheres))
25 3
        );
26
    }
27
}
28