Skip to content

Commit

Permalink
🚑 Replaces ProcessBuilder by ProcessExecutor
Browse files Browse the repository at this point in the history
Fixes: #59
  • Loading branch information
frenck committed Oct 26, 2018
1 parent eaef5f5 commit ff3bb9c
Showing 1 changed file with 20 additions and 17 deletions.
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

0 comments on commit ff3bb9c

Please sign in to comment.