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

Various minor tweaks #151

Merged
merged 5 commits into from Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Expand Up @@ -4,9 +4,11 @@ When contributing to this repository, please first discuss the change you wish
to make via issue, email, or any other method with the owners of this repository
before making a change.

Please note we have [a code of conduct](#code-of-conduct), please follow it in all your interactions
Please note we have [a code of conduct][], please follow it in all your interactions
with the project.

[a code of conduct]: https://github.com/Dealerdirect/phpcodesniffer-composer-installer/blob/master/CODE_OF_CONDUCT.md

## Issues and feature requests

You've found a bug in the source code, a mistake in the documentation or maybe
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2016-2021 Dealerdirect B.V.
Copyright (c) 2016-2022 Dealerdirect B.V.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -60,7 +60,7 @@ This plugin is compatible with:

Basically, this plugin executes the following steps:

- This plugin searches for [`phpcodesniffer-standard` packages] in all of your currently installed Composer packages.
- This plugin searches for [`phpcodesniffer-standard` packages][] in all of your currently installed Composer packages.
- Matching packages and the project itself are scanned for PHP_CodeSniffer rulesets.
- The plugin will call PHP_CodeSniffer and configure the `installed_paths` option.

Expand Down Expand Up @@ -235,7 +235,7 @@ For a full list of all author and/or contributors, check [the contributors page]

The MIT License (MIT)

Copyright (c) 2016-2021 Dealerdirect B.V.
Copyright (c) 2016-2022 Dealerdirect B.V.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 5 additions & 1 deletion composer.json
Expand Up @@ -4,7 +4,7 @@
"type": "composer-plugin",
"keywords": [
"composer", "installer", "plugin",
"phpcs", "codesniffer", "phpcodesniffer", "php_codesniffer",
"phpcs", "phpcbf", "codesniffer", "phpcodesniffer", "php_codesniffer",
"standard", "standards", "style guide", "stylecheck",
"qa", "quality", "code quality", "tests"
],
Expand All @@ -16,6 +16,10 @@
"email": "franck.nijhof@dealerdirect.com",
"homepage": "http://www.frenck.nl",
"role": "Developer / IT Manager"
},
{
"name" : "Contributors",
"homepage" : "https://github.com/Dealerdirect/phpcodesniffer-composer-installer/graphs/contributors"
}
],
"support": {
Expand Down
3 changes: 3 additions & 0 deletions phpcs.xml.dist
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"/>
Potherca marked this conversation as resolved.
Show resolved Hide resolved

</ruleset>
45 changes: 23 additions & 22 deletions src/Plugin.php
Expand Up @@ -4,7 +4,7 @@
* This file is part of the Dealerdirect PHP_CodeSniffer Standards
* Composer Installer Plugin package.
*
* @copyright 2016-2021 Dealerdirect B.V.
* @copyright 2016-2022 Dealerdirect B.V.
* @license MIT
*/

Expand Down 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