Skip to content
This repository was archived by the owner on Oct 19, 2020. It is now read-only.

Commit 15b98af

Browse files
committed
Fixed namespace
1 parent 6f9f822 commit 15b98af

File tree

22 files changed

+1490
-10
lines changed

22 files changed

+1490
-10
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/**
4+
* Composer Plugin QA
5+
*
6+
* @author Webysther Nunes <webysther@gmail.com>
7+
*/
8+
9+
namespace Webs\QA\Command\CodeBeautifierFixer;
10+
11+
/**
12+
* Alias for qa:code-beautifier-fixer
13+
*/
14+
class CBF extends CodeBeautifierFixer
15+
{
16+
/**
17+
* Console params configuration
18+
*
19+
* @return void
20+
*/
21+
protected function configure()
22+
{
23+
parent::configure();
24+
$this->setName('qa:cbf');
25+
}
26+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<?php
2+
3+
/**
4+
* Composer Plugin QA
5+
*
6+
* @author Webysther Nunes <webysther@gmail.com>
7+
*/
8+
9+
namespace Webs\QA\Command\CodeBeautifierFixer;
10+
11+
use Composer\Command\BaseCommand;
12+
use Symfony\Component\Console\Input\InputArgument;
13+
use Symfony\Component\Console\Input\InputInterface;
14+
use Symfony\Component\Console\Input\InputOption;
15+
use Symfony\Component\Console\Output\OutputInterface;
16+
use Symfony\Component\Console\Style\SymfonyStyle;
17+
use Symfony\Component\Process\Process;
18+
use Webs\QA\Command\Util;
19+
20+
/**
21+
* Code Beautifier and Fixer Wrapper
22+
*/
23+
class CodeBeautifierFixer extends BaseCommand
24+
{
25+
/**
26+
* Console description
27+
*
28+
* @var string
29+
*/
30+
protected $description = 'Code Beautifier and Fixer';
31+
32+
/**
33+
* Console params configuration
34+
*
35+
* @return void
36+
*/
37+
protected function configure()
38+
{
39+
// Alias is composer qa:cbf
40+
$this->setName('qa:code-beautifier-fixer')
41+
->setDescription($this->description)
42+
->addArgument(
43+
'source',
44+
InputArgument::IS_ARRAY | InputArgument::OPTIONAL,
45+
'List of directories/files to search <comment>[Default:"src,app,tests"]</>'
46+
)
47+
->addOption(
48+
'standard',
49+
null,
50+
InputOption::VALUE_REQUIRED,
51+
'List of standards',
52+
'PSR1,PSR2'
53+
)
54+
->addOption(
55+
'diff',
56+
null,
57+
InputOption::VALUE_NONE,
58+
'Use `git status -s` to search files to check'
59+
);
60+
}
61+
62+
/**
63+
* Execution
64+
*
65+
* @param InputInterface $input Input console
66+
* @param OutputInterface $output Output console
67+
* @return integer Exit code
68+
*/
69+
protected function execute(InputInterface $input, OutputInterface $output)
70+
{
71+
$start = microtime(true);
72+
$style = new SymfonyStyle($input, $output);
73+
$style->title($this->description);
74+
75+
$util = new Util();
76+
$cbf = $util->checkBinary('phpcbf');
77+
$output->writeln($util->checkVersion($cbf));
78+
$source = $util->checkSource($input);
79+
if ($input->getOption('diff')) {
80+
$source = $util->getDiffSource();
81+
}
82+
83+
if (empty($source)) {
84+
$output->writeln('<error>No files found</>');
85+
$style->newLine();
86+
87+
return 1;
88+
}
89+
90+
$cmd = $cbf.' --standard='.$input->getOption('standard').' '.$source;
91+
$output->writeln('<info>Command: '.$cmd.'</>');
92+
$style->newLine();
93+
$process = new Process($cmd);
94+
$exitCode = $process->setTimeout(3600)->run();
95+
96+
$changes = true;
97+
if (strpos($process->getOutput(), 'No fixable errors were found') !== false) {
98+
$changes = false;
99+
$output->writeln('<info>No changes</>');
100+
$style->newLine();
101+
102+
return 0;
103+
}
104+
105+
$changed = $util->getDiffSource();
106+
if ($changes && !empty($changed)) {
107+
$output->writeln(str_replace(' ', PHP_EOL, $changed));
108+
$sources = explode(' ', $changed);
109+
$style->newLine();
110+
111+
foreach ($sources as $source) {
112+
$git = 'git -c color.ui=always';
113+
$options = '--compaction-heuristic -U0 --patch --minimal --patience';
114+
$process = new Process($git.' diff '.$options.' '.$source);
115+
$process->run();
116+
$output->writeln($process->getOutput());
117+
}
118+
}
119+
120+
$end = microtime(true);
121+
$time = round($end - $start);
122+
123+
$style->section('Results');
124+
$output->writeln('<info>Time: '.$time.' seconds</>');
125+
$style->newLine();
126+
127+
return $exitCode;
128+
}
129+
}

src/Command/CodeCoverage/CC.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/**
4+
* Composer Plugin QA
5+
*
6+
* @author Webysther Nunes <webysther@gmail.com>
7+
*/
8+
9+
namespace Webs\QA\Command\CodeCoverage;
10+
11+
/**
12+
* Alias for qa:code-coverage
13+
*/
14+
class CC extends CodeCoverage
15+
{
16+
/**
17+
* Console params configuration
18+
*
19+
* @return void
20+
*/
21+
protected function configure()
22+
{
23+
parent::configure();
24+
$this->setName('qa:cc');
25+
}
26+
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
<?php
2+
3+
/**
4+
* Composer Plugin QA
5+
*
6+
* @author Webysther Nunes <webysther@gmail.com>
7+
*/
8+
9+
namespace Webs\QA\Command\CodeCoverage;
10+
11+
use Composer\Command\BaseCommand;
12+
use Symfony\Component\Console\Input\InputArgument;
13+
use Symfony\Component\Console\Input\InputInterface;
14+
use Symfony\Component\Console\Input\InputOption;
15+
use Symfony\Component\Console\Output\OutputInterface;
16+
use Symfony\Component\Console\Style\SymfonyStyle;
17+
use Symfony\Component\Process\Process;
18+
use Webs\QA\Command\Util;
19+
20+
/**
21+
* Code Coverage Wrapper
22+
*/
23+
class CodeCoverage extends BaseCommand
24+
{
25+
/**
26+
* Console description
27+
*
28+
* @var string
29+
*/
30+
protected $description = 'Code Coverage';
31+
32+
/**
33+
* Console params configuration
34+
*
35+
* @return void
36+
*/
37+
protected function configure()
38+
{
39+
// Alias is composer qa:cc
40+
$this->setName('qa:code-coverage')
41+
->addArgument(
42+
'source',
43+
InputArgument::IS_ARRAY | InputArgument::OPTIONAL,
44+
'List of directories/files to search'
45+
)
46+
->addOption(
47+
'fail-coverage-less-than',
48+
null,
49+
InputOption::VALUE_REQUIRED,
50+
'Fail if covered lines is less than the value. Default:80%',
51+
80
52+
)
53+
->setDescription($this->description);
54+
}
55+
56+
/**
57+
* Execution
58+
*
59+
* @param InputInterface $input Input console
60+
* @param OutputInterface $output Output console
61+
* @return integer Exit code
62+
*/
63+
protected function execute(InputInterface $input, OutputInterface $output)
64+
{
65+
$start = microtime(true);
66+
$this->output = $output;
67+
$command = $this;
68+
$style = new SymfonyStyle($input, $output);
69+
$style->title($this->description);
70+
71+
$util = new Util();
72+
$paratest = $util->checkBinary('paratest');
73+
$output->writeln($util->checkVersion($paratest));
74+
75+
$source = '';
76+
if ($input->getArgument('source')) {
77+
$source = ' '.$util->checkSource($input);
78+
}
79+
80+
(new Process('rm -rf coverage'))->run();
81+
mkdir('coverage');
82+
83+
$cmd = $paratest.$source.' --colors --coverage-php=coverage/result.cov';
84+
$output->writeln('<info>Command: '.$cmd.'</>');
85+
$process = new Process($cmd);
86+
$process->setTimeout(3600);
87+
$process->run(function ($type, $buffer) use ($command) {
88+
$command->output->write($buffer);
89+
});
90+
$exitCode = $process->getExitCode();
91+
92+
if ($exitCode) {
93+
return $exitCode;
94+
}
95+
96+
$cov = $util->checkBinary('phpcov');
97+
$cmd = $cov.' merge --text --show-colors coverage';
98+
$output->writeln('<info>Command: '.$cmd.'</>');
99+
$style->newLine();
100+
$process = new Process($cmd);
101+
$process->run(function ($type, $buffer) use ($command) {
102+
$command->output->write($buffer);
103+
});
104+
105+
$cmd = $cov.' merge --text coverage';
106+
$process = new Process($cmd);
107+
$process->run();
108+
preg_match(
109+
'/^\s*Lines:\s*(\d+.\d+)\%/m',
110+
$process->getOutput(),
111+
$matches
112+
);
113+
$coverage = end($matches);
114+
115+
(new Process('rm -rf coverage'))->run();
116+
117+
$end = microtime(true);
118+
$time = round($end - $start);
119+
120+
$style->newLine();
121+
$style->section('Results');
122+
123+
if (empty($coverage)) {
124+
$exitCode = 1;
125+
}
126+
127+
if (!empty($coverage)) {
128+
$output->writeln('Coverage is '.$coverage.'%');
129+
$fail = $input->getOption('fail-coverage-less-than');
130+
if ($fail && $coverage < $fail) {
131+
$output->writeln('<error>Mininum coverage is '.$fail.'% actual is '.$coverage.'%</>');
132+
$exitCode = 1;
133+
}
134+
}
135+
136+
$style->newLine();
137+
$output->writeln('<info>Command: '.$cmd.'</>');
138+
$output->writeln('<info>Time: '.$time.' seconds</>');
139+
$style->newLine();
140+
141+
return $exitCode;
142+
}
143+
}

src/Command/CodeSniffer/CS.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/**
4+
* Composer Plugin QA
5+
*
6+
* @author Webysther Nunes <webysther@gmail.com>
7+
*/
8+
9+
namespace Webs\QA\Command\CodeSniffer;
10+
11+
/**
12+
* Alias for qa:code-sniffer
13+
*/
14+
class CS extends CodeSniffer
15+
{
16+
/**
17+
* Console params configuration
18+
*
19+
* @return void
20+
*/
21+
protected function configure()
22+
{
23+
parent::configure();
24+
$this->setName('qa:cs');
25+
}
26+
}

0 commit comments

Comments
 (0)