Skip to content

Commit 1e26de1

Browse files
committed
Produce a warning in the report when a non-PHP 7 binary is used.
1 parent 357630a commit 1e26de1

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

classes/tests.php

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,20 @@ public function testLine($line) {
113113
return $issues;
114114
}
115115

116+
/**
117+
* Return the PHP binary location.
118+
*
119+
* @access public
120+
* @return string PHP binary location.
121+
*/
122+
public function getPHPBinaryPath() {
123+
$binary = 'php';
124+
if ($this->php !== null) {
125+
$binary = $this->php;
126+
}
127+
return $binary;
128+
}
129+
116130
/**
117131
* Set the location of the PHP binary.
118132
*
@@ -124,6 +138,21 @@ public function setPHPBinaryPath($path) {
124138
$this->php = $path;
125139
}
126140

141+
/**
142+
* Return the version of PHP for the selected binary.
143+
*
144+
* @access public
145+
* @return mixed Version string or false on error.
146+
*/
147+
public function getPHPVersion() {
148+
$binary = $this->getPHPBinaryPath();
149+
$version = exec($binary.' -r "echo(phpversion());" 2>&1', $version);
150+
151+
$version = trim($version);
152+
153+
return version_compare($version, "7.0.0-dev", ">=");
154+
}
155+
127156
/**
128157
* Check if syntax is valid and return line information if not.
129158
*
@@ -132,10 +161,7 @@ public function setPHPBinaryPath($path) {
132161
* @return array Test Results
133162
*/
134163
public function checkSyntax($filePath) {
135-
$binary = 'php';
136-
if ($this->php !== null) {
137-
$binary = $this->php;
138-
}
164+
$binary = $this->getPHPBinaryPath();
139165
exec($binary.' -l '.$filePath.' 2>&1', $output);
140166

141167
$syntax = [];

mar.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ private function run() {
106106
$filePath = $this->scanner->getCurrentFilePath();
107107
if (!$this->options->getOption('t') || in_array('syntax', $this->options->getOption('t'), true)) {
108108
$checkSyntax = true;
109+
$versionGood = $this->tests->getPHPVersion();
110+
if (!$versionGood) {
111+
$this->reporter->add("ERROR! Syntax checking was selected and a PHP binary lower than 7.0.0-dev was specified.", 0, 1);
112+
}
109113
} else {
110114
$checkSyntax = false;
111115
}

0 commit comments

Comments
 (0)