* use php-cs-fixer instead of phpcodesniffer * updated scrutinizer config * adjusted code yules to all files * updated CONTRIBUTING guidelines
This commit is contained in:
@@ -11,22 +11,22 @@ namespace App\Command;
|
||||
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
|
||||
/**
|
||||
* Command used to check the project coding styles.
|
||||
* Command used to check and apply the projects coding styles.
|
||||
*/
|
||||
class RunCodeSnifferCommand extends Command
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $rootDir;
|
||||
protected $rootDir = '';
|
||||
|
||||
/**
|
||||
* RunCodeSnifferCommand constructor.
|
||||
* @param $projectDirectory
|
||||
* @param string $projectDirectory
|
||||
*/
|
||||
public function __construct($projectDirectory)
|
||||
{
|
||||
@@ -35,46 +35,64 @@ class RunCodeSnifferCommand extends Command
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('kimai:phpcs')
|
||||
->setDescription('Run PHP_CodeSniffer to check for the projects coding style')
|
||||
->addOption('fix', null, InputOption::VALUE_NONE, 'Fix all found problems (risky: modifies your files)')
|
||||
->addOption('checkstyle', null, InputOption::VALUE_OPTIONAL, '')
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
|
||||
$this->executeCodeSniffer($io, '/src');
|
||||
$this->executeCodeSniffer($io, '/tests');
|
||||
$this->executeCodeSniffer($io, '/templates');
|
||||
}
|
||||
$filename = null;
|
||||
ob_start();
|
||||
|
||||
/**
|
||||
* @param string $directory
|
||||
*/
|
||||
protected function executeCodeSniffer(SymfonyStyle $io, $directory)
|
||||
{
|
||||
$directory = $this->rootDir . $directory;
|
||||
$args = [];
|
||||
if (!$input->getOption('fix')) {
|
||||
$filename = $input->getOption('checkstyle');
|
||||
$args[] = '--dry-run';
|
||||
$args[] = '--verbose';
|
||||
$args[] = '--show-progress=none';
|
||||
|
||||
if (!empty($filename) && (file_exists($filename) && !is_writeable($filename))) {
|
||||
$io->error('Target file is not writeable: ' . $filename);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!empty($filename)) {
|
||||
$filename = $this->rootDir . '/' . $filename;
|
||||
$args[] = '> ' . $filename;
|
||||
} else {
|
||||
$args[] = '--format=txt';
|
||||
}
|
||||
}
|
||||
|
||||
$exitCode = 0;
|
||||
ob_start();
|
||||
passthru($this->rootDir . '/bin/phpcs --standard=PSR2 ' . $directory, $exitCode);
|
||||
passthru($this->rootDir . '/vendor/bin/php-cs-fixer fix ' . implode(' ', $args), $exitCode);
|
||||
$result = ob_get_clean();
|
||||
|
||||
$io->write($result);
|
||||
|
||||
if ($exitCode > 0) {
|
||||
$io->error('Found problems while checking sources at: ' . $directory);
|
||||
} else {
|
||||
$io->success('All sources look good at: ' . $directory);
|
||||
$io->error(
|
||||
'Found problems while checking your code styles' .
|
||||
(!empty($filename) ? '. Saved checkstyle data to: ' . $filename : '')
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$io->success('All source files have proper code styles');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user