Skip to content

Commit

Permalink
🔨 Trival code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
frenck committed Oct 26, 2018
1 parent ca8cfb8 commit 1abca7b
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions src/Plugin.php
Expand Up @@ -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;
Expand All @@ -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';
Expand All @@ -53,24 +53,29 @@ class Plugin implements PluginInterface, EventSubscriberInterface
private $composer;

/**
* @var IOInterface
* @var string
*/
private $io;
private $cwd;

/**
* @var Filesystem
*/
private $filesystem;

/**
* @var array
*/
private $installedPaths;

/**
* @var ProcessExecutor
* @var IOInterface
*/
private $processExecutor;
private $io;

/**
* @var Filesystem
* @var ProcessExecutor
*/
private $filesystem;
private $processExecutor;

/**
* @var string
Expand Down Expand Up @@ -108,8 +113,8 @@ public static function run(Event $event)
*
* @throws \RuntimeException
* @throws LogicException
* @throws RuntimeException
* @throws ProcessFailedException
* @throws RuntimeException
*/
public function activate(Composer $composer, IOInterface $io)
{
Expand All @@ -129,7 +134,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);
$this->cwd = getcwd();
Expand All @@ -154,9 +161,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()
{
Expand Down Expand Up @@ -185,9 +192,9 @@ public function onDependenciesChangedEvent()
/**
* Load all paths from PHP_CodeSniffer into an array.
*
* @throws RuntimeException
* @throws LogicException
* @throws ProcessFailedException
* @throws RuntimeException
*/
private function loadInstalledPaths()
{
Expand All @@ -213,9 +220,9 @@ private function loadInstalledPaths()
/**
* Save all coding standard paths back into PHP_CodeSniffer
*
* @throws RuntimeException
* @throws LogicException
* @throws ProcessFailedException
* @throws RuntimeException
*/
private function saveInstalledPaths()
{
Expand Down Expand Up @@ -305,12 +312,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) {
Expand Down

0 comments on commit 1abca7b

Please sign in to comment.