Completed
Push — master ( 33bc8d...136dfe )
by Dmitry
03:12 queued 15s
created

CreateSequence   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 31
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 4 1
A getBody() 0 13 1
A getName() 0 4 1
A getParams() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Tarantool\Mapper\Procedure;
6
7
use Exception;
8
use Tarantool\Mapper\Plugin\Sequence;
9
use Tarantool\Mapper\Procedure;
10
use Tarantool\Mapper\Space;
11
12
class CreateSequence extends Procedure
13
{
14
    public function execute(string $space, string $primaryIndex, int $primaryField)
15
    {
16
        $this($space, $primaryIndex, $primaryField);
17
    }
18
19
    public function getBody() : string
20
    {
21
        return <<<LUA
22
        if box.sequence[space] == nil then
23
            local last = 0
24
            local tuple = box.space[space].index[primary_index]:max()
25
            if tuple ~= nil then
26
                last = tuple[primary_field]
27
            end
28
            box.schema.sequence.create(space, { start = last + 1 })
29
        end
30
LUA;
31
    }
32
33
    public function getName() : string
34
    {
35
        return 'mapper_create_sequence';
36
    }
37
38
    public function getParams() : array
39
    {
40
        return ['space', 'primary_index', 'primary_field'];
41
    }
42
}
43