Skip to content
This repository has been archived by the owner on May 25, 2020. It is now read-only.

Commit

Permalink
Experimenting on Windows support, got rid of symfony/process
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Aug 28, 2013
1 parent abe63ce commit 40d5ddb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 41 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
}
],
"require": {
"squizlabs/php_codesniffer": "1.4.*",
"symfony/process": "dev-master"
"squizlabs/php_codesniffer": "1.4.*"
},
"autoload": {
"psr-0": {
Expand Down
63 changes: 26 additions & 37 deletions src/DiffSniffer/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function __construct()

/**
* Runs CodeSniffer against specified changeset
*
*
* @param Changeset $changeset Changeset instance
* @param array $arguments PHP_CodeSniffer command line arguments
*
Expand All @@ -98,7 +98,7 @@ public function run(Changeset $changeset, array $arguments = array())

/**
* Create temporary directory
*
*
* @return string Directory path
*/
protected function createTempDir()
Expand Down Expand Up @@ -187,10 +187,10 @@ protected function createTempFile()

return $file;
}

/**
* Runs CodeSniffer
*
*
* @param string $dir Base directory path
* @param string $diffPath Diff file path
* @param array $arguments PHP_CodeSniffer command line arguments
Expand All @@ -203,30 +203,22 @@ protected function runCodeSniffer($dir, $diffPath, array $arguments)

$cmd = $this->getCommand($autoPrependFile, $dir, $arguments);

$process = new Process(
$pipes = array();
$process = proc_open(
$cmd,
array(
1 => array('file', 'php://stdout', 'w'),
2 => array('file', 'php://stderr', 'w'),
),
$pipes,
null,
array(
'PHPCS_DIFF_PATH' => $diffPath,
'PHPCS_BASE_DIR' => $dir,
),
null
);

$return_value = $process->run(
function ($type, $buffer) {
switch ($type) {
case Process::OUT:
fwrite(STDOUT, $buffer);
break;
case Process::ERR:
fwrite(STDERR, $buffer);
break;
}
}
)
);

return $return_value;
return proc_close($process);
}

/**
Expand All @@ -241,39 +233,36 @@ function ($type, $buffer) {
*/
protected function getCommand($autoPrependFile, $dir, $arguments)
{
$finder = new PhpExecutableFinder();
if (false === $php = $finder->find()) {
throw new \RuntimeException('Unable to find the PHP executable');
}

$arguments = array_filter(
$arguments,
function ($argument) {
return strpos($argument, '--report') === false;
}
);

$isWindows = defined('PHP_WINDOWS_VERSION_BUILD');
if (!$isWindows) {
$phpBin = 'vendor/bin/composer-php';
} else {
$phpBin = 'vendor\bin\composer-php.bat';
}

$arguments = array_merge(
array(
$php,
'-d',
'include_path=' . ini_get('include_path')
. PATH_SEPARATOR . $this->includePath,
$phpBin,
'-d',
'auto_prepend_file=' . $autoPrependFile,
),
array(
$this->phpCsBin,
'auto_prepend_file=' . escapeshellarg($autoPrependFile),
'-f',
escapeshellarg($this->phpCsBin),
'--',
),
$arguments,
array(
'--report=xml',
$dir
escapeshellarg($dir),
)
);

$arguments = array_map('escapeshellarg', $arguments);

$cmd = implode(' ', $arguments);

return $cmd;
Expand Down
15 changes: 13 additions & 2 deletions src/PHP/CodeSniffer/Reports/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* @see PHP_CodeSniffer_Report
*/
require_once 'PHP/CodeSniffer/Report.php';
require_once 'CodeSniffer/Report.php';

/**
* Wrapper report for PHP_CodeSniffer.
Expand Down Expand Up @@ -49,9 +49,19 @@ public function generate(
$width = 80,
$toScreen = true
) {
if (!isset($_SERVER['PHPCS_DIFF_PATH'])) {
throw new PHP_CodeSniffer_Exception(
'PHPCS_DIFF_PATH environment variable is not set'
);
}
$diffPath = $_SERVER['PHPCS_DIFF_PATH'];
$diff = file_get_contents($diffPath);

if (!isset($_SERVER['PHPCS_DIFF_PATH'])) {
throw new PHP_CodeSniffer_Exception(
'PHPCS_DIFF_PATH environment variable is not set'
);
}
$baseDir = $_SERVER['PHPCS_BASE_DIR'];

$report = $this->filter($report, $baseDir, $diff);
Expand All @@ -75,7 +85,8 @@ protected function filter(array $report, $baseDir, $diff)

$files = array();
foreach ($changes as $relPath => $lines) {
$absPath = $baseDir . DIRECTORY_SEPARATOR . $relPath;
$absPath = $baseDir . DIRECTORY_SEPARATOR
. str_replace('/', DIRECTORY_SEPARATOR, $relPath);

if (isset($report['files'][$absPath])) {
$files[$relPath]['messages'] = array_intersect_key(
Expand Down

0 comments on commit 40d5ddb

Please sign in to comment.