From 77f1d5945f8ac6e907ac2c092cfced158db16e49 Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Fri, 31 Jul 2015 09:57:07 +0200 Subject: [PATCH] make sure php version errors are less misleading * determine conflicting version in problem using pool package * hide version in rule to keep it generic rather than possibly misleading fixes #4319 --- src/Composer/DependencyResolver/Problem.php | 6 +++++- src/Composer/DependencyResolver/Rule.php | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Composer/DependencyResolver/Problem.php b/src/Composer/DependencyResolver/Problem.php index 7fcb636b0..5d2117f2c 100644 --- a/src/Composer/DependencyResolver/Problem.php +++ b/src/Composer/DependencyResolver/Problem.php @@ -87,8 +87,12 @@ class Problem } 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')) { @@ -97,7 +101,7 @@ class Problem 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 diff --git a/src/Composer/DependencyResolver/Rule.php b/src/Composer/DependencyResolver/Rule.php index 5d95d678a..8f23b6a94 100644 --- a/src/Composer/DependencyResolver/Rule.php +++ b/src/Composer/DependencyResolver/Rule.php @@ -199,16 +199,17 @@ class Rule } 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';