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

Commit 40d5ddb

Browse files
committed
Experimenting on Windows support, got rid of symfony/process
1 parent abe63ce commit 40d5ddb

File tree

3 files changed

+40
-41
lines changed

3 files changed

+40
-41
lines changed

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
}
99
],
1010
"require": {
11-
"squizlabs/php_codesniffer": "1.4.*",
12-
"symfony/process": "dev-master"
11+
"squizlabs/php_codesniffer": "1.4.*"
1312
},
1413
"autoload": {
1514
"psr-0": {

src/DiffSniffer/Runner.php

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function __construct()
7777

7878
/**
7979
* Runs CodeSniffer against specified changeset
80-
*
80+
*
8181
* @param Changeset $changeset Changeset instance
8282
* @param array $arguments PHP_CodeSniffer command line arguments
8383
*
@@ -98,7 +98,7 @@ public function run(Changeset $changeset, array $arguments = array())
9898

9999
/**
100100
* Create temporary directory
101-
*
101+
*
102102
* @return string Directory path
103103
*/
104104
protected function createTempDir()
@@ -187,10 +187,10 @@ protected function createTempFile()
187187

188188
return $file;
189189
}
190-
190+
191191
/**
192192
* Runs CodeSniffer
193-
*
193+
*
194194
* @param string $dir Base directory path
195195
* @param string $diffPath Diff file path
196196
* @param array $arguments PHP_CodeSniffer command line arguments
@@ -203,30 +203,22 @@ protected function runCodeSniffer($dir, $diffPath, array $arguments)
203203

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

206-
$process = new Process(
206+
$pipes = array();
207+
$process = proc_open(
207208
$cmd,
209+
array(
210+
1 => array('file', 'php://stdout', 'w'),
211+
2 => array('file', 'php://stderr', 'w'),
212+
),
213+
$pipes,
208214
null,
209215
array(
210216
'PHPCS_DIFF_PATH' => $diffPath,
211217
'PHPCS_BASE_DIR' => $dir,
212-
),
213-
null
214-
);
215-
216-
$return_value = $process->run(
217-
function ($type, $buffer) {
218-
switch ($type) {
219-
case Process::OUT:
220-
fwrite(STDOUT, $buffer);
221-
break;
222-
case Process::ERR:
223-
fwrite(STDERR, $buffer);
224-
break;
225-
}
226-
}
218+
)
227219
);
228220

229-
return $return_value;
221+
return proc_close($process);
230222
}
231223

232224
/**
@@ -241,39 +233,36 @@ function ($type, $buffer) {
241233
*/
242234
protected function getCommand($autoPrependFile, $dir, $arguments)
243235
{
244-
$finder = new PhpExecutableFinder();
245-
if (false === $php = $finder->find()) {
246-
throw new \RuntimeException('Unable to find the PHP executable');
247-
}
248-
249236
$arguments = array_filter(
250237
$arguments,
251238
function ($argument) {
252239
return strpos($argument, '--report') === false;
253240
}
254241
);
255242

243+
$isWindows = defined('PHP_WINDOWS_VERSION_BUILD');
244+
if (!$isWindows) {
245+
$phpBin = 'vendor/bin/composer-php';
246+
} else {
247+
$phpBin = 'vendor\bin\composer-php.bat';
248+
}
249+
256250
$arguments = array_merge(
257251
array(
258-
$php,
259-
'-d',
260-
'include_path=' . ini_get('include_path')
261-
. PATH_SEPARATOR . $this->includePath,
252+
$phpBin,
262253
'-d',
263-
'auto_prepend_file=' . $autoPrependFile,
264-
),
265-
array(
266-
$this->phpCsBin,
254+
'auto_prepend_file=' . escapeshellarg($autoPrependFile),
255+
'-f',
256+
escapeshellarg($this->phpCsBin),
257+
'--',
267258
),
268259
$arguments,
269260
array(
270261
'--report=xml',
271-
$dir
262+
escapeshellarg($dir),
272263
)
273264
);
274265

275-
$arguments = array_map('escapeshellarg', $arguments);
276-
277266
$cmd = implode(' ', $arguments);
278267

279268
return $cmd;

src/PHP/CodeSniffer/Reports/Xml.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
/**
1616
* @see PHP_CodeSniffer_Report
1717
*/
18-
require_once 'PHP/CodeSniffer/Report.php';
18+
require_once 'CodeSniffer/Report.php';
1919

2020
/**
2121
* Wrapper report for PHP_CodeSniffer.
@@ -49,9 +49,19 @@ public function generate(
4949
$width = 80,
5050
$toScreen = true
5151
) {
52+
if (!isset($_SERVER['PHPCS_DIFF_PATH'])) {
53+
throw new PHP_CodeSniffer_Exception(
54+
'PHPCS_DIFF_PATH environment variable is not set'
55+
);
56+
}
5257
$diffPath = $_SERVER['PHPCS_DIFF_PATH'];
5358
$diff = file_get_contents($diffPath);
5459

60+
if (!isset($_SERVER['PHPCS_DIFF_PATH'])) {
61+
throw new PHP_CodeSniffer_Exception(
62+
'PHPCS_DIFF_PATH environment variable is not set'
63+
);
64+
}
5565
$baseDir = $_SERVER['PHPCS_BASE_DIR'];
5666

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

7686
$files = array();
7787
foreach ($changes as $relPath => $lines) {
78-
$absPath = $baseDir . DIRECTORY_SEPARATOR . $relPath;
88+
$absPath = $baseDir . DIRECTORY_SEPARATOR
89+
. str_replace('/', DIRECTORY_SEPARATOR, $relPath);
7990

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

0 commit comments

Comments
 (0)