Skip to content

Commit d1943dc

Browse files
author
Willem Stuursma
committed
Restore caching in SyntaxSniff
1 parent 49099b8 commit d1943dc

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,6 +1520,7 @@ public static function getExecutablePath($name)
15201520
/*
15211521
* For php, we know the executable path. There's no need to look it up.
15221522
*/
1523+
15231524
return PHP_BINARY;
15241525
}
15251526

src/Standards/Generic/Sniffs/PHP/SyntaxSniff.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@
1717
class SyntaxSniff implements Sniff
1818
{
1919

20+
/**
21+
* The path to the PHP version we are checking with.
22+
*
23+
* @var string
24+
*/
25+
private $phpPath = null;
26+
2027

2128
/**
2229
* Returns an array of tokens this test wants to listen for.
@@ -41,8 +48,12 @@ public function register()
4148
*/
4249
public function process(File $phpcsFile, $stackPtr)
4350
{
51+
if ($this->phpPath === null) {
52+
$this->phpPath = Config::getExecutablePath('php');
53+
}
54+
4455
$fileName = escapeshellarg($phpcsFile->getFilename());
45-
$cmd = escapeshellcmd(Config::getExecutablePath('php'))." -l -d display_errors=1 -d error_prepend_string='' $fileName 2>&1";
56+
$cmd = escapeshellcmd($this->phpPath)." -l -d display_errors=1 -d error_prepend_string='' $fileName 2>&1";
4657
$output = shell_exec($cmd);
4758
$matches = [];
4859
if (preg_match('/^.*error:(.*) in .* on line ([0-9]+)/m', trim($output), $matches) === 1) {

0 commit comments

Comments
 (0)