Passed
Push — master ( e5181e...c911bb )
by Andrea
04:13
created

PannelloAmministrazioneUtils   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 91.67%

Importance

Changes 0
Metric Value
wmc 8
eloc 36
dl 0
loc 68
ccs 33
cts 36
cp 0.9167
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A runSymfonyCommand() 0 13 2
A runCommand() 0 19 2
A clearcache() 0 20 3
1
<?php
2
3
namespace Fi\PannelloAmministrazioneBundle\DependencyInjection;
4
5
use Symfony\Bundle\FrameworkBundle\Console\Application;
6
use Symfony\Component\Console\Output\BufferedOutput;
7
use Symfony\Component\Console\Input\ArrayInput;
8
use Symfony\Component\Process\Process;
9
use Fi\PannelloAmministrazioneBundle\DependencyInjection\ProjectPath;
10
use Fi\OsBundle\DependencyInjection\OsFunctions;
11
12
class PannelloAmministrazioneUtils
13
{
14
15
    private $container;
16
    private $apppaths;
17
18 4
    public function __construct($container)
19
    {
20 4
        $this->container = $container;
21 4
        $this->apppaths = $container->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...
22 4
    }
23
24 2
    public function clearcache($env = "")
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 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...
25
    {
26 2
        if (!$env) {
27 1
            $env = $this->container->get('kernel')->getEnvironment();
28
        }
29
30 2
        $phpPath = OsFunctions::getPHPExecutableFromPath();
31
32 2
        if (in_array($env, array('dev', 'test', 'localhost'))) {
33 2
            $command = $phpPath . ' ' . $this->apppaths->getConsole() . ' cache:clear '
34 2
                    . '--no-warmup --env=' . $env;
35
        } else {
36 1
            $command = $phpPath . ' ' . $this->apppaths->getConsole() . ' cache:clear '
37 1
                    . '--no-debug --no-warmup --env=' . $env;
38
39 1
            $command = $command . " && " . $phpPath . ' ' . $this->apppaths->getConsole() . ' cache:warmup '
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal && 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
                    . '--no-debug --env=' . $env;
41
        }
42
43 2
        return self::runCommand($command);
44
    }
45
46 3
    public static function runCommand($command)
47
    {
48
        /* @var $process \Symfony\Component\Process\Process */
49 3
        $process = new Process($command);
50 3
        $process->setTimeout(60 * 60 * 24);
51 3
        $process->run();
52
53 3
        if (!$process->isSuccessful()) {
54
            $return = array("errcode" => -1,
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...
55
                "command" => $command,
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal command 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...
56
                "errmsg" => 'Errore nel comando ' . $command . $process->getErrorOutput() . $process->getOutput());
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...
57
        } else {
58 3
            $return = array("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...
59 3
                "command" => $command,
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal command 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 3
                "errmsg" => $process->getOutput()
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...
61
            );
62
        }
63
64 3
        return $return;
65
    }
66
67 1
    public function runSymfonyCommand($command, array $options = array())
68
    {
69 1
        $application = new Application($this->container->get('kernel'));
70 1
        $application->setAutoExit(false);
71
72 1
        $cmdoptions = array_merge(array('command' => $command), $options);
73
74 1
        $outputbuf = new BufferedOutput();
75
        // return the output, don't use if you used NullOutput()
76 1
        $returncode = $application->run(new ArrayInput($cmdoptions), $outputbuf);
77 1
        $output = $outputbuf->fetch();
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...
78
79 1
        return array('errcode' => ($returncode == 0 ? 0 : 1), 'command' => $cmdoptions['command'], 'message' => $output);
80
    }
81
}
82