Passed
Push — master ( 2a39ec...3b6c56 )
by Andrea
03:42
created

Fifree2droptablesCommand   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 38.71%

Importance

Changes 0
Metric Value
wmc 9
eloc 30
dl 0
loc 51
ccs 12
cts 31
cp 0.3871
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
B execute() 0 39 8
1
<?php
2
3
namespace Fi\CoreBundle\Command;
4
5
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6
use Symfony\Component\Console\Input\InputInterface;
7
use Symfony\Component\Console\Input\InputOption;
8
use Symfony\Component\Console\Output\OutputInterface;
9
10
class Fifree2droptablesCommand extends ContainerAwareCommand
11
{
12
13 6
    protected function configure()
14
    {
15
        $this
16 6
                ->setName('fifree2:droptables')
17 6
                ->setDescription('Eliminazione di tutte le tabelle fifree2')
18 6
                ->setHelp('ATTENZIONE, questo comando cancellerà tutte le informazioni presenti nel database!!')
19 6
                ->addOption('force', null, InputOption::VALUE_NONE, 'Se non impostato, il comando non avrà effetto');
20 6
    }
21
22 1
    protected function execute(InputInterface $input, OutputInterface $output)
23
    {
24
        /* @var $em \Doctrine\ORM\EntityManager */
25 1
        $em = $this->getContainer()->get('doctrine')->getManager();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
26 1
        $driver = $em->getConnection()->getDriver()->getName();
27
28 1
        if ($driver == "pdo_sqlite") {
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal pdo_sqlite does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
29 1
            $output->writeln("Non previsto per driver: " . $driver);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Non previsto per driver: does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
30 1
            return 1;
31
        }
32
33
        $force = $input->getOption('force');
34
35
        if (!$force) {
36
            $output->writeln("Specificare l'opzione --force per eseguire il comando");
37
            return 1;
38
        }
39
        $addcascade = "";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
40
        if ($driver == "pdo_pgsql") {
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal pdo_pgsql does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
41
            $addcascade = " CASCADE";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal CASCADE does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
42
        }
43
44
        //Truncate tabelle
45
        $tables = $em->getConnection()->getSchemaManager()->listTables();
46
        foreach ($tables as $table) {
47
            $tableName = $table->getName();
48
            $em->getConnection()->executeQuery(sprintf('TRUNCATE TABLE %s' . $addcascade, $tableName));
49
        }
50
        //Cancellazione tabelle
51
        foreach ($tables as $table) {
0 ignored issues
show
Comprehensibility Bug introduced by
$table is overwriting a variable from outer foreach loop.
Loading history...
52
            $tableName = $table->getName();
53
            $em->getConnection()->executeQuery(sprintf('DROP TABLE %s' . $addcascade, $tableName));
54
        }
55
        if ($driver == "pdo_pgsql") {
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal pdo_pgsql does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
56
            //Cancellazione sequences
57
            $sequences = $em->getConnection()->getSchemaManager()->listSequences();
58
            foreach ($sequences as $sequence) {
59
                $sequenceName = $sequence->getName();
60
                $em->getConnection()->executeQuery(sprintf('DROP SEQUENCE %s', $sequenceName));
61
            }
62
        }
63
    }
64
}
65