Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaces ProcessBuilder by ProcessExecutor #70

Merged
merged 1 commit into from Oct 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 20 additions & 17 deletions src/Plugin.php
Expand Up @@ -19,11 +19,11 @@
use Composer\Plugin\PluginInterface;
use Composer\Script\Event;
use Composer\Script\ScriptEvents;
use Composer\Util\ProcessExecutor;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Process\Exception\LogicException;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Exception\RuntimeException;
use Symfony\Component\Process\ProcessBuilder;

/**
* PHP_CodeSniffer standard installation manager.
Expand Down Expand Up @@ -62,9 +62,9 @@ class Plugin implements PluginInterface, EventSubscriberInterface
private $installedPaths;

/**
* @var ProcessBuilder
* @var ProcessExecutor
*/
private $processBuilder;
private $processExecutor;

/**
* Triggers the plugin's main functionality.
Expand Down Expand Up @@ -119,9 +119,7 @@ public function activate(Composer $composer, IOInterface $io)
private function init()
{
$this->installedPaths = array();

$this->processBuilder = new ProcessBuilder();
$this->processBuilder->setPrefix($this->composer->getConfig()->get('bin-dir') . DIRECTORY_SEPARATOR . 'phpcs');
$this->processExecutor = new ProcessExecutor($this->io);
}

/**
Expand Down Expand Up @@ -181,11 +179,14 @@ public function onDependenciesChangedEvent()
private function loadInstalledPaths()
{
if ($this->isPHPCodeSnifferInstalled() === true) {
$output = $this->processBuilder
->setArguments(array('--config-show', self::PHPCS_CONFIG_KEY))
->getProcess()
->mustRun()
->getOutput();
$this->processExecutor->execute(
sprintf(
'phpcs --config-show %s',
self::PHPCS_CONFIG_KEY
),
$output,
$this->composer->getConfig()->get('bin-dir')
);

$phpcsInstalledPaths = str_replace(self::PHPCS_CONFIG_KEY . ': ', '', $output);
$phpcsInstalledPaths = trim($phpcsInstalledPaths);
Expand Down Expand Up @@ -225,12 +226,14 @@ private function saveInstalledPaths()

$this->io->write($configMessage);

$configResult = $this->processBuilder
->setArguments($arguments)
->getProcess()
->mustRun()
->getOutput()
;
$this->processExecutor->execute(
sprintf(
'phpcs %s',
implode(' ', $arguments)
),
$configResult,
$this->composer->getConfig()->get('bin-dir')
);

if ($this->io->isVerbose() && !empty($configResult)) {
$this->io->write(sprintf('<info>%s</info>', $configResult));
Expand Down