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

MigrationService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace WebComplete\core\utils\migration;
4
5
class MigrationService
6
{
7
8
    /**
9
     * @var MigrationRegistryInterface
10
     */
11
    protected $registry;
12
13
    /**
14
     * MigrationService constructor.
15
     *
16
     * @param MigrationRegistryInterface $registry
17
     */
18
    public function __construct(MigrationRegistryInterface $registry)
19
    {
20
        $this->registry = $registry;
21
    }
22
23
    /**
24
     * @param array $classes
25
     *
26
     * @throws \Exception
27
     * @throws \Psr\Container\ContainerExceptionInterface
28
     * @throws \Psr\Container\NotFoundExceptionInterface
29
     */
30
    public function upAll(array $classes)
31
    {
32
        foreach ($classes as $class) {
33
            $this->up($class);
34
        }
35
    }
36
37
    /**
38
     * @throws \Exception
39
     * @throws \Psr\Container\ContainerExceptionInterface
40
     * @throws \Psr\Container\NotFoundExceptionInterface
41
     */
42
    public function downAll()
43
    {
44
        $classes = $this->registry->getRegistered();
45
        foreach ($classes as $class) {
46
            $this->down($class);
47
        }
48
    }
49
50
    /**
51
     * @param $class
52
     *
53
     * @throws \Exception
54
     * @throws \Psr\Container\ContainerExceptionInterface
55
     * @throws \Psr\Container\NotFoundExceptionInterface
56
     */
57
    public function up($class)
58
    {
59
        $this->registry->register($class);
60
    }
61
62
    /**
63
     * @param $class
64
     *
65
     * @throws \Exception
66
     * @throws \Psr\Container\ContainerExceptionInterface
67
     * @throws \Psr\Container\NotFoundExceptionInterface
68
     */
69
    public function down($class)
70
    {
71
        $this->registry->unregister($class);
72
    }
73
}
74