diff --git a/src/Plugin.php b/src/Plugin.php index 2c7ff1af..b73aedd9 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -46,6 +46,7 @@ class Plugin implements PluginInterface, EventSubscriberInterface const PACKAGE_NAME = 'squizlabs/php_codesniffer'; const PACKAGE_TYPE = 'phpcodesniffer-standard'; + const PHPCS_CONFIG_REGEX = '`%s:[^\r\n]+`'; const PHPCS_CONFIG_KEY = 'installed_paths'; /** @@ -199,22 +200,29 @@ public function onDependenciesChangedEvent() */ private function loadInstalledPaths() { - if ($this->isPHPCodeSnifferInstalled() === true) { - $this->processExecutor->execute( - sprintf( - 'phpcs --config-show %s', - self::PHPCS_CONFIG_KEY - ), - $output, - $this->composer->getConfig()->get('bin-dir') - ); + if ($this->isPHPCodeSnifferInstalled() !== true) { + return; + } + + $this->processExecutor->execute( + sprintf( + 'phpcs --config-show %s', + self::PHPCS_CONFIG_KEY + ), + $output, + $this->composer->getConfig()->get('bin-dir') + ); - $phpcsInstalledPaths = str_replace(self::PHPCS_CONFIG_KEY . ': ', '', $output); - $phpcsInstalledPaths = trim($phpcsInstalledPaths); + $regex = sprintf(self::PHPCS_CONFIG_REGEX, self::PHPCS_CONFIG_KEY); + if (preg_match($regex, $output, $match) !== 1) { + return; + } - if ($phpcsInstalledPaths !== '') { - $this->installedPaths = explode(',', $phpcsInstalledPaths); - } + $phpcsInstalledPaths = str_replace(self::PHPCS_CONFIG_KEY . ': ', '', $match[0]); + $phpcsInstalledPaths = trim($phpcsInstalledPaths); + + if ($phpcsInstalledPaths !== '') { + $this->installedPaths = explode(',', $phpcsInstalledPaths); } }