Completed
Push — master ( 61e01b...82ad84 )
by Maxim
03:45
created

AbstractMigrationRegistry::getMigration()   A

Complexity

Conditions 4
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 1
nop 1
dl 0
loc 12
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace WebComplete\core\utils\migration;
4
5
use RuntimeException;
6
use WebComplete\core\utils\container\ContainerInterface;
7
8
abstract class AbstractMigrationRegistry implements MigrationRegistryInterface
9
{
10
11
    /**
12
     * @var ContainerInterface
13
     */
14
    protected $container;
15
16
    /**
17
     * @param ContainerInterface $container
18
     */
19
    public function __construct(ContainerInterface $container)
20
    {
21
        $this->container = $container;
22
    }
23
24
    /**
25
     * @param $class
26
     *
27
     * @return MigrationInterface
28
     * @throws \Exception
29
     */
30
    public function getMigration($class): MigrationInterface
31
    {
32
        $migration = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $migration is dead and can be removed.
Loading history...
33
        try {
34
            $migration = $this->container->get($class);
35
            if (!$migration || !$migration instanceof MigrationInterface) {
36
                throw new \RuntimeException('Migration must implement ' . MigrationInterface::class);
37
            }
38
        } catch (\Exception $e) {
39
            throw new RuntimeException('Migration instantiate error: ' . $class, 0, $e);
40
        }
41
        return $migration;
42
    }
43
}
44