コード例 #1
0
 /**
  * make sure that $a and $b are types that can be used together in
  * any of our operators
  *
  * $b will be transformed (if necessary) to a type that is compatible
  * with $a
  *
  * @param  VersionNumber $a
  *         a version number
  * @param  VersionNumber|string $b
  *         a second version number
  * @param  VersionParser|null $parser
  *         the parser to use if $b is a string
  * @return VersionNumber
  *         a version number with the value of $b, compatible with $a
  */
 public static function from(VersionNumber $a, $b, VersionParser $parser = null)
 {
     // convert $b to a string if needed
     $bObj = EnsureVersionNumber::from($b, $parser);
     // do we have a match?
     if (VersionNumbersAreCompatible::check($a, $bObj)) {
         return $bObj;
     }
     // if we get here, then no we do not
     throw new E4xx_IncompatibleVersionNumbers($a, $bObj);
 }
コード例 #2
0
 /**
  * is $a > $b?
  *
  * @param  VersionNumber|string $a
  *         the LHS of this calculation
  * @param  VersionNumber|string $b
  *         the RHS of this calculation
  * @param  VersionParser|null $parser
  *         the parser to use if $a or $b are strings
  * @return boolean
  *         TRUE if $a > $b
  *         FALSE otherwise
  */
 public static function calculate($a, $b, VersionParser $parser = null)
 {
     $aObj = EnsureVersionNumber::from($a, $parser);
     $bObj = EnsureCompatibleVersionNumber::from($aObj, $b, $parser);
     return CompareTwoVersionNumbers::calculate($aObj, $bObj, self::$resultsMap);
 }
コード例 #3
0
 /**
  * is $a compatible with $b, according to the rules of the
  * ^ operator?
  *
  * @param  VersionNumber|string $a
  *         the LHS of this calculation
  * @param  VersionNumber|string $b
  *         the RHS of this calculation
  * @param  VersionParser|null $parser
  *         the parser to use if $a or $b are strings
  * @return boolean
  *         TRUE if $a is compatible with $b
  *         FALSE otherwise
  */
 public static function calculate($a, $b, VersionParser $parser = null)
 {
     // make sure $b is something we can work with
     $aObj = EnsureVersionNumber::from($a, $parser);
     $bObj = EnsureCompatibleVersionNumber::from($aObj, $b, $parser);
     // calculate the upper boundary
     $c = $bObj->getCompatibleUpperBoundary();
     // is $a compatible with $b?
     return InBetween::calculate($aObj, $bObj, $c);
 }
コード例 #4
0
 /**
  * is $a approximately equal to $b, according to the rules of the
  * ~ operator?
  *
  * NOTES:
  *
  * - you can only use the ~ operator to pin down which major / minor
  *   version to limit to, not the preRelease level
  *
  * @param  VersionNumber|string $a
  *         the LHS of this calculation
  * @param  VersionNumber|string $b
  *         the RHS of this calcuation
  * @param  VersionParser|null $parser
  *         the parser to use if $a or $b are strings
  * @return boolean
  *         TRUE if $a ~= $b
  *         FALSE otherwise
  */
 public static function calculate($a, $b, VersionParser $parser = null)
 {
     $aObj = EnsureVersionNumber::from($a, $parser);
     $bObj = EnsureCompatibleVersionNumber::from($aObj, $b);
     $c = $bObj->getApproximateUpperBoundary();
     return InBetween::calculate($aObj, $bObj, $c);
 }
コード例 #5
0
 /**
  * @covers ::from
  * @dataProvider provideValidVersionsForDispatch
  */
 public function testCanBeCalledStatically($data, $expectedResult)
 {
     // ----------------------------------------------------------------
     // setup your test
     $parser = new ParseSemanticVersion();
     // ----------------------------------------------------------------
     // perform the change
     $actualResult = EnsureVersionNumber::from($data, $parser);
     // ----------------------------------------------------------------
     // test the results
     $this->assertEquals($expectedResult, $actualResult);
 }
コード例 #6
0
 /**
  * is $a the same version as $b, discounting the pre-release string?
  *
  * @param  VersionNumber|string $a
  *         the LHS of this calculation
  * @param  VersionNumber|string $b
  *         the RHS of this calculation
  * @param  VersionParser|null $parser
  *         the parser to use if $a or $b are strings
  * @return boolean
  *         TRUE if $a == $b (discounting pre-release string)
  *         FALSE otherwise
  */
 public static function calculate($a, $b, VersionParser $parser = null)
 {
     // make sure we have something we can use
     $aObj = EnsureVersionNumber::from($a, $parser);
     $bObj = EnsureCompatibleVersionNumber::from($aObj, $b, $parser);
     if ($aObj->getMajor() != $bObj->getMajor()) {
         return false;
     }
     if ($aObj->getMinor() != $bObj->getMinor()) {
         return false;
     }
     if ($aObj->getPatchLevel() != $bObj->getPatchLevel()) {
         return false;
     }
     return true;
 }
コード例 #7
0
 /**
  * is $a a pre-release of $b?
  *
  * @param  VersionNumber|string $a
  *         the LHS of this calculation
  * @param  VersionNumber|string $b
  *         the RHS of this calculation
  * @param  VersionParser|null $parser
  *         the parser to use if $a or $b are strings
  * @return boolean
  *         TRUE if $a < $b
  *         FALSE otherwise
  */
 public static function calculate($a, $b, VersionParser $parser = null)
 {
     $aObj = EnsureVersionNumber::from($a, $parser);
     $bObj = EnsureCompatibleVersionNumber::from($aObj, $b, $parser);
     // quickest test of all ... is $a a pre-release?
     if (!$aObj->hasPreRelease()) {
         return false;
     }
     return SameVersion::calculate($aObj, $bObj);
 }