DoctrineFixtureRunCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 36
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
A getFixtures() 0 3 1
A execute() 0 14 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
}