phpVersionProvider = $phpVersionProvider; } /** * @return bool|int|null */ public function evaluate(ConditionInterface $condition) { if ($condition instanceof VersionCompareCondition) { return $this->evaluateVersionCompareCondition($condition); } if ($condition instanceof BinaryToVersionCompareCondition) { return $this->isEvaluedAsTrue($condition); } return null; } /** * @return bool|int|null */ private function evaluateVersionCompareCondition(VersionCompareCondition $versionCompareCondition) { $compareSign = $versionCompareCondition->getCompareSign(); if ($compareSign !== null) { if ($compareSign === '<' && $this->phpVersionProvider->provide() < $versionCompareCondition->getSecondVersion()) { return null; } return \version_compare((string) $versionCompareCondition->getFirstVersion(), (string) $versionCompareCondition->getSecondVersion(), $compareSign); } return \version_compare((string) $versionCompareCondition->getFirstVersion(), (string) $versionCompareCondition->getSecondVersion()); } private function isEvaluedAsTrue(BinaryToVersionCompareCondition $binaryToVersionCompareCondition) : bool { $versionCompareResult = $this->evaluateVersionCompareCondition($binaryToVersionCompareCondition->getVersionCompareCondition()); if ($binaryToVersionCompareCondition->getBinaryClass() === Identical::class) { return $binaryToVersionCompareCondition->getExpectedValue() === $versionCompareResult; } if ($binaryToVersionCompareCondition->getBinaryClass() === NotIdentical::class) { return $binaryToVersionCompareCondition->getExpectedValue() !== $versionCompareResult; } if ($binaryToVersionCompareCondition->getBinaryClass() === Equal::class) { // weak comparison on purpose return $binaryToVersionCompareCondition->getExpectedValue() === $versionCompareResult; } if ($binaryToVersionCompareCondition->getBinaryClass() === NotEqual::class) { // weak comparison on purpose return $binaryToVersionCompareCondition->getExpectedValue() !== $versionCompareResult; } throw new ShouldNotHappenException(); } }