Completed
Branch master (0bf65c)
by Dmitry
02:31
created

Migrator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 95.45%

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 6
c 4
b 1
f 0
lcom 1
cbo 4
dl 0
loc 35
ccs 21
cts 22
cp 0.9545
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A registerMigration() 0 8 2
A migrate() 0 21 4
1
<?php
2
3
namespace Tarantool\Mapper\Migrations;
4
5
use Tarantool\Mapper\Contracts;
6
use InvalidArgumentException;
7
use ReflectionClass;
8
9
class Migrator implements Contracts\Migration
10
{
11
    protected $migrations = [];
12
13 2
    public function registerMigration($class)
14
    {
15 2
        $reflection = new ReflectionClass($class);
16 2
        if (!$reflection->implementsInterface(Contracts\Migration::class)) {
17
            throw new InvalidArgumentException("Register only Migration classes");
18
        }
19 2
        $this->migrations[] = $class;
20 2
    }
21
22 4
    public function migrate(Contracts\Manager $manager)
23
    {
24 4
        if (!$manager->getSchema()->hasSpace('migrations')) {
25 4
            $instance = new Tracker();
26 4
            $instance->migrate($manager);
27 4
            $manager->save($manager->get('migrations')->make(['name' => Migration::class]));
0 ignored issues
show
Unused Code introduced by
The call to Repository::make() has too many arguments starting with array('name' => \Taranto...tions\Migration::class).

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
28 4
        }
29
30 4
        $repository = $manager->get('migrations');
31
32 4
        foreach ($this->migrations as $migration) {
33
            $row = [
34
                'name' => $migration
35 2
            ];
36 2
            if (!$repository->find($row, true)) {
37 2
                $instance = new $migration;
38 2
                $instance->migrate($manager);
39 2
                $manager->save($repository->make($row));
0 ignored issues
show
Unused Code introduced by
The call to Repository::make() has too many arguments starting with $row.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
40 2
            }
41 4
        }
42 4
    }
43
}
44