Example #1
0
 /**
  * @param string $simple
  * @return Primitive[] Collection of primitives matching the simple expression.
  */
 public static function parseSimpleExpression($simple)
 {
     if (!preg_match(self::REGEX_SIMPLE_EXPRESSION, $simple ?: '*', $parts)) {
         throw SemverException::format('Could not parse simple constraint "%s"', $simple);
     }
     $operator = $parts[1];
     $partial = str_replace(['*', 'x', 'X'], '*', $parts[3]);
     $qualifier = $parts[4];
     // Redirect leading wildcard into the universal wildcard primitive right away
     if ($partial[0] === '*') {
         return [Primitive::getWildcard()];
     }
     return PrimitiveGenerator::getInstance()->generate($operator, self::expandXRs($partial, $qualifier));
 }
Example #2
0
 /**
  * @expectedException \Omines\Semver\Exception\SemverException
  * @expectedExceptionMessage Invalid primitive operator "invalid"
  */
 public function testInvalidOperatorThrows()
 {
     $primitive = new Primitive('1.0.0', 'invalid');
     $primitive->matches(Version::fromString('1.2.0'));
 }