AbstractMigrationRegistry   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getMigration() 0 11 4
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