Passed
Push — develop ( 11585d...bd8de4 )
by Andrea
35:10
created

BiCoreBundleDropdatabaseCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
dl 0
loc 45
ccs 21
cts 28
cp 0.75
rs 10
c 1
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 0 6 1
A execute() 0 26 3
1
<?php
2
3
namespace Cdf\BiCoreBundle\Command;
4
5
use Symfony\Component\Console\Command\Command;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Input\InputOption;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Symfony\Component\Console\Input\ArrayInput;
10
use Doctrine\Common\Persistence\ObjectManager;
11
12
class BiCoreBundleDropdatabaseCommand extends Command
13
{
14
15
    protected static $defaultName = 'bicorebundle:dropdatabase';
16
17 1
    public function __construct(ObjectManager $em)
18
    {
19 1
        $this->em = $em;
0 ignored issues
show
Bug Best Practice introduced by
The property em does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
20
21
        // you *must* call the parent constructor
22 1
        parent::__construct();
23 1
    }
24 1
    protected function configure()
25
    {
26
        $this
27 1
                ->setDescription('Cancellazione database bicorebundle')
28 1
                ->setHelp('Cancella il database e tutti i dati di bicorebundle')
29 1
                ->addOption('force', null, InputOption::VALUE_NONE, 'Se non impostato, il comando non avrà effetto');
30 1
    }
31 1
    protected function execute(InputInterface $input, OutputInterface $output)
32
    {
33 1
        $force = $input->getOption('force');
34
35 1
        if (!$force) {
36
            echo "Specificare l'opzione --force per eseguire il comando";
37
38
            return 1;
39
        }
40
41
        /* @var $em \Doctrine\ORM\EntityManager */
42 1
        $em = $this->em;
43 1
        $driver = $em->getConnection()->getDatabasePlatform()->getName();
44 1
        switch ($driver) {
45 1
            case 'sqlite':
46
                $command = $this->getApplication()->find('doctrine:database:drop');
47
                $arguments = array('command' => 'doctrine:database:drop', '--force' => true/*, '--if-exists' => true*/);
48
                $inputcmd = new ArrayInput($arguments);
49
                $command->run($inputcmd, $output);
50
                break;
51
            default:
52 1
                $command = $this->getApplication()->find('doctrine:schema:drop');
53 1
                $arguments = array('command' => 'doctrine:schema:drop', '--force' => true, '--full-database' => true);
54 1
                $inputcmd = new ArrayInput($arguments);
55 1
                $command->run($inputcmd, $output);
56 1
                break;
57
        }
58 1
    }
59
}
60