diff --git a/composer.json b/composer.json index 533f9a8..f68399f 100644 --- a/composer.json +++ b/composer.json @@ -7,8 +7,7 @@ "require": { "knplabs/github-api": "~1.2", "league/flysystem": "0.5.*", - "symfony/console": "v2.6.3", - "squizlabs/php_codesniffer": "~3.1" + "symfony/console": "v2.6.3" }, "authors": [ { diff --git a/src/Melody/Diffcs/Executor.php b/src/Melody/Diffcs/Executor.php index 1190fca..2bea548 100644 --- a/src/Melody/Diffcs/Executor.php +++ b/src/Melody/Diffcs/Executor.php @@ -13,6 +13,8 @@ */ class Executor { + const PHPCS_PHAR_URL = 'https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar'; + /** * @var type */ @@ -162,6 +164,8 @@ public function downloadFiles($files, $commitId) */ public function runCodeSniffer($downloadedFiles) { + $phpcsBinPath = self::getPhpCsBinPath(); + $progress = new ProgressBar($this->output, count($downloadedFiles)); $progress->setProgressCharacter('|'); $progress->start(); @@ -174,7 +178,7 @@ public function runCodeSniffer($downloadedFiles) } $command = sprintf( - "vendor/bin/phpcs %s/%s --standard=%s", + "php $phpcsBinPath %s/%s --standard=%s", sys_get_temp_dir(), $file, $this->codeStandard @@ -194,4 +198,21 @@ public function runCodeSniffer($downloadedFiles) return $outputs; } + + private static function getPhpCsBinPath() + { + $phpcsBinPath = shell_exec('which phpcs'); + + if (!$phpcsBinPath) { + $phpcsBinPath = sys_get_temp_dir() . '/.diffcs/phpcs'; + } + + if (!file_exists($phpcsBinPath)) { + shell_exec(sprintf("mkdir -p %s/.diffcs", sys_get_temp_dir())); + copy(self::PHPCS_PHAR_URL, $phpcsBinPath); + shell_exec('chmod +x ' . $phpcsBinPath); + } + + return $phpcsBinPath; + } }