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

GenerateymlentitiesCommand   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 7
eloc 51
dl 0
loc 79
ccs 40
cts 48
cp 0.8333
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
A getExportJsonCommand() 0 25 2
A execute() 0 37 4
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\Output\OutputInterface;
9
use Fi\OsBundle\DependencyInjection\OsFunctions;
10
11
class GenerateymlentitiesCommand extends ContainerAwareCommand
12
{
13
14
    protected $apppaths;
15
    protected $genhelper;
16
    protected $pammutils;
17
18 6
    protected function configure()
19
    {
20
        $this
21 6
                ->setName('pannelloamministrazione:generateymlentities')
22 6
                ->setDescription('Genera le entities partendo da un modello workbeanch mwb')
23 6
                ->setHelp('Genera i ifle yml per le entities partendo da un modello workbeanch mwb, <br/>fifree.mwb Fi/CoreBundle default<br/>')
24 6
                ->addArgument('mwbfile', InputArgument::REQUIRED, 'Nome file mwb, fifree.mwb')
25
        ;
26 6
    }
27 2
    protected function execute(InputInterface $input, OutputInterface $output)
28
    {
29 2
        set_time_limit(0);
30 2
        $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...
31 2
        $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...
32 2
        $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...
33 2
        $mwbfile = $input->getArgument('mwbfile');
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...
34
35 2
        $wbFile = $this->apppaths->getDocPath() . DIRECTORY_SEPARATOR . $mwbfile;
0 ignored issues
show
Bug introduced by
Are you sure $mwbfile of type null|string|string[] can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
        $wbFile = $this->apppaths->getDocPath() . DIRECTORY_SEPARATOR . /** @scrutinizer ignore-type */ $mwbfile;
Loading history...
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 12 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...
36 2
        $checkprerequisiti = $this->genhelper->checkprerequisiti($mwbfile, $output);
37
38 2
        if ($checkprerequisiti < 0) {
39
            return -1;
40
        }
41
42 2
        $destinationPath = $this->genhelper->getDestinationEntityYmlPath();
43
44 2
        $command = $this->getExportJsonCommand($wbFile);
45
        
46 2
        $schemaupdateresult = $this->pammutils->runCommand($command);
47 2
        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...
48
            $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...
49
            return 1;
50
        } else {
51 2
            $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...
52
        }
53
54 2
        $this->genhelper->removeExportJsonFile();
55
56 2
        $tablecheck = $this->genhelper->checktables($destinationPath, $wbFile, $output);
57
58 2
        if ($tablecheck < 0) {
59
            return 1;
60
        }
61
62 2
        $output->writeln('<info>Entities yml create</info>');
63 2
        return 0;
64
    }
65 2
    private function getExportJsonCommand($wbFile)
66
    {
67 2
        $exportJson = $this->genhelper->getExportJsonFile();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 13 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...
68 2
        $scriptGenerator = $this->genhelper->getScriptGenerator();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 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 2
        $destinationPathEscaped = realpath($this->genhelper->getDestinationEntityYmlPath());
70 2
        $exportjsonfile = $this->genhelper->getJsonMwbGenerator();
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...
71
        
72 2
        $exportjsonreplaced = str_replace('[dir]', $destinationPathEscaped, $exportjsonfile);
73
        
74 2
        file_put_contents($exportJson, $exportjsonreplaced);
75 2
        $sepchr = OsFunctions::getSeparator();
76 2
        if (OsFunctions::isWindows()) {
77
            $command = 'cd ' . $this->apppaths->getRootPath() . $sepchr
78
                    . $scriptGenerator . '.bat '
79
                    . ' --config=' .
80
                    $exportJson . ' ' . $wbFile . ' ' . $destinationPathEscaped;
81
        } else {
82 2
            $phpPath = OsFunctions::getPHPExecutableFromPath();
83 2
            $command = 'cd ' . $this->apppaths->getRootPath() . $sepchr
84 2
                    . $phpPath . ' ' . $scriptGenerator . ' '
85 2
                    . ' --config=' .
86 2
                    $exportJson . ' ' . $wbFile . ' ' . $destinationPathEscaped;
87
        }
88
89 2
        return $command;
90
    }
91
}
92