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

Commit

Permalink
Produce a warning in the report when a non-PHP 7 binary is used.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexia committed Jul 22, 2015
1 parent 357630a commit 1e26de1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
34 changes: 30 additions & 4 deletions classes/tests.php
Expand Up @@ -113,6 +113,20 @@ public function testLine($line) {
return $issues;
}

/**
* Return the PHP binary location.
*
* @access public
* @return string PHP binary location.
*/
public function getPHPBinaryPath() {
$binary = 'php';
if ($this->php !== null) {
$binary = $this->php;
}
return $binary;
}

/**
* Set the location of the PHP binary.
*
Expand All @@ -124,6 +138,21 @@ public function setPHPBinaryPath($path) {
$this->php = $path;
}

/**
* Return the version of PHP for the selected binary.
*
* @access public
* @return mixed Version string or false on error.
*/
public function getPHPVersion() {
$binary = $this->getPHPBinaryPath();
$version = exec($binary.' -r "echo(phpversion());" 2>&1', $version);

$version = trim($version);

return version_compare($version, "7.0.0-dev", ">=");
}

/**
* Check if syntax is valid and return line information if not.
*
Expand All @@ -132,10 +161,7 @@ public function setPHPBinaryPath($path) {
* @return array Test Results
*/
public function checkSyntax($filePath) {
$binary = 'php';
if ($this->php !== null) {
$binary = $this->php;
}
$binary = $this->getPHPBinaryPath();
exec($binary.' -l '.$filePath.' 2>&1', $output);

$syntax = [];
Expand Down
4 changes: 4 additions & 0 deletions mar.php
Expand Up @@ -106,6 +106,10 @@ private function run() {
$filePath = $this->scanner->getCurrentFilePath();
if (!$this->options->getOption('t') || in_array('syntax', $this->options->getOption('t'), true)) {
$checkSyntax = true;
$versionGood = $this->tests->getPHPVersion();
if (!$versionGood) {
$this->reporter->add("ERROR! Syntax checking was selected and a PHP binary lower than 7.0.0-dev was specified.", 0, 1);
}
} else {
$checkSyntax = false;
}
Expand Down

0 comments on commit 1e26de1

Please sign in to comment.