Completed
Pull Request — develop (#189)
by Serhii
04:07 queued 02:03
created

MigrationFactory::createVersion()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace App\Doctrine;
4
5
use Doctrine\DBAL\Connection;
6
use Doctrine\Migrations\AbstractMigration;
7
use Doctrine\ORM\EntityManagerInterface;
8
use Psr\Log\LoggerInterface;
9
10
class MigrationFactory implements \Doctrine\Migrations\Version\MigrationFactory
11
{
12
    /** @var Connection */
13
    private $connection;
14
15
    /** @var LoggerInterface */
16
    private $logger;
17
18
    /**
19
     * @var EntityManagerInterface
20
     */
21
    private $em;
22
23
    public function __construct(Connection $connection, LoggerInterface $logger, EntityManagerInterface $em)
24
    {
25
        $this->connection = $connection;
26
        $this->logger     = $logger;
27
        $this->em = $em;
28
    }
29
30
    public function createVersion(string $migrationClassName) : AbstractMigration
31
    {
32
        $migration = new $migrationClassName(
33
            $this->connection,
34
            $this->logger
35
        );
36
37
        // or you can ommit this check
38
        if ($migration instanceof EntityManagerAwareInterface) {
39
            $migration->setEntityManager($this->em);
40
        }
41
42
        return $migration;
43
    }
44
}
45