Passed
Push — master ( ead1f2...80923f )
by Andrea
15:57
created

GenerateOrmEntitiesCommand   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
eloc 43
dl 0
loc 75
ccs 36
cts 40
cp 0.9
rs 10
c 0
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 6 1
A __construct() 0 8 1
A execute() 0 49 5
1
<?php
2
3
namespace Cdf\PannelloAmministrazioneBundle\Command;
4
5
use Symfony\Component\Console\Command\Command;
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
use Cdf\PannelloAmministrazioneBundle\Utils\ProjectPath;
11
use Cdf\PannelloAmministrazioneBundle\Utils\GeneratorHelper;
12
use Cdf\PannelloAmministrazioneBundle\Utils\Utility;
13
14
class GenerateOrmEntitiesCommand extends Command
15
{
16
    protected static $defaultName = 'pannelloamministrazione:generateormentities';
17
    protected $apppaths;
18
    protected $genhelper;
19
    protected $pammutils;
20
21 1
    protected function configure()
22
    {
23
        $this
24 1
                ->setDescription('Genera le entities partendo da un modello workbeanch mwb')
25 1
                ->setHelp('Genera i file orm per le entities partendo da un modello workbeanch mwb, <br/>bi.mwb Fi/BiCoreBundle default<br/>')
26 1
                ->addArgument('mwbfile', InputArgument::REQUIRED, 'Nome file mwb, bi.mwb')
27
        ;
28 1
    }
29
30 1
    public function __construct(ProjectPath $projectpath, GeneratorHelper $genhelper, Utility $pammutils)
31
    {
32 1
        $this->apppaths = $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...
33 1
        $this->genhelper = $genhelper;
34 1
        $this->pammutils = $pammutils;
35
36
        // you *must* call the parent constructor
37 1
        parent::__construct();
38 1
    }
39
40 1
    protected function execute(InputInterface $input, OutputInterface $output)
41
    {
42 1
        set_time_limit(0);
43
44 1
        $mwbfile = $input->getArgument('mwbfile');
45
46 1
        $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

46
        $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...
47 1
        $checkprerequisiti = $this->genhelper->checkprerequisiti($mwbfile, $output);
48
49 1
        if ($checkprerequisiti < 0) {
50
            return -1;
51
        }
52
53 1
        $destinationPath = $this->genhelper->getDestinationEntityOrmPath();
54
55 1
        $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...
56 1
        $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...
57 1
        $destinationPathEscaped = $this->genhelper->getDestinationEntityOrmPath();
58 1
        $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...
59
60 1
        $exportjsonreplaced = str_replace('[dir]', $destinationPathEscaped, $exportjsonfile);
61
62 1
        file_put_contents($exportJson, $exportjsonreplaced);
63 1
        $workingdir = $this->apppaths->getRootPath();
64 1
        if (OsFunctions::isWindows()) {
65
            $command = $scriptGenerator.'.bat'.' --config='.$exportJson.' '.$wbFile.' '.$destinationPathEscaped;
66
        } else {
67 1
            $command = $scriptGenerator.' --config='.$exportJson.' '.$wbFile.' '.$destinationPathEscaped;
68
        }
69
70 1
        $schemaupdateresult = $this->pammutils->runCommand($command, $workingdir);
71 1
        if ($schemaupdateresult['errcode'] < 0) {
72
            $output->writeln($schemaupdateresult['message']);
73
74
            return 1;
75
        } else {
76 1
            $output->writeln($schemaupdateresult['message']);
77
        }
78
79 1
        $this->genhelper->removeExportJsonFile();
80 1
        $tablecheck = $this->genhelper->checktables($destinationPath, $wbFile, $output);
81
82 1
        if ($tablecheck < 0) {
83 1
            return 1;
84
        }
85
86 1
        $output->writeln('<info>Entities yml create</info>');
87
88 1
        return 0;
89
    }
90
}
91