Completed
Push — master ( 2705ab...006cbd )
by Dmitry
04:32
created

Clear::run()   B

Complexity

Conditions 5
Paths 9

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 19
ccs 12
cts 12
cp 1
rs 8.8571
cc 5
eloc 11
nc 9
nop 1
crap 5
1
<?php
2
3
namespace Basis\Job\Tarantool;
4
5
use Basis\Job;
6
use Tarantool\Client\Client;
7
use Tarantool\Client\Schema\Index;
8
9
class Clear extends Job
10
{
11 5
    public function run(Client $client)
12
    {
13 5
        $space = $client->getSpace('_vspace');
14 5
        $response = $space->select([], Index::SPACE_NAME);
15 5
        $data = $response->getData();
16 5
        foreach ($data as $row) {
17 5
            if ($row[1] == 0) {
18
                // user space
19 5
                $client->evaluate('box.space.'.$row[2].':drop{}');
20
            }
21
        }
22
23 5
        $schema = $client->getSpace('_schema')->select([], 0)->getData();
24 5
        foreach ($schema as $tuple) {
25 5
            if (strpos($tuple[0], 'mapper-once') === 0) {
26 5
                $client->getSpace('_schema')->delete([$tuple[0]]);
27
            }
28
        }
29 5
    }
30
}
31