Completed
Push — 5.0 ( e2d752...1ddd5c )
by Andrea
13:22
created

Fifree2droptablesCommand   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 7
eloc 32
dl 0
loc 50
ccs 24
cts 32
cp 0.75
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B execute() 0 40 6
A configure() 0 7 1
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 3
    protected function configure()
13
    {
14
        $this
15 3
                ->setName('fifree2:droptables')
16 3
                ->setDescription('Eliminazione di tutte le tabelle fifree2')
17 3
                ->setHelp('ATTENZIONE, questo comando cancellerà tutte le informazioni presenti nel database!!')
18 3
                ->addOption('force', null, InputOption::VALUE_NONE, 'Se non impostato, il comando non avrà effetto');
19 3
    }
20 1
    protected function execute(InputInterface $input, OutputInterface $output)
21
    {
22
        /* @var $em \Doctrine\ORM\EntityManager */
23 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...
24 1
        $driver = $em->getConnection()->getDatabasePlatform()->getName();
25
26 1
        $force = $input->getOption('force');
27
28 1
        if (!$force) {
29
            $output->writeln("Specificare l'opzione --force per eseguire il comando");
30
            return 1;
31
        }
32
33
        //Truncate tabelle
34 1
        $tables = $em->getConnection()->getSchemaManager()->listTables();
35
        //Cancellazione tabelle
36 1
        foreach ($tables as $table) {
37 1
            $tableName = $table->getName();
38 1
            switch ($driver) {
39 1
                case "postgresql":
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal postgresql 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 1
                    $em->getConnection()->executeQuery(sprintf('DROP TABLE %s CASCADE', $tableName));
41 1
                    $sequences = $em->getConnection()->getSchemaManager()->listSequences();
42 1
                    foreach ($sequences as $sequence) {
43 1
                        $sequenceName = $sequence->getName();
44 1
                        $em->getConnection()->executeQuery(sprintf('DROP SEQUENCE %s', $sequenceName));
45
                    }
46 1
                    break;
47
                case "mysql":
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal mysql 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...
48
                    $em->getConnection()->executeQuery('SET FOREIGN_KEY_CHECKS=0');
49
                    $em->getConnection()->executeQuery(sprintf('DROP TABLE %s', $tableName));
50
                    $em->getConnection()->executeQuery('SET FOREIGN_KEY_CHECKS=1');
51
                    break;
52
                default:
53
                    //$em->getConnection()->executeQuery(sprintf('DELETE FROM %s', $tableName));
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
54
                    $em->getConnection()->executeQuery(sprintf('DROP TABLE %s', $tableName));
55 1
                    break;
56
            }
57
        }
58
59 1
        $output->writeln("Done!");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Done! 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...
60 1
    }
61
}
62