diff --git a/src/Plugin.php b/src/Plugin.php index 3ad32709..76803351 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -19,8 +19,8 @@ use Composer\Plugin\PluginInterface; use Composer\Script\Event; use Composer\Script\ScriptEvents; -use Composer\Util\ProcessExecutor; use Composer\Util\Filesystem; +use Composer\Util\ProcessExecutor; use Symfony\Component\Finder\Finder; use Symfony\Component\Process\Exception\LogicException; use Symfony\Component\Process\Exception\ProcessFailedException; @@ -38,9 +38,9 @@ class Plugin implements PluginInterface, EventSubscriberInterface const MESSAGE_ERROR_WRONG_MAX_DEPTH = 'The value of "%s" (in the composer.json "extra".section) must be an integer larger then %d, %s given.'; - const MESSAGE_RUNNING_INSTALLER = 'Running PHPCodeSniffer Composer Installer'; - const MESSAGE_NOTHING_TO_INSTALL = 'Nothing to install or update'; const MESSAGE_NOT_INSTALLED = 'PHPCodeSniffer is not installed'; + const MESSAGE_NOTHING_TO_INSTALL = 'Nothing to install or update'; + const MESSAGE_RUNNING_INSTALLER = 'Running PHPCodeSniffer Composer Installer'; const PACKAGE_NAME = 'squizlabs/php_codesniffer'; const PACKAGE_TYPE = 'phpcodesniffer-standard'; @@ -53,9 +53,14 @@ class Plugin implements PluginInterface, EventSubscriberInterface private $composer; /** - * @var IOInterface + * @var string */ - private $io; + private $cwd; + + /** + * @var Filesystem + */ + private $filesystem; /** * @var array @@ -63,14 +68,14 @@ class Plugin implements PluginInterface, EventSubscriberInterface private $installedPaths; /** - * @var ProcessExecutor + * @var IOInterface */ - private $processExecutor; + private $io; /** - * @var Filesystem + * @var ProcessExecutor */ - private $filesystem; + private $processExecutor; /** * Triggers the plugin's main functionality. @@ -103,8 +108,8 @@ public static function run(Event $event) * * @throws \RuntimeException * @throws LogicException - * @throws RuntimeException * @throws ProcessFailedException + * @throws RuntimeException */ public function activate(Composer $composer, IOInterface $io) { @@ -124,7 +129,9 @@ public function activate(Composer $composer, IOInterface $io) */ private function init() { + $this->cwd = getcwd(); $this->installedPaths = array(); + $this->processExecutor = new ProcessExecutor($this->io); $this->filesystem = new Filesystem($this->processExecutor); } @@ -148,9 +155,9 @@ public static function getSubscribedEvents() * Entry point for post install and post update events. * * @throws \InvalidArgumentException - * @throws RuntimeException * @throws LogicException * @throws ProcessFailedException + * @throws RuntimeException */ public function onDependenciesChangedEvent() { @@ -179,9 +186,9 @@ public function onDependenciesChangedEvent() /** * Load all paths from PHP_CodeSniffer into an array. * - * @throws RuntimeException * @throws LogicException * @throws ProcessFailedException + * @throws RuntimeException */ private function loadInstalledPaths() { @@ -207,9 +214,9 @@ private function loadInstalledPaths() /** * Save all coding standard paths back into PHP_CodeSniffer * - * @throws RuntimeException * @throws LogicException * @throws ProcessFailedException + * @throws RuntimeException */ private function saveInstalledPaths() { @@ -293,12 +300,12 @@ private function updateInstalledPaths() $finder = new Finder(); $finder->files() - ->ignoreUnreadableDirs() - ->ignoreVCS(true) ->depth('<= ' . $this->getMaxDepth()) ->depth('>= ' . $this->getMinDepth()) - ->name('ruleset.xml') - ->in($searchPaths); + ->ignoreUnreadableDirs() + ->ignoreVCS(true) + ->in($searchPaths) + ->name('ruleset.xml'); // Process each found possible ruleset. foreach ($finder as $ruleset) {