/** * Find the lowest stability. * * @param string[] $stabilities The list of stability * @param VersionParser $versionParser The version parser * * @return string The lowest stability */ public static function findInlineStabilities(array $stabilities, VersionParser $versionParser) { $lowestStability = 'stable'; foreach ($stabilities as $stability) { $stability = $versionParser->normalizeStability($stability); $stability = $versionParser->parseStability($stability); if (Package::$stabilities[$stability] > Package::$stabilities[$lowestStability]) { $lowestStability = $stability; } } return $lowestStability; }
/** * Validates the tag. * * @param string $tag * @param AssetTypeInterface $assetType * @param VersionParser|null $parser * * @return false|string */ public static function validateTag($tag, AssetTypeInterface $assetType, VersionParser $parser = null) { if (in_array($tag, array('master', 'trunk', 'default'))) { return false; } if (null === $parser) { $parser = new VersionParser(); } try { $tag = $assetType->getVersionConverter()->convertVersion($tag); $tag = $parser->normalize($tag); } catch (\Exception $e) { $tag = false; } return $tag; }
/** * Initialize the installed package. */ private function initInstalledPackages() { /* @var PackageInterface $package */ foreach ($this->installedRepository->getPackages() as $package) { $operator = $this->getFilterOperator($package); /* @var Link $link */ $link = current($this->versionParser->parseLinks($this->package->getName(), $this->package->getVersion(), 'installed', array($package->getName() => $operator . $package->getPrettyVersion()))); $link = $this->includeRootConstraint($package, $link); $this->requires[$package->getName()] = $link; } }
/** * Clean the raw version. * * @param string $version The version * @param array $matches The match of pattern asset version * * @return array The list of $type, $version and $end */ protected static function cleanVersion($version, array $matches) { $end = substr($version, strlen($matches[1][0][0])); $version = $matches[1][0][0] . '-'; $matches = array(); if (preg_match('/^(\\-|\\+)/', $end, $matches)) { $end = substr($end, 1); } $matches = array(); preg_match('/^[a-z]+/', $end, $matches); $type = isset($matches[0]) ? VersionParser::normalizeStability($matches[0]) : null; $end = substr($end, strlen($type)); return array($type, $version, $end); }
/** * Convert the installed package data tests to mock package instance. * * @param array $installed The config of installed packages * * @return array The package instance of installed packages */ protected function convertInstalled(array $installed) { $packages = array(); $parser = new VersionParser(); foreach ($installed as $name => $version) { $package = $this->getMockBuilder('Composer\\Package\\PackageInterface')->getMock(); $package->expects($this->any())->method('getName')->will($this->returnValue($name)); $package->expects($this->any())->method('getVersion')->will($this->returnValue($parser->normalize($version))); $package->expects($this->any())->method('getPrettyVersion')->will($this->returnValue($version)); $packages[] = $package; } return $packages; }
/** * Normalize the alias of branch. * * @param PackageInterface $package The package instance * * @return string The alias branch name */ protected function normalizeBranchAlias(PackageInterface $package) { $stability = VersionParser::parseStability($this->versionParser->normalize($this->rootPackageVersion)); $aliasNormalized = 'dev-' . $this->rootPackageVersion; if (BasePackage::STABILITY_STABLE === BasePackage::$stabilities[$stability] && null === $this->findPackage($package->getName(), $this->rootPackageVersion)) { $aliasNormalized = $this->versionParser->normalize($this->rootPackageVersion); } return $aliasNormalized; }
/** * Check if the require dependency has a satisfactory stability. * * @param Link $require The require link defined in root package * @param string $normalizedVersion The normalized version * * @return bool */ protected function satisfyStability(Link $require, $normalizedVersion) { $requireStability = $this->getRequireStability($require); $stability = $this->versionParser->parseStability($normalizedVersion); return Package::$stabilities[$stability] <= Package::$stabilities[$requireStability]; }