Skip to content

Commit

Permalink
CS: minor tweaks
Browse files Browse the repository at this point in the history
.. for improved code readability and consistency.
  • Loading branch information
jrfnl committed Jan 30, 2022
1 parent ab0923f commit 7e5d56d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
3 changes: 3 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@
and constant visibility was only introduced in PHP 7.1. -->
<exclude name="PSR12.Properties.ConstantVisibility.NotFound"/>
</rule>

<rule ref="Generic.Formatting.MultipleStatementAlignment"/>

</ruleset>
43 changes: 22 additions & 21 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,17 @@ 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_NOT_INSTALLED = 'PHPCodeSniffer is not installed';

const MESSAGE_NOT_INSTALLED = 'PHPCodeSniffer is not installed';
const MESSAGE_NOTHING_TO_INSTALL = 'Nothing to install or update';
const MESSAGE_PLUGIN_UNINSTALLED = 'PHPCodeSniffer Composer Installer is uninstalled';
const MESSAGE_RUNNING_INSTALLER = 'Running PHPCodeSniffer Composer Installer';
const MESSAGE_RUNNING_INSTALLER = 'Running PHPCodeSniffer Composer Installer';

const PACKAGE_NAME = 'squizlabs/php_codesniffer';
const PACKAGE_TYPE = 'phpcodesniffer-standard';

const PHPCS_CONFIG_REGEX = '`%s:[^\r\n]+`';
const PHPCS_CONFIG_KEY = 'installed_paths';
const PHPCS_CONFIG_KEY = 'installed_paths';

const PLUGIN_NAME = 'dealerdirect/phpcodesniffer-composer-installer';

Expand Down Expand Up @@ -96,12 +97,12 @@ class Plugin implements PluginInterface, EventSubscriberInterface
*/
public static function run(Event $event)
{
$io = $event->getIO();
$io = $event->getIO();
$composer = $event->getComposer();

$instance = new static();

$instance->io = $io;
$instance->io = $io;
$instance->composer = $composer;
$instance->init();
$instance->onDependenciesChangedEvent();
Expand All @@ -118,7 +119,7 @@ public static function run(Event $event)
public function activate(Composer $composer, IOInterface $io)
{
$this->composer = $composer;
$this->io = $io;
$this->io = $io;

$this->init();
}
Expand Down Expand Up @@ -147,11 +148,11 @@ public function uninstall(Composer $composer, IOInterface $io)
*/
private function init()
{
$this->cwd = getcwd();
$this->cwd = getcwd();
$this->installedPaths = array();

$this->processExecutor = new ProcessExecutor($this->io);
$this->filesystem = new Filesystem($this->processExecutor);
$this->filesystem = new Filesystem($this->processExecutor);
}

/**
Expand Down Expand Up @@ -179,9 +180,9 @@ public static function getSubscribedEvents()
*/
public function onDependenciesChangedEvent()
{
$io = $this->io;
$io = $this->io;
$isVerbose = $io->isVerbose();
$exitCode = 0;
$exitCode = 0;

if ($isVerbose) {
$io->write(sprintf('<info>%s</info>', self::MESSAGE_RUNNING_INSTALLER));
Expand Down Expand Up @@ -267,16 +268,16 @@ private function saveInstalledPaths()
// Check if we found installed paths to set.
if (count($this->installedPaths) !== 0) {
sort($this->installedPaths);
$paths = implode(',', $this->installedPaths);
$arguments = array('--config-set', self::PHPCS_CONFIG_KEY, $paths);
$paths = implode(',', $this->installedPaths);
$arguments = array('--config-set', self::PHPCS_CONFIG_KEY, $paths);
$configMessage = sprintf(
'PHP CodeSniffer Config <info>%s</info> <comment>set to</comment> <info>%s</info>',
self::PHPCS_CONFIG_KEY,
$paths
);
} else {
// Delete the installed paths if none were found.
$arguments = array('--config-delete', self::PHPCS_CONFIG_KEY);
$arguments = array('--config-delete', self::PHPCS_CONFIG_KEY);
$configMessage = sprintf(
'PHP CodeSniffer Config <info>%s</info> <comment>delete</comment>',
self::PHPCS_CONFIG_KEY
Expand Down Expand Up @@ -305,7 +306,7 @@ private function saveInstalledPaths()
array(
'php executable' => $this->getPhpExecCommand(),
'phpcs executable' => $phpcsExecutable,
'arguments' => implode(' ', $arguments)
'arguments' => implode(' ', $arguments),
)
);

Expand Down Expand Up @@ -382,7 +383,7 @@ protected function getPhpExecCommand()
: ''
;

$command = ProcessExecutor::escape($phpPath) .
$command = ProcessExecutor::escape($phpPath) .
$phpArgs .
' -d allow_url_fopen=' . ProcessExecutor::escape(ini_get('allow_url_fopen')) .
' -d disable_functions=' . ProcessExecutor::escape(ini_get('disable_functions')) .
Expand All @@ -405,7 +406,7 @@ private function cleanInstalledPaths()
$changes = false;
foreach ($this->installedPaths as $key => $path) {
// This might be a relative path as well
$alternativePath = realpath($this->getPHPCodeSnifferInstallPath() . DIRECTORY_SEPARATOR . $path);
$alternativePath = realpath($this->getPHPCodeSnifferInstallPath() . \DIRECTORY_SEPARATOR . $path);

if (
(is_dir($path) === false || is_readable($path) === false) &&
Expand Down Expand Up @@ -435,13 +436,13 @@ private function updateInstalledPaths()
{
$changes = false;

$searchPaths = array($this->cwd);
$searchPaths = array($this->cwd);
$codingStandardPackages = $this->getPHPCodingStandardPackages();
foreach ($codingStandardPackages as $package) {
$installPath = $this->composer->getInstallationManager()->getInstallPath($package);
if ($this->filesystem->isAbsolutePath($installPath) === false) {
$installPath = $this->filesystem->normalizePath(
$this->cwd . DIRECTORY_SEPARATOR . $installPath
$this->cwd . \DIRECTORY_SEPARATOR . $installPath
);
}
$searchPaths[] = $installPath;
Expand Down Expand Up @@ -477,7 +478,7 @@ private function updateInstalledPaths()
// De-duplicate and add when directory is not configured.
if (in_array($standardsPath, $this->installedPaths, true) === false) {
$this->installedPaths[] = $standardsPath;
$changes = true;
$changes = true;
}
}

Expand Down Expand Up @@ -593,8 +594,8 @@ private function getMaxDepth()
$message = vsprintf(
self::MESSAGE_ERROR_WRONG_MAX_DEPTH,
array(
'key' => self::KEY_MAX_DEPTH,
'min' => $minDepth,
'key' => self::KEY_MAX_DEPTH,
'min' => $minDepth,
'given' => var_export($maxDepth, true),
)
);
Expand Down

0 comments on commit 7e5d56d

Please sign in to comment.