示例#1
0
 /**
  * @param ValuesBag                $valuesBag
  * @param ValueComparisonInterface $comparison
  * @param array                    $options
  */
 private function removeDuplicateMatchers(ValuesBag $valuesBag, ValueComparisonInterface $comparison, array $options)
 {
     /** @var PatternMatch[] $matchers */
     $matchers = $valuesBag->get(PatternMatch::class);
     foreach ($matchers as $i => $value) {
         foreach ($matchers as $c => $value2) {
             if ($i === $c) {
                 continue;
             }
             if ($value->isCaseInsensitive() === $value2->isCaseInsensitive() && $value->getType() === $value2->getType() && $comparison->isEqual($value->getValue(), $value2->getValue(), $options)) {
                 $valuesBag->remove(PatternMatch::class, $i);
                 unset($matchers[$i]);
             }
         }
     }
 }
示例#2
0
 /**
  * Optimizes connected ranges.
  *
  * A range is connected when the upper-bound is equal to the lower-bound of the
  * second range, but only when the bounds inclusiveness are equal they can be optimized.
  *
  * @param Range[]                  $ranges
  * @param ValuesBag                $valuesBag
  * @param ValueComparisonInterface $comparison
  * @param array                    $options
  */
 private function optimizeConnectedRanges(array $ranges, ValuesBag $valuesBag, ValueComparisonInterface $comparison, array $options, $exclude = false)
 {
     $class = $exclude ? ExcludedRange::class : Range::class;
     foreach ($ranges as $i => $range) {
         // If the range is already removed just ignore it.
         if (!isset($ranges[$i])) {
             continue;
         }
         foreach ($ranges as $c => $value) {
             if ($i === $c) {
                 continue;
             }
             if ($range->isLowerInclusive() !== $value->isLowerInclusive() || $range->isUpperInclusive() !== $value->isUpperInclusive()) {
                 continue;
             }
             if ($comparison->isEqual($range->getUpper(), $value->getLower(), $options)) {
                 $newRange = new $class($range->getLower(), $value->getUpper(), $range->isLowerInclusive(), $range->isUpperInclusive(), $range->getViewLower(), $value->getViewUpper());
                 $valuesBag->remove($class, $i);
                 $valuesBag->remove($class, $c);
                 $valuesBag->add($newRange);
                 unset($ranges[$i], $ranges[$c]);
             }
         }
     }
 }