Completed
Push — develop ( d74711...190a84 )
by Neomerx
02:10
created

PassportMigration::getDatabaseScheme()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php namespace Limoncello\Passport\Package;
2
3
/**
4
 * Copyright 2015-2017 [email protected]
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
use Doctrine\DBAL\Connection;
20
use Limoncello\Contracts\Data\MigrationInterface;
21
use Limoncello\Passport\Contracts\Entities\DatabaseSchemaInterface;
22
use Limoncello\Passport\Traits\DatabaseSchemaMigrationTrait;
23
use Psr\Container\ContainerInterface;
24
25
/**
26
 * @package Limoncello\Passport
27
 */
28
class PassportMigration implements MigrationInterface
29
{
30
    use DatabaseSchemaMigrationTrait;
31
32
    /**
33
     * @var ContainerInterface
34
     */
35
    private $container;
36
37
    /**
38
     * @inheritdoc
39
     */
40 2
    public function init(ContainerInterface $container): MigrationInterface
41
    {
42 2
        $this->container = $container;
43
44 2
        return $this;
45
    }
46
47
    /**
48
     * @return void
49
     */
50 1
    public function migrate(): void
51
    {
52 1
        $this->createDatabaseSchema($this->getConnection(), $this->getDatabaseSchema());
53
    }
54
55
    /**
56
     * @return void
57
     */
58 1
    public function rollback(): void
59
    {
60 1
        $this->removeDatabaseSchema($this->getConnection(), $this->getDatabaseSchema());
61
    }
62
63
    /**
64
     * @return ContainerInterface
65
     */
66 2
    protected function getContainer(): ContainerInterface
67
    {
68 2
        assert($this->container !== null);
69
70 2
        return $this->container;
71
    }
72
73
    /**
74
     * @return Connection
75
     */
76 2
    protected function getConnection(): Connection
77
    {
78 2
        return $this->getContainer()->get(Connection::class);
79
    }
80
81
    /**
82
     * @return DatabaseSchemaInterface
83
     */
84 2
    protected function getDatabaseSchema(): DatabaseSchemaInterface
85
    {
86 2
        return $this->getContainer()->get(DatabaseSchemaInterface::class);
87
    }
88
}
89