1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cdf\PannelloAmministrazioneBundle\Command; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Console\Command\Command; |
6
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
7
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
8
|
|
|
use Symfony\Component\Process\Process; |
9
|
|
|
use Cdf\PannelloAmministrazioneBundle\DependencyInjection\ProjectPath; |
10
|
|
|
|
11
|
|
|
class ChecksrcCommand extends Command |
12
|
|
|
{ |
13
|
|
|
|
14
|
3 |
|
protected function configure() |
15
|
|
|
{ |
16
|
|
|
$this |
17
|
3 |
|
->setName('pannelloamministrazione:checksrc') |
18
|
3 |
|
->setDescription('Controlla i sorgenti') |
19
|
3 |
|
->setHelp('Usa phpcs, phpmd, ecc per controllare il codice in src'); |
20
|
3 |
|
} |
21
|
|
|
|
22
|
|
|
// @codeCoverageIgnoreStart |
23
|
|
|
public function __construct(ProjectPath $projectpath) |
24
|
|
|
{ |
25
|
|
|
$this->apppaths = $projectpath; |
|
|
|
|
26
|
|
|
|
27
|
|
|
// you *must* call the parent constructor |
28
|
|
|
parent::__construct(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
32
|
|
|
{ |
33
|
|
|
$prjpath = $this->apppaths; |
|
|
|
|
34
|
|
|
$vendorBin = $prjpath->getVendorBinPath() . "/"; |
|
|
|
|
35
|
|
|
$srcPath = $prjpath->getSrcPath(); |
|
|
|
|
36
|
|
|
$rootPath = $prjpath->getRootPath(); |
|
|
|
|
37
|
|
|
|
38
|
|
|
/* phpcpd */ |
39
|
|
|
$phpcpdcmd = array($vendorBin . "phpcpd", $srcPath); |
|
|
|
|
40
|
|
|
$phpcpdoutput = $this->runcmd($phpcpdcmd); |
41
|
|
|
if (!$phpcpdoutput) { |
42
|
|
|
$output->writeln("phpmd: OK"); |
|
|
|
|
43
|
|
|
} else { |
44
|
|
|
if (strpos($phpcpdoutput, "0.00%")) { |
|
|
|
|
45
|
|
|
$output->writeln("phpmd: OK"); |
|
|
|
|
46
|
|
|
} else { |
47
|
|
|
$output->writeln($phpcpdoutput); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
/* phpcpd */ |
51
|
|
|
|
52
|
|
|
/* phpcs */ |
53
|
|
|
$phpcscmd = array($vendorBin . "phpcs", "--standard=" . $rootPath. "/../tools/phpcs/ruleset.xml", "--extensions=php", $srcPath); |
|
|
|
|
54
|
|
|
$phpcsoutput = $this->runcmd($phpcscmd); |
55
|
|
|
if (!$phpcsoutput) { |
56
|
|
|
$output->writeln("phpcs: OK"); |
|
|
|
|
57
|
|
|
} else { |
58
|
|
|
$output->writeln($phpcsoutput); |
59
|
|
|
$output->writeln("Per correggere automaticamente un file eseguire:"); |
|
|
|
|
60
|
|
|
$output->writeln($vendorBin . "phpcbf --standard=PSR2 nomefile.php"); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
/* phpcs */ |
63
|
|
|
|
64
|
|
|
/* phpmd */ |
65
|
|
|
$phpmdcmd = array($vendorBin . "phpmd", $srcPath , "text", $rootPath . "/../tools/phpmd/ruleset.xml"); |
|
|
|
|
66
|
|
|
$phpmdoutput = $this->runcmd($phpmdcmd); |
67
|
|
|
if (!$phpmdoutput) { |
68
|
|
|
$output->writeln("phpmd: OK"); |
|
|
|
|
69
|
|
|
} else { |
70
|
|
|
$output->writeln($phpmdoutput); |
71
|
|
|
} |
72
|
|
|
/* phpmd */ |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
private function runcmd(Array $cmd) |
76
|
|
|
{ |
77
|
|
|
$process = new Process($cmd); |
78
|
|
|
$process->setTimeout(60 * 100); |
79
|
|
|
$process->run(); |
80
|
|
|
if ($process->isSuccessful()) { |
81
|
|
|
$out = $process->getOutput(); |
82
|
|
|
} else { |
83
|
|
|
$out = ($process->getErrorOutput() ? $process->getErrorOutput() : $process->getOutput()); |
84
|
|
|
} |
85
|
|
|
return $out; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
// @codeCoverageIgnoreEnd |
89
|
|
|
} |
90
|
|
|
|