Skip to content

Commit

Permalink
Option to allow Xdebug for debugging purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Oct 19, 2019
1 parent c327552 commit 3b379a3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
5 changes: 0 additions & 5 deletions bin/phpstan
@@ -1,7 +1,6 @@
#!/usr/bin/env php
<?php declare(strict_types=1);

use Composer\XdebugHandler\XdebugHandler;
use PHPStan\Command\AnalyseCommand;
use PHPStan\Command\DumpDependenciesCommand;

Expand Down Expand Up @@ -42,10 +41,6 @@ if (is_file($devOrPharAutoloadFile)) {
require_once $devOrPharAutoloadFile;
}

$xdebug = new XdebugHandler('phpstan', '--ansi');
$xdebug->check();
unset($xdebug);

$version = 'Version unknown';
try {
$version = \Jean85\PrettyVersions::getVersion('phpstan/phpstan')->getPrettyVersion();
Expand Down
6 changes: 5 additions & 1 deletion src/Command/AnalyseCommand.php
Expand Up @@ -31,6 +31,7 @@ protected function configure(): void
new InputOption('autoload-file', 'a', InputOption::VALUE_REQUIRED, 'Project\'s additional autoload file path'),
new InputOption('error-format', null, InputOption::VALUE_REQUIRED, 'Format in which to print the result of the analysis', 'table'),
new InputOption('memory-limit', null, InputOption::VALUE_REQUIRED, 'Memory limit for analysis'),
new InputOption('xdebug', null, InputOption::VALUE_NONE, 'Allow running with XDebug for debugging purposes'),
]);
}

Expand Down Expand Up @@ -63,6 +64,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$configuration = $input->getOption('configuration');
$level = $input->getOption(self::OPTION_LEVEL);
$pathsFile = $input->getOption('paths-file');
$allowXdebug = $input->getOption('xdebug');

if (
!is_array($paths)
Expand All @@ -71,6 +73,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
|| (!is_string($configuration) && $configuration !== null)
|| (!is_string($level) && $level !== null)
|| (!is_string($pathsFile) && $pathsFile !== null)
|| (!is_bool($allowXdebug))
) {
throw new \PHPStan\ShouldNotHappenException();
}
Expand All @@ -84,7 +87,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$memoryLimit,
$autoloadFile,
$configuration,
$level
$level,
$allowXdebug
);
} catch (\PHPStan\Command\InceptionNotSuccessfulException $e) {
return 1;
Expand Down
9 changes: 8 additions & 1 deletion src/Command/CommandHelper.php
Expand Up @@ -2,6 +2,7 @@

namespace PHPStan\Command;

use Composer\XdebugHandler\XdebugHandler;
use Nette\DI\Config\Adapters\NeonAdapter;
use Nette\DI\Config\Adapters\PhpAdapter;
use Nette\DI\Helpers;
Expand Down Expand Up @@ -33,9 +34,15 @@ public static function begin(
?string $memoryLimit,
?string $autoloadFile,
?string $projectConfigFile,
?string $level
?string $level,
bool $allowXdebug
): InceptionResult
{
if (!$allowXdebug) {
$xdebug = new XdebugHandler('phpstan', '--ansi');
$xdebug->check();
unset($xdebug);
}
$errorOutput = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output;
$consoleStyle = new ErrorsConsoleStyle($input, $output);
if ($memoryLimit !== null) {
Expand Down
8 changes: 7 additions & 1 deletion src/Command/DumpDependenciesCommand.php
Expand Up @@ -27,6 +27,7 @@ protected function configure(): void
new InputOption('autoload-file', 'a', InputOption::VALUE_REQUIRED, 'Project\'s additional autoload file path'),
new InputOption('memory-limit', null, InputOption::VALUE_REQUIRED, 'Memory limit for the run'),
new InputOption('analysed-paths', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Project-scope paths'),
new InputOption('xdebug', null, InputOption::VALUE_NONE, 'Allow running with XDebug for debugging purposes'),
]);
}

Expand All @@ -47,6 +48,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int

/** @var string|null $pathsFile */
$pathsFile = $input->getOption('paths-file');

/** @var bool $allowXdebug */
$allowXdebug = $input->getOption('xdebug');

$inceptionResult = CommandHelper::begin(
$input,
$output,
Expand All @@ -55,7 +60,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$memoryLimit,
$autoloadFile,
$configurationFile,
'0' // irrelevant but prevents an error when a config file is passed
'0', // irrelevant but prevents an error when a config file is passed
$allowXdebug
);
} catch (\PHPStan\Command\InceptionNotSuccessfulException $e) {
return 1;
Expand Down
3 changes: 2 additions & 1 deletion tests/PHPStan/Command/CommandHelperTest.php
Expand Up @@ -116,7 +116,8 @@ public function testBegin(
null,
null,
$projectConfigFile,
$level
$level,
false
);
if ($expectException) {
$this->fail();
Expand Down

0 comments on commit 3b379a3

Please sign in to comment.