Exemplo n.º 1
0
 /**
  * Build a label from a token list.
  *
  * @param Token[] $versionTokenList
  * @param Token[] $labelTokenList
  *
  * @return VersionInterface|null
  */
 public function buildFromTokens(array $versionTokenList, array $labelTokenList)
 {
     $minor = 0;
     $patch = 0;
     $label = null;
     switch (count($versionTokenList)) {
         // Major Only
         case 1:
             $major = $versionTokenList[0]->getValue();
             break;
             // Major, minor
         // Major, minor
         case 3:
             $major = $versionTokenList[0]->getValue();
             $minor = $versionTokenList[2]->getValue();
             break;
             // Major, minor, patch
         // Major, minor, patch
         case 5:
             $major = $versionTokenList[0]->getValue();
             $minor = $versionTokenList[2]->getValue();
             $patch = $versionTokenList[4]->getValue();
             break;
         default:
             throw new \RuntimeException('Invalid version');
     }
     return new Version($major, $minor, $patch, $this->labelBuilder->buildFromTokens($labelTokenList));
 }
Exemplo n.º 2
0
 public function testCreateAbsent()
 {
     $builder = new LabelBuilder();
     $label = $builder->build();
     $this->assertEquals(new Label(Label::PRECEDENCE_ABSENT), $label);
 }
 /**
  * Determines the correct upper version constraint for a hyphenated range.
  *
  * @param Token[] $versionTokenList
  * @param Token[] $labelTokenList
  *
  * @return VersionRangeInterface
  */
 private function getUpperConstraint(array $versionTokenList, array $labelTokenList = array())
 {
     $minor = 0;
     $patch = 0;
     $label = null;
     $labelBuilder = new LabelBuilder();
     switch (count($versionTokenList)) {
         case 1:
             $comparator = $this->lessThan;
             $major = $versionTokenList[0]->getValue() + 1;
             break;
         case 3:
             $comparator = $this->lessThan;
             $major = $versionTokenList[0]->getValue();
             $minor = $versionTokenList[2]->getValue() + 1;
             break;
         case 5:
             $comparator = $this->lessOrEqualTo;
             $major = $versionTokenList[0]->getValue();
             $minor = $versionTokenList[2]->getValue();
             $patch = $versionTokenList[4]->getValue();
             break;
         default:
             throw new \RuntimeException('Invalid version');
     }
     return new ComparatorVersion($comparator, new Version($major, $minor, $patch, $labelBuilder->buildFromTokens($labelTokenList)));
 }