DoctrineFixtureRunCommand::execute()   A
last analyzed

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 2
1
<?php
2
3
namespace BWC\Share\Symfony\Command;
4
5
6
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Doctrine\Common\DataFixtures\Loader;
11
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
12
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
13
14
15
abstract class DoctrineFixtureRunCommand extends ContainerAwareCommand
16
{
17
    protected function configure() {
18
        $this
19
            ->setName('bwc:doctrine:fixture:run')
20
            ->setDescription('Runs specified fixture')
21
            ->addArgument('fixtures', InputArgument::IS_ARRAY)
22
        ;
23
    }
24
25
    /**
26
     * @param InputInterface $input
27
     * @return string[]
28
     */
29
    private function getFixtures(InputInterface $input) {
30
        return $input->getArgument('fixtures');
31
    }
32
33
34
    protected function execute(InputInterface $input, OutputInterface $output) {
35
        $fixtures = $this->getFixtures($input);
36
37
        $loader = new Loader();
38
        foreach ($fixtures as $fixture) {
39
            $loader->addFixture(new $fixture());
40
        }
41
42
        $purger = new ORMPurger();
43
        /** @var $em \Doctrine\ORM\EntityManager */
44
        $em = $this->getContainer()->get('doctrine.orm.entity_manager');
45
        $executor = new ORMExecutor($em, $purger);
46
        $executor->execute($loader->getFixtures());
47
    }
48
49
50
}