Esempio n. 1
0
 /**
  * @inheritdoc
  */
 public function doResolve($alias, Collection $collection)
 {
     // exit early if there's a full match
     if ($collection->contains($alias)) {
         return $collection->get($alias);
     }
     // lazy id search
     $length = strlen($alias);
     $candidate = null;
     foreach ($collection as $key => $version) {
         if (substr($key, 0, $length) === $alias) {
             if (null === $candidate) {
                 // make this version a candidate, but continue searching to see if any other items also meet the
                 // condition (in which case we'd know the $id being searched for is "ambiguous")
                 $candidate = $version;
             } else {
                 // the $id is ambiguous when used for lazy matching, therefore:
                 $candidate = null;
                 // remove the candidate
                 break;
             }
         }
     }
     return $candidate;
 }
Esempio n. 2
0
 /**
  * @{inheritdoc}
  *
  * IMPROVE: this method has an NPath complexity of 400. The configured NPath complexity threshold is 200.
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  *
  * @param string $alias
  * @param Collection $collection
  *
  * @return DeltaInterface|null
  */
 protected function doResolve($alias, Collection $collection)
 {
     // parse alias
     $matches = [];
     if (!preg_match(self::PATTERN, $alias, $matches)) {
         return null;
     }
     list(, $newAlias, $operator) = $matches;
     // resolve the new alias (this will allow to resolve e.g. HEAD-1)
     $absoluteVersion = $collection->get($newAlias);
     if (null === $absoluteVersion) {
         return null;
     }
     // calculate the offset
     $count = !isset($matches[3]) ? strlen($operator) : (int) $matches[3];
     if (strlen($operator) > 1) {
         $operator = substr($operator, 0, 1);
     }
     $multiplier = $operator === '+' ? 1 : -1;
     $offset = $count * $multiplier;
     // find version by absolute getPosition + offset
     $absolutePos = $collection->getPosition($absoluteVersion);
     return $collection->getByPosition($absolutePos + $offset);
 }