phug-php/dev-tool

View on GitHub
src/Phug/DevTool/Command/CheckCommand.php

Summary

Maintainability
B
5 hrs
Test Coverage
<?php
 
namespace Phug\DevTool\Command;
 
use Phug\DevTool\AbstractCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
 
class CheckCommand extends AbstractCommand
{
Method `configure` has 54 lines of code (exceeds 25 allowed). Consider refactoring.
protected function configure()
{
Call to undeclared method `\Phug\DevTool\Command\CheckCommand::setName`
$this->setName('check')
->addOption(
'report',
null,
Reference to constant `VALUE_NONE` from undeclared class `\Symfony\Component\Console\Input\InputOption`
InputOption::VALUE_NONE,
'Send coverage report?'
)
->addOption(
'coverage-text',
null,
Reference to constant `VALUE_NONE` from undeclared class `\Symfony\Component\Console\Input\InputOption`
InputOption::VALUE_NONE,
'Display coverage info?'
)
->addOption(
'coverage-html',
null,
Reference to constant `VALUE_OPTIONAL` from undeclared class `\Symfony\Component\Console\Input\InputOption`
InputOption::VALUE_OPTIONAL,
'Save coverage info as HTML?',
false
)
->addOption(
'coverage-clover',
null,
Reference to constant `VALUE_OPTIONAL` from undeclared class `\Symfony\Component\Console\Input\InputOption`
InputOption::VALUE_OPTIONAL,
'Save coverage info as XML?',
false
)
->addOption(
'group',
null,
Reference to constant `VALUE_OPTIONAL` from undeclared class `\Symfony\Component\Console\Input\InputOption`
InputOption::VALUE_OPTIONAL,
'Excute only a tests group?',
false
)
->addOption(
'ignore-tests',
null,
Reference to constant `VALUE_NONE` from undeclared class `\Symfony\Component\Console\Input\InputOption`
InputOption::VALUE_NONE,
'Ignore /tests/ directories'
)
->addOption(
'ignore-debug',
null,
Reference to constant `VALUE_NONE` from undeclared class `\Symfony\Component\Console\Input\InputOption`
InputOption::VALUE_NONE,
'Ignore /debug/ directories'
)
->addOption(
'coverage-php-version',
null,
Reference to constant `VALUE_OPTIONAL` from undeclared class `\Symfony\Component\Console\Input\InputOption`
InputOption::VALUE_OPTIONAL,
'If specified, the coverage is only tested for the given PHP version'
)
->setDescription('Runs all necessary checks.')
->setHelp('Runs all necessary checks');
}
 
Method `runCoverage` has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Avoid assigning values to variables in if clauses and the like (line '91', column '14').
Avoid assigning values to variables in if clauses and the like (line '97', column '14').
Parameter `$input` has undeclared type `\Symfony\Component\Console\Input\InputInterface`
Parameter `$output` has undeclared type `\Symfony\Component\Console\Output\OutputInterface`
protected function runCoverage(InputInterface $input, OutputInterface $output, $coverageFilePath)
{
$app = $this->getApplication();
 
Call to method `getOption` from undeclared class `\Symfony\Component\Console\Input\InputInterface`
$phpVersion = $input->getOption('coverage-php-version');
 
if (!empty($phpVersion)) {
Argument #1 of this call to `\preg_match` is typically a literal or constant but isn't, but argument #2 (which is typically a variable) is a literal or constant. The arguments may be in the wrong order.
if (!preg_match('/^'.preg_quote($phpVersion).'(\D.*)?$/', PHP_VERSION)) {
Call to method `writeln` from undeclared class `\Symfony\Component\Console\Output\OutputInterface`
$output->writeln(
'Coverage ignored since PHP version ('.PHP_VERSION.')'.
' does not match '.$phpVersion.'.'
);
 
return 0;
}
Call to method `writeln` from undeclared class `\Symfony\Component\Console\Output\OutputInterface`
$output->writeln(
'<fg=green>Proceed test report since PHP version ('.PHP_VERSION.') '.
'matches '.$phpVersion.'.</>'
);
}
 
if (($code = $app->runCommand('coverage:check', $output, [
'input-file' => $coverageFilePath,
])) !== 0) {
return $code;
}
 
if (($code = $app->runCommand('coverage:report', $output, [
'input-file' => $coverageFilePath,
])) !== 0) {
return $code;
}
 
return 0;
}
 
Method `execute` has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Function `execute` has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Avoid assigning values to variables in if clauses and the like (line '129', column '14').
Avoid assigning values to variables in if clauses and the like (line '124', column '17').
Avoid assigning values to variables in if clauses and the like (line '133', column '33').
Avoid assigning values to variables in if clauses and the like (line '137', column '60').
Parameter `$output` has undeclared type `\Symfony\Component\Console\Output\OutputInterface`
Parameter `$input` has undeclared type `\Symfony\Component\Console\Input\InputInterface`
protected function execute(InputInterface $input, OutputInterface $output)
{
$app = $this->getApplication();
$coverageFilePath = $app->getWorkingDirectory().'/coverage.xml';
 
$args = [
'--coverage-text' => true,
'--coverage-clover' => $coverageFilePath,
];
 
$passTrough = [
'coverage-text',
'coverage-clover',
'coverage-html',
'group',
];
 
foreach ($passTrough as $option) {
Call to method `getOption` from undeclared class `\Symfony\Component\Console\Input\InputInterface`
if ($value = $input->getOption($option)) {
$args[$option] = $value;
}
}
 
if (($code = $app->runCommand('unit-tests:run', $output, $args)) !== 0) {
return $code;
}
 
if (!$app->isHhvm() && ($code = $this->runCoverage($input, $output, $coverageFilePath))) {
return $code;
}
 
if (version_compare(PHP_VERSION, '5.6.0') >= 0 && ($code = $app->runCommand('code-style:check', $output, [
'--no-interaction',
Call to method `getOption` from undeclared class `\Symfony\Component\Console\Input\InputInterface`
'--ignore-tests' => $input->getOption('ignore-tests'),
])) !== 0) {
return $code;
}
 
if (file_exists($coverageFilePath)) {
unlink($coverageFilePath);
}
 
return 0;
}
}