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

Utility::clearcache()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 10
ccs 5
cts 6
cp 0.8333
crap 2.0185
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Cdf\PannelloAmministrazioneBundle\Utils;
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
10
class Utility
11
{
12
    private $apppaths;
13
    private $kernel;
14
15 1
    public function __construct($kernel, ProjectPath $projectpath)
16
    {
17 1
        $this->apppaths = $projectpath;
18 1
        $this->kernel = $kernel;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 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...
19 1
    }
20
21 1
    public function clearcache($env = '')
22
    {
23 1
        if (!$env) {
24
            $env = $this->kernel->getEnvironment();
25
        }
26
27 1
        $command = $this->apppaths->getConsole();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 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...
28 1
        $parametri = array('cache:clear', '--env='.$env);
29
30 1
        return self::runCommand($command, $parametri);
31
    }
32
33 1
    public static function runCommand($command, $workingdir = '')
34
    {
35
        /* @var $process \Symfony\Component\Process\Process */
36 1
        if (version_compare(\Symfony\Component\HttpKernel\Kernel::VERSION, '4.2.0') >= 0) {
37 1
            $process = Process::fromShellCommandline($command);
0 ignored issues
show
Bug introduced by
The method fromShellCommandline() does not exist on Symfony\Component\Process\Process. ( Ignorable by Annotation )

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

37
            /** @scrutinizer ignore-call */ 
38
            $process = Process::fromShellCommandline($command);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
        } else {
39
            $process = new Process($command, $workingdir);
40
        }
41
42 1
        if ($workingdir) {
43 1
            $process->setWorkingDirectory($workingdir);
44
        }
45 1
        $process->setTimeout(60 * 60 * 24);
46 1
        $process->run();
47
48 1
        if (!$process->isSuccessful()) {
49 1
            $return = array('errcode' => -1,
50 1
                'command' => $command,
51 1
                'message' => 'Errore nel comando '.$command."\n".$process->getErrorOutput()."\n".$process->getOutput(), );
52
        } else {
53 1
            $return = array('errcode' => 0,
54 1
                'command' => $command,
55 1
                'message' => $process->getOutput(),
56
            );
57
        }
58
59 1
        return $return;
60
    }
61
62 1
    public function runSymfonyCommand($command, array $options = array())
63
    {
64 1
        $application = new Application($this->kernel);
65 1
        $application->setAutoExit(false);
66
67 1
        $cmdoptions = array_merge(array('command' => $command), $options);
68
69 1
        $outputbuf = new BufferedOutput();
70
        // return the output, don't use if you used NullOutput()
71 1
        $returncode = $application->run(new ArrayInput($cmdoptions), $outputbuf);
72 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...
73
74 1
        return array('errcode' => (0 == $returncode ? 0 : 1), 'command' => $cmdoptions['command'], 'message' => $output);
75
    }
76
}
77