Skip to content

Commit

Permalink
make sure php version errors are less misleading
Browse files Browse the repository at this point in the history
* determine conflicting version in problem using pool package
* hide version in rule to keep it generic rather than possibly misleading

fixes #4319
  • Loading branch information
alcohol committed Jul 31, 2015
1 parent a67eaf0 commit 77f1d59
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/Composer/DependencyResolver/Problem.php
Expand Up @@ -87,8 +87,12 @@ public function getPrettyString(array $installedMap = array())
}

if ($job && $job['cmd'] === 'install' && empty($packages)) {

// handle php/hhvm
if ($job['packageName'] === 'php' || $job['packageName'] === 'php-64bit' || $job['packageName'] === 'hhvm') {
$available = $this->pool->whatProvides($job['packageName']);
$version = count($available) ? $available[0]->getPrettyVersion() : phpversion();

$msg = "\n - This package requires ".$job['packageName'].$this->constraintToText($job['constraint']).' but ';

if (defined('HHVM_VERSION')) {
Expand All @@ -97,7 +101,7 @@ public function getPrettyString(array $installedMap = array())
return $msg . 'you are running this with PHP and not HHVM.';
}

return $msg . 'your PHP version ('. phpversion().') does not satisfy that requirement.';
return $msg . 'your PHP version ('. $version .') does not satisfy that requirement.';
}

// handle php extensions
Expand Down
5 changes: 3 additions & 2 deletions src/Composer/DependencyResolver/Rule.php
Expand Up @@ -199,16 +199,17 @@ public function getPrettyString(Pool $pool, array $installedMap = array())
} else {
$targetName = $this->reasonData->getTarget();

// handle php extensions
if ($targetName === 'php' || $targetName === 'php-64bit' || $targetName === 'hhvm') {
// handle php/hhvm
if (defined('HHVM_VERSION')) {
$text .= ' -> your HHVM version does not satisfy that requirement.';
} elseif ($targetName === 'hhvm') {
$text .= ' -> you are running this with PHP and not HHVM.';
} else {
$text .= ' -> your PHP version ('. phpversion().') does not satisfy that requirement.';
$text .= ' -> your PHP version does not satisfy that requirement.';
}
} elseif (0 === strpos($targetName, 'ext-')) {
// handle php extensions
$ext = substr($targetName, 4);
$error = extension_loaded($ext) ? 'has the wrong version ('.(phpversion($ext) ?: '0').') installed' : 'is missing from your system';

Expand Down

0 comments on commit 77f1d59

Please sign in to comment.