AbstractMigrationRegistry::getMigration()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.2
c 0
b 0
f 0
cc 4
eloc 7
nc 3
nop 1
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
        try {
33
            $migration = $this->container->get($class);
34
            if (!$migration || !$migration instanceof MigrationInterface) {
35
                throw new \RuntimeException('Migration must implement ' . MigrationInterface::class);
36
            }
37
        } catch (\Exception $e) {
38
            throw new RuntimeException('Migration instantiate error: ' . $class, 0, $e);
39
        }
40
        return $migration;
41
    }
42
}
43