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

Trivial code cleanup #74

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions src/Plugin.php
Original file line number Diff line number Diff line change
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;

/**
* Triggers the plugin's main functionality.
Expand Down Expand Up @@ -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)
{
Expand All @@ -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);
}
Expand All @@ -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()
{
Expand Down Expand Up @@ -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()
{
Expand All @@ -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()
{
Expand Down Expand Up @@ -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) {
Expand Down