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

Commit a7accb0

Browse files
committed
Wrapers
1 parent 80f8ad3 commit a7accb0

22 files changed

+1035
-11
lines changed

README.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,34 @@
66

77
# Composer Plugin for QA
88

9-
[Plugin for composer](https://getcomposer.org/doc/articles/plugins.md#creating-a-plugin)
10-
to execute [PHP QA Tools](http://phpqatools.org).
9+
Comprehensive [plugin for composer](https://getcomposer.org/doc/articles/plugins.md#creating-a-plugin)
10+
to execute [PHP QA Tools](http://phpqatools.org) in a uniform and simple way.
1111

1212
For others plugins for composer [see](https://packagist.org/search/?q=type=composer-plugin).
13+
14+
PHP Quality Assurance Tools
15+
==========
16+
17+
This is a composer meta package for installing PHP Quality Assurance Tools with only one dependency, based on [h4cc/phpqatools](https://github.com/h4cc/phpqatools).
18+
19+
Included in this package (based on [phpqatools](http://phpqatools.org/)) are:
20+
21+
- [PHPUnit](https://github.com/sebastianbergmann/phpunit): Testing Framework
22+
- [PHPCOV](https://github.com/sebastianbergmann/phpcov): CLI frontend for the [PHP_CodeCoverage](https://github.com/sebastianbergmann/php-code-coverage)
23+
- [Paratest](https://github.com/brianium/paratest): Parallel testing for PHPUnit
24+
- [DbUnit](https://github.com/sebastianbergmann/dbunit): Puts your database into a known state between test runs
25+
- [PHPLOC](https://github.com/sebastianbergmann/phploc): A tool for quickly measuring the size of a PHP project
26+
- [PHPCPD](https://github.com/sebastianbergmann/phpcpd): Copy/Paste Detector
27+
- [PHP_Depend](https://github.com/pdepend/pdepend): Quality of your design in the terms of extensibility, reusability and maintainability
28+
- [PHPMD](https://github.com/phpmd/phpmd): User friendly frontend application for the raw metrics stream measured by PHP Depend
29+
- [PhpMetrics](https://github.com/phpmetrics/PhpMetrics): Static analysis tool, gives metrics about PHP project and classes
30+
- [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer): Detects violations of a defined set of coding standards
31+
32+
Plus:
33+
34+
- [PHP-CS-Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer): A tool to automatically fix coding standards issues
35+
- [Security-Checker](https://github.com/sensiolabs/security-checker): Checks if your application uses dependencies with known security vulnerabilities
36+
37+
Suggest install:
38+
39+
- [Prestissimo](https://github.com/hirak/prestissimo): Composer parallel install plugin

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
],
1313
"require": {
1414
"php": ">=5.3",
15-
"composer-plugin-api": "^1.0",
15+
"composer-plugin-api": "^1.0"
16+
},
17+
"require-dev": {
1618
"webysther/composer-meta-qa": "~1.0.2"
1719
},
1820
"suggest": {

src/Command/All.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace Webs\QA\Command;
4+
5+
use Composer\Command\BaseCommand;
6+
use Symfony\Component\Console\Input\InputArgument;
7+
use Symfony\Component\Console\Input\InputInterface;
8+
use Symfony\Component\Console\Input\InputOption;
9+
use Symfony\Component\Console\Output\OutputInterface;
10+
use Symfony\Component\Process\Exception\ProcessFailedException;
11+
use Symfony\Component\Process\Process;
12+
13+
class All extends BaseCommand
14+
{
15+
protected $input;
16+
protected $output;
17+
protected $description = 'Run all tools';
18+
19+
protected function configure()
20+
{
21+
$this->setName('qa:all')
22+
->setDescription($this->description);
23+
}
24+
25+
protected function execute(InputInterface $input, OutputInterface $output)
26+
{
27+
$start = microtime(true);
28+
29+
$provider = new Provider();
30+
$commands = $provider->getCommands();
31+
32+
foreach ($commands as $command) {
33+
$name = $command->getName();
34+
if($name == 'qa:all' || strlen($name) < 7) continue;
35+
36+
$output->writeln('<comment>Running ' . $name . '</comment>');
37+
$returnCode = $this->getApplication()->find($command->getName())->run($input, $output);
38+
if($returnCode){
39+
exit($returnCode);
40+
}
41+
}
42+
43+
$end = microtime(true);
44+
$time = round($end-$start);
45+
$output->writeln('<comment>All take ' . $time . ' seconds</comment>');
46+
}
47+
}

src/Command/CBF.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Webs\QA\Command;
4+
5+
class CBF extends CodeBeautifierFixer
6+
{
7+
8+
protected function configure()
9+
{
10+
parent::configure();
11+
$this->setName('qa:cbf');
12+
}
13+
}

src/Command/CC.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Webs\QA\Command;
4+
5+
class CC extends CodeCoverage
6+
{
7+
8+
protected function configure()
9+
{
10+
parent::configure();
11+
$this->setName('qa:cc');
12+
}
13+
}

src/Command/CS.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Webs\QA\Command;
4+
5+
class CS extends CodeSniffer
6+
{
7+
8+
protected function configure()
9+
{
10+
parent::configure();
11+
$this->setName('qa:cs');
12+
}
13+
}

src/Command/CSF.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Webs\QA\Command;
4+
5+
class CSF extends PHPCSFixer
6+
{
7+
8+
protected function configure()
9+
{
10+
parent::configure();
11+
$this->setName('qa:csf');
12+
}
13+
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?php
2+
3+
namespace Webs\QA\Command;
4+
5+
use Composer\Command\BaseCommand;
6+
use Symfony\Component\Console\Input\InputArgument;
7+
use Symfony\Component\Console\Input\InputInterface;
8+
use Symfony\Component\Console\Input\InputOption;
9+
use Symfony\Component\Console\Output\OutputInterface;
10+
use Symfony\Component\Process\Exception\ProcessFailedException;
11+
use Symfony\Component\Process\Process;
12+
13+
class CodeBeautifierFixer extends BaseCommand
14+
{
15+
protected $input;
16+
protected $output;
17+
protected $source = array('src','app','tests');
18+
protected $description = 'Code Beautifier and Fixer';
19+
20+
protected function configure()
21+
{
22+
// Alias is composer qa:cbf
23+
$this->setName('qa:code-beautifier-fixer')
24+
->setDescription($this->description)
25+
->addArgument(
26+
'source',
27+
InputArgument::IS_ARRAY|InputArgument::OPTIONAL,
28+
'List of directories to search Default:src,app,tests'
29+
)
30+
->addOption(
31+
'standard',
32+
null,
33+
InputOption::VALUE_REQUIRED,
34+
'List of standards Default:PSR1,PSR2',
35+
'PSR1,PSR2'
36+
)
37+
->addOption(
38+
'no-diff',
39+
null,
40+
InputOption::VALUE_NONE,
41+
'Ignore changed files Important: Using `git stash`, maybe fail in some cases'
42+
);
43+
}
44+
45+
protected function execute(InputInterface $input, OutputInterface $output)
46+
{
47+
$start = microtime(true);
48+
$this->input = $input;
49+
$this->output = $output;
50+
$this->output->writeln('<comment>Running ' . $this->description . '...</comment>');
51+
52+
$cbf = 'vendor/bin/phpcbf';
53+
if(!file_exists($cbf)){
54+
$process = new Process('phpcbf --help');
55+
$process->run();
56+
if ($process->isSuccessful()) {
57+
$cbf = 'phpcbf';
58+
} else {
59+
throw new ProcessFailedException($process);
60+
}
61+
}
62+
63+
$process = new Process($cbf . ' --version');
64+
$process->run();
65+
$this->output->writeln($process->getOutput());
66+
67+
if($input->getOption('no-diff')){
68+
$process = new Process('git stash');
69+
$process->run();
70+
if(!$process->isSuccessful()){
71+
throw new ProcessFailedException($process);
72+
}
73+
}
74+
75+
$cmd = $cbf . ' --standard='.$input->getOption('standard') . ' ' . $this->getSource();
76+
$process = new Process($cmd);
77+
$process->setTimeout(3600);
78+
$process->run();
79+
$exitCode = $process->getExitCode();
80+
81+
$changes = true;
82+
if(strpos($process->getOutput(), 'No fixable errors were found') !== false){
83+
$changes = false;
84+
$this->output->writeln('No changes'.PHP_EOL);
85+
}
86+
87+
$changed = '';
88+
if($changes){
89+
$process = new Process('git status -s');
90+
$process->run();
91+
$changed = $process->getOutput();
92+
$this->output->writeln($changed);
93+
}
94+
95+
$filesChanged = count(preg_split('/\n|\r/', $changed));
96+
if($changes && $filesChanged < 25 && $input->getOption('no-diff')){
97+
$process = new Process(
98+
'git -c color.ui=always diff --compaction-heuristic -U0 --patch --minimal --patience'
99+
);
100+
$process->run();
101+
$this->output->writeln($process->getOutput());
102+
}
103+
104+
if($input->getOption('no-diff')){
105+
$process = new Process('git stash apply');
106+
$process->run();
107+
if(!$process->isSuccessful()){
108+
throw new ProcessFailedException($process);
109+
}
110+
}
111+
112+
$end = microtime(true);
113+
$time = round($end-$start);
114+
115+
$this->output->writeln('<comment>Command executed `' . $cmd . '` in ' . $time . ' seconds</comment>');
116+
exit($exitCode);
117+
}
118+
119+
protected function getSource()
120+
{
121+
if($this->input->getArgument('source')){
122+
$this->source = $this->input->getArgument('source');
123+
}
124+
125+
$dirs = array();
126+
foreach ($this->source as $dir) {
127+
if(is_dir($dir)){
128+
$dirs[] = $dir;
129+
}
130+
}
131+
132+
return implode(' ', $dirs);
133+
}
134+
}

0 commit comments

Comments
 (0)