FixturesLoadCommand::fire()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 0
1
<?php namespace Nord\Lumen\Doctrine\ORM\Console;
2
3
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
4
use Doctrine\Common\DataFixtures\Loader;
5
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
6
use Symfony\Component\Console\Input\InputOption;
7
8
class FixturesLoadCommand extends DoctrineCommand
9
{
10
11
    /**
12
     * @var string
13
     */
14
    protected $name = 'doctrine:fixtures:load';
15
16
    /**
17
     * @var string
18
     */
19
    protected $description = 'Loads data fixtures into the database';
20
21
22
    /**
23
     * @inheritdoc
24
     */
25
    public function fire()
26
    {
27
        $loader = new Loader();
28
29
        $this->info('Loading fixtures ...');
30
31
        $loader->loadFromDirectory($this->option('path'));
32
33
        $fixtures = $loader->getFixtures();
34
35
        $purger   = new ORMPurger();
36
        $executor = new ORMExecutor($this->getEntityManager(), $purger);
37
        $executor->execute($fixtures, $this->option('append'));
38
39
        $this->info('Fixtures loaded!');
40
    }
41
42
43
    /**
44
     * @return array
45
     */
46
    protected function getOptions()
47
    {
48
        return [
49
            ['path', null, InputOption::VALUE_REQUIRED, 'Path to fixtures.'],
50
            ['append', true, InputOption::VALUE_OPTIONAL, 'Whether to append fixtures and preserve the database.'],
51
        ];
52
    }
53
}
54