From fbd81070a3290f87d89d8cda733c7bee1e705e88 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Fri, 8 Sep 2017 11:53:51 +0100 Subject: [PATCH] CS: Add PHP 5.3 compatibility The use of short syntax for arrays was the only thing stopping this package from being compatible with PHP 5.3 as well. This makes it usable for more authors (such as those in the WordPress community). --- composer.json | 1 + src/Plugin.php | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index 9b26bb0d..225b5b7c 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,7 @@ "source": "https://github.com/dealerdirect/phpcodesniffer-composer-installer" }, "require": { + "php": "^5.3|^7", "composer-plugin-api": "^1.0", "squizlabs/php_codesniffer": "*" }, diff --git a/src/Plugin.php b/src/Plugin.php index a1727b4e..b12a6ccd 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -113,7 +113,7 @@ public function activate(Composer $composer, IOInterface $io) */ private function init() { - $this->installedPaths = []; + $this->installedPaths = array(); $this->processBuilder = new ProcessBuilder(); $this->processBuilder->setPrefix($this->composer->getConfig()->get('bin-dir') . DIRECTORY_SEPARATOR . 'phpcs'); @@ -126,14 +126,14 @@ private function init() */ public static function getSubscribedEvents() { - return [ - ScriptEvents::POST_INSTALL_CMD => [ - ['onDependenciesChangedEvent', 0], - ], - ScriptEvents::POST_UPDATE_CMD => [ - ['onDependenciesChangedEvent', 0], - ], - ]; + return array( + ScriptEvents::POST_INSTALL_CMD => array( + array('onDependenciesChangedEvent', 0), + ), + ScriptEvents::POST_UPDATE_CMD => array( + array('onDependenciesChangedEvent', 0), + ), + ); } /** @@ -178,7 +178,7 @@ private function loadInstalledPaths() { if ($this->isPHPCodeSnifferInstalled() === true) { $output = $this->processBuilder - ->setArguments(['--config-show', self::PHPCS_CONFIG_KEY]) + ->setArguments(array('--config-show', self::PHPCS_CONFIG_KEY)) ->getProcess() ->mustRun() ->getOutput(); @@ -204,7 +204,7 @@ private function saveInstalledPaths() // Check if we found installed paths to set. if (count($this->installedPaths) !== 0) { $paths = implode(',', $this->installedPaths); - $arguments = ['--config-set', self::PHPCS_CONFIG_KEY, $paths]; + $arguments = array('--config-set', self::PHPCS_CONFIG_KEY, $paths); $configMessage = sprintf( 'PHP CodeSniffer Config %s set to %s', self::PHPCS_CONFIG_KEY, @@ -212,7 +212,7 @@ private function saveInstalledPaths() ); } else { // Delete the installed paths if none were found. - $arguments = ['--config-delete', self::PHPCS_CONFIG_KEY]; + $arguments = array('--config-delete', self::PHPCS_CONFIG_KEY); $configMessage = sprintf( 'PHP CodeSniffer Config %s delete', self::PHPCS_CONFIG_KEY @@ -271,7 +271,7 @@ private function updateInstalledPaths() { $changes = false; - $searchPaths = [getcwd()]; + $searchPaths = array(getcwd()); $codingStandardPackages = $this->getPHPCodingStandardPackages(); foreach ($codingStandardPackages as $package) { $searchPaths[] = $this->composer->getInstallationManager()->getInstallPath($package);