Completed
Push — master ( d750c1...767439 )
by Andrea
37:45 queued 33:43
created

Commands::clearcache()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 0
dl 0
loc 14
ccs 0
cts 10
cp 0
crap 12
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace Cdf\PannelloAmministrazioneBundle\Utils;
4
5
use Symfony\Component\Filesystem\Filesystem;
6
7
class Commands
8
{
9
    /* @var $apppaths \Cdf\PannelloAmministrazioneBundle\Utils\ProjectPath */
0 ignored issues
show
Documentation Bug introduced by
The doc comment $apppaths at position 0 could not be parsed: Unknown type name '$apppaths' at position 0 in $apppaths.
Loading history...
10
11
    private $apppaths;
12
    /* @var $pammutils \Cdf\PannelloAmministrazioneBundle\Utils\Utility */
0 ignored issues
show
Documentation Bug introduced by
The doc comment $pammutils at position 0 could not be parsed: Unknown type name '$pammutils' at position 0 in $pammutils.
Loading history...
13
    private $pammutils;
14
15 1
    public function __construct(ProjectPath $projectpath, Utility $pautils)
16
    {
17 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...
18 1
        $this->pammutils = $pautils;
19 1
    }
20
21
    // @codeCoverageIgnoreStart
22
    public function getVcs()
23
    {
24
        $fs = new Filesystem();
25
26
        $projectDir = $this->apppaths->getRootPath();
27
        if ($fs->exists($projectDir.DIRECTORY_SEPARATOR.'.svn')) {
28
            $command = 'svn update';
29
        }
30
        if ($fs->exists($projectDir.DIRECTORY_SEPARATOR.'.git')) {
31
            $command = 'git pull';
32
        }
33
        if (!$command) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $command does not seem to be defined for all execution paths leading up to this point.
Loading history...
34
            throw new \Exception('Vcs non trovato', 100);
35
        }
36
37
        return $this->pammutils->runCommand($command, $projectDir);
38
    }
39
40
    // @codeCoverageIgnoreEnd
41 1
    public function generateEntity($wbFile)
42
    {
43 1
        $command = 'pannelloamministrazione:generateormentities';
44 1
        $result = $this->pammutils->runSymfonyCommand($command, array('mwbfile' => $wbFile));
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...
45
46 1
        if (0 != $result['errcode']) {
47
            return array(
48 1
                'errcode' => -1,
49 1
                'command' => $command,
50 1
                'message' => 'Errore nel comando:'.$command.';'.$result['message'],
51
            );
52
        }
53
54
        return array(
55 1
            'errcode' => 0,
56 1
            'command' => $command,
57 1
            'message' => 'Eseguito comando:'.$command.';'.$result['message'], );
58
    }
59
60 1
    public function generateFormCrud($entityform, $generatemplate)
61
    {
62
        /* @var $fs \Symfony\Component\Filesystem\Filesystem */
63 1
        $resultchk = $this->checkFormCrud($entityform);
64
65 1
        if (0 !== $resultchk['errcode']) {
66
            return $resultchk;
67
        }
68 1
        $formcrudparms = array('entityform' => $entityform, '--generatemplate' => $generatemplate);
69
70 1
        $retmsggenerateform = $this->pammutils->runSymfonyCommand('pannelloamministrazione:generateformcrud', $formcrudparms);
71
72
        $retmsg = array(
73 1
            'errcode' => $retmsggenerateform['errcode'],
74 1
            'command' => $retmsggenerateform['command'],
75 1
            'message' => $retmsggenerateform['message'],
76
        );
77
78 1
        return $retmsg;
79
    }
80
81 1
    public function checkFormCrud($entityform)
82
    {
83
        /* @var $fs \Symfony\Component\Filesystem\Filesystem */
84 1
        $fs = new Filesystem();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 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...
85 1
        $srcPath = $this->apppaths->getSrcPath();
86 1
        $appPath = $srcPath;
87 1
        if (!is_writable($appPath)) {
88
            return array('errcode' => -1, 'message' => $appPath.' non scrivibile');
89
        }
90 1
        $formPath = $appPath.'/Form/'.$entityform.'Type.php';
91
92 1
        $entityPath = $appPath.'/Entity'.DIRECTORY_SEPARATOR.$entityform.'.php';
93
94 1
        if (!$fs->exists($entityPath)) {
95
            return array('errcode' => -1, 'message' => $entityPath.' entity non trovata');
96
        }
97
98 1
        if ($fs->exists($formPath)) {
99
            return array('errcode' => -1, 'message' => $formPath.' esistente');
100
        }
101
102 1
        $controllerPath = $appPath.'/Controller'.DIRECTORY_SEPARATOR.$entityform.'Controller.php';
103
104 1
        if ($fs->exists($controllerPath)) {
105
            return array('errcode' => -1, 'message' => $controllerPath.' esistente');
106
        }
107
108 1
        $viewPathSrc = $this->apppaths->getTemplatePath().DIRECTORY_SEPARATOR.$entityform;
109
110 1
        if ($fs->exists($viewPathSrc)) {
111
            return array('errcode' => -1, 'message' => $viewPathSrc.' esistente');
112
        }
113
114 1
        return array('errcode' => 0, 'message' => 'OK');
115
    }
116
117
    public function clearcache()
118
    {
119
        $cmdoutput = '';
120
        $envs = array('dev', 'test', 'prod');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 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...
121
        foreach ($envs as $env) {
122
            $result = $this->pammutils->clearcache($env);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 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...
123
            $cmdoutput = $cmdoutput.$result['message'];
124
            if (0 !== $result['errcode']) {
125
                return $result;
126
            }
127
            $result['message'] = $cmdoutput;
128
        }
129
130
        return $result;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $result seems to be defined by a foreach iteration on line 121. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
131
    }
132
133 1
    public function aggiornaSchemaDatabase()
134
    {
135 1
        $result = $this->pammutils->runSymfonyCommand('doctrine:schema:update', array('--force' => true));
136
137 1
        return $result;
138
    }
139
}
140