Passed
Push — master ( d0855e...e9dbe1 )
by Andrea
03:56
created

GenerateentitiesCommand::execute()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 32
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 32
ccs 0
cts 15
cp 0
rs 9.7666
c 0
b 0
f 0
cc 4
nc 8
nop 2
crap 20
1
<?php
2
3
namespace Fi\PannelloAmministrazioneBundle\Command;
4
5
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Fi\OsBundle\DependencyInjection\OsFunctions;
11
12
class GenerateentitiesCommand extends ContainerAwareCommand
13
{
14
15
    protected $apppaths;
16
    protected $genhelper;
17
    protected $pammutils;
18
19 6
    protected function configure()
20
    {
21
        $this
22 6
                ->setName('pannelloamministrazione:generateentities')
23 6
                ->setDescription('Genera le entities partendo da un modello workbeanch mwb')
24 6
                ->setHelp('Genera le entities partendo da un modello workbeanch mwb, <br/>fifree.mwb Fi/CoreBundle default [--schemaupdate]<br/>')
25 6
                ->addArgument('em', InputArgument::OPTIONAL, 'Entity manager, default = default')
26 6
                ->addOption('schemaupdate', null, InputOption::VALUE_NONE, 'Se settato fa anche lo schema update sul db');
27 6
    }
28
    protected function execute(InputInterface $input, OutputInterface $output)
29
    {
30
        set_time_limit(0);
31
        $this->apppaths = $this->getContainer()->get("pannelloamministrazione.projectpath");
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 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...
Coding Style Comprehensibility introduced by
The string literal pannelloamministrazione.projectpath 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...
32
        $this->genhelper = $this->getContainer()->get("pannelloamministrazione.generatorhelper");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal pannelloamministrazione.generatorhelper 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...
33
        $this->pammutils = $this->getContainer()->get("pannelloamministrazione.utils");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal pannelloamministrazione.utils 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...
34
35
        $schemaupdate = false;
36
37
        if (!$input->getArgument('em')) {
38
            $emdest = 'default';
39
        } else {
40
            $emdest = $input->getArgument('em');
41
        }
42
43
        if ($input->getOption('schemaupdate')) {
44
            $schemaupdate = true;
45
        }
46
47
        /* $generateentitiesresult = $this->pammutils->clearCache();
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% 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...
48
          if ($generateentitiesresult["errcode"] < 0) {
49
          $output->writeln($generateentitiesresult["errmsg"]);
50
          return 1;
51
          } else {
52
          $output->writeln($generateentitiesresult["errmsg"]);
53
          } */
54
        $generatecheck = $this->generateentities($emdest, $schemaupdate, $output);
55
        if ($generatecheck < 0) {
56
            return 1;
57
        }
58
59
        return 0;
60
    }
61
    private function generateentities($emdest, $schemaupdate, $output)
62
    {
63
        /* GENERATE ENTITIES */
64
        $output->writeln('Creazione entities class');
65
66
        $console = $this->apppaths->getConsole();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 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...
67
        $scriptGenerator = $console . ' make:entity';
68
        $phpPath = OsFunctions::getPHPExecutableFromPath();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 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...
69
70
        $command = $phpPath . ' ' . $scriptGenerator . ' --regenerate App';
71
        
72
        $generateentitiesresult = $this->pammutils->runCommand($command);
73
        if ($generateentitiesresult["errcode"] < 0) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal errcode 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...
74
            $output->writeln($generateentitiesresult["errmsg"]);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal errmsg 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...
75
            return 1;
76
        } else {
77
            $output->writeln($generateentitiesresult["errmsg"]);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal errmsg 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...
78
        }
79
80
        $output->writeln('<info>Entities class create</info>');
81
82
        if ($schemaupdate) {
83
            $output->writeln('Aggiornamento database...');
84
85
            $scriptGenerator = $console . ' doctrine:schema:update';
86
87
            $phpPath = OsFunctions::getPHPExecutableFromPath();
88
            $command = $phpPath . ' ' . $scriptGenerator . ' --force --em=' . $emdest
89
                    . ' --no-debug --env=' . $this->getContainer()->get('kernel')->getEnvironment();
90
91
            $schemaupdateresult = $this->pammutils->runCommand($command);
92
            if ($schemaupdateresult["errcode"] < 0) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal errcode 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...
93
                $output->writeln($schemaupdateresult["errmsg"]);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal errmsg 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...
94
            } else {
95
                $output->writeln($schemaupdateresult["errmsg"]);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal errmsg 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...
96
                $output->writeln('<info>Aggiornamento database completato</info>');
97
            }
98
            return $schemaupdateresult["errcode"];
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal errcode 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...
99
        }
100
    }
101
}
102