Skip to content

Commit

Permalink
Fixed the phpcs dependency issue
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelsud committed Oct 1, 2017
1 parent 4a28515 commit 0115ad9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
23 changes: 22 additions & 1 deletion src/Melody/Diffcs/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
class Executor
{
const PHPCS_PHAR_URL = 'https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar';

/**
* @var type
*/
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -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;
}
}

0 comments on commit 0115ad9

Please sign in to comment.