diff --git a/.travis.yml b/.travis.yml index 9e27f10e8b6..597580295ef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,12 +51,6 @@ script: php bin/run_all_sets.php fi - # try #2205 w/ xdebug - - | - if [[ $COVERAGE == true ]]; then - bin/rector -c - fi - # Eat your own dog food - | if [[ $DOG_FOOD == true ]]; then diff --git a/bin/container.php b/bin/container.php index e8874e8b3b7..f56fee5df3d 100644 --- a/bin/container.php +++ b/bin/container.php @@ -25,16 +25,7 @@ try { } // And from --config or default one -$argInput = new ArgvInput(); - -// https://github.com/rectorphp/rector/issues/2205 -$configOptionValue = ConfigFileFinder::getOptionValue($argInput, ['-c', '--config']); -if ($configOptionValue === '--ansi') { - // empty --config with xdebug handler - die('Option "-c" or "--config" cannot be empty. Provide path to config file' . PHP_EOL); -} - -ConfigFileFinder::detectFromInput('rector', $argInput); +ConfigFileFinder::detectFromInput('rector', new ArgvInput()); $configs[] = ConfigFileFinder::provide('rector', ['rector.yml', 'rector.yaml']); // remove empty values diff --git a/bin/rector b/bin/rector index 1c071f1edca..a4f29aa3769 100755 --- a/bin/rector +++ b/bin/rector @@ -3,7 +3,6 @@ declare(strict_types=1); -use Composer\XdebugHandler\XdebugHandler; use Psr\Container\ContainerInterface; use Rector\Console\Application; @@ -15,10 +14,6 @@ gc_disable(); // Require Composer autoload.php require_once __DIR__ . '/bootstrap.php'; -$xdebug = new XdebugHandler('rector', '--ansi'); -$xdebug->check(); -unset($xdebug); - /** @var ContainerInterface $container */ $container = require_once __DIR__ . '/container.php'; diff --git a/ecs.yaml b/ecs.yaml index 6870625c4f4..e6a48ac213e 100644 --- a/ecs.yaml +++ b/ecs.yaml @@ -46,6 +46,7 @@ services: - 'Symfony\Component\Console\Input\*Input' - 'PHPStan\Analyser\NameScope' - 'PHPStan\Rules\RuleErrors\RuleError*' + - '*\XdebugHandler' Symplify\CodingStandard\Fixer\Naming\PropertyNameMatchingTypeFixer: extra_skipped_classes: diff --git a/src/Console/Application.php b/src/Console/Application.php index 8f76b7921a0..70b421cee0a 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -167,6 +167,13 @@ final class Application extends SymfonyApplication 'Enable debug verbosity (-vvv)' )); + $inputDefinition->addOption(new InputOption( + 'xdebug', + null, + InputOption::VALUE_NONE, + 'Allow running xdebug' + )); + $inputDefinition->addOption(new InputOption( '--working-dir', '-d', diff --git a/src/Console/Command/AbstractCommand.php b/src/Console/Command/AbstractCommand.php index bf4387f56db..fd9f439b5f2 100644 --- a/src/Console/Command/AbstractCommand.php +++ b/src/Console/Command/AbstractCommand.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace Rector\Console\Command; +use Composer\XdebugHandler\XdebugHandler; use Nette\Utils\Strings; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Descriptor\TextDescriptor; @@ -60,5 +61,12 @@ abstract class AbstractCommand extends Command $this->getApplication()->setCatchExceptions(false); } + + // @fixes https://github.com/rectorphp/rector/issues/2205 + if ($input->getOption('xdebug')) { + $xdebug = new XdebugHandler('rector', '--ansi'); + $xdebug->check(); + unset($xdebug); + } } }