Completed
Push — master ( 53b1ff...145864 )
by Dmitry
07:02 queued 02:50
created

Clear::run()   B

Complexity

Conditions 6
Paths 18

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 6.0106

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 24
ccs 14
cts 15
cp 0.9333
rs 8.5125
c 1
b 1
f 0
cc 6
eloc 14
nc 18
nop 2
crap 6.0106
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
use Basis\Filesystem;
9
10
class Clear extends Job
11
{
12 6
    public function run(Client $client, Filesystem $fs)
13
    {
14 6
        $space = $client->getSpace('_vspace');
15 6
        $response = $space->select([], Index::SPACE_NAME);
16 6
        $data = $response->getData();
17 6
        foreach ($data as $row) {
18 6
            if ($row[1] == 0) {
19
                // user space
20 6
                $client->evaluate('box.space.'.$row[2].':drop{}');
21
            }
22
        }
23
24 6
        $schema = $client->getSpace('_schema')->select([], 0)->getData();
25 6
        foreach ($schema as $tuple) {
26 6
            if (strpos($tuple[0], 'mapper-once') === 0) {
27 6
                $client->getSpace('_schema')->delete([$tuple[0]]);
28
            }
29
        }
30
31 6
        $filename = $fs->getPath('.cache/mapper-meta.php');
32 6
        if (file_exists($filename)) {
33
            unlink($filename);
34
        }
35 6
    }
36
}
37