Extract stability.

@param  string  $version

@return mixed
962857
private function extractStability($version)
    {
        $stability = $this->getExplicitStability($version);

        if ($stability === null) {
            $stability = $this->getParsedStability($version);
        }

        return $stability;
    }
699254
public function match(Version $version)
    {
        $versionStabilityIndex = array_search($version->getStability(), Version::$stabilities);
        $constraintStabilityIndex = array_search($this->stability, Version::$stabilities);

        if ($this->compare($versionStabilityIndex, $constraintStabilityIndex) !== 0) {
            return false;
        }

        $numericValues = $version->numeric();
        $comparisons = array();

        foreach ($this->version as $i => $value) {
            $comparisons[$i] = $this->compare($numericValues[$i], $value);
        }

        switch ($this->operator) {
            case '=': case '==':
                // all parts must be equal:
                return array_filter($comparisons) === array();
                break;
            case '!': case '!=':
                // any part must be unequal:
                return array_filter($comparisons) !== array();
                break;
            case '>=':
            case '<=':
            case '>':
            case '<':
                // the first mismatch is the tie breaker
                $mismatches = array_filter($comparisons);
                if (!count($mismatches)) {
                    // if no mismatches, only ok if equality operator
                    return in_array($this->operator, array('<=', '>='));
                } else {
                    $first = array_shift($mismatches);
                    return
                           ($this->operator === '<'  && $first < 0)
                        || ($this->operator === '<=' && $first < 0)
                        || ($this->operator === '>'  && $first > 0)
                        || ($this->operator === '>=' && $first > 0)
                    ;
                }
        }

        throw new \UnexpectedValueException("An unknown edge case was encountered. Is the constraint valid?");
    }
172179
public function compare(SchemaVersion $version)
    {
        return version_compare(
            str_replace('-', '.', $this->toString()),
            str_replace('-', '.', $version->toString())
        );
    }
451551
public function isPartOf(Version $version)
    {
        if (is_null($version->getOperator()))
        {
            if ($this->major == $version->getMajor()  && $this->minor == $version->getMinor() && $this->path == $version->getPath())
                return true;
            return false;
        }

        switch ($version->getOperator())
        {
            case self::GREATER:
                return $this->mustGreaterThan($version);
                break;

            case self::GREATER_EQUAL:
                return $this->mustGreaterEqualThan($version);
                break;
            case self::TILDE:
                return $this->mustTilde($version);
                break;
        }
    }
311387
protected static function extractVersion(string $version, string $expression): ?string
    {
        if (preg_match($expression, $version, $result)) {
            return Arr::first($result);
        }

        return null;
    }
1016471
public function importVersion($version)
    {
        return $this
            ->setMajor($version->getMajor())
            ->setMinor($version->getMinor())
            ->setPatch($version->getPatch())
            ->setPreRelease($version->getPreRelease())
            ->setBuild($version->getBuild());
    }
439221
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;
    }
9182
private function getBranchAliases(ApiPackage\Version $version)
    {
        $extra = $version->getExtra();
        if (null !== $extra
            && isset($extra["branch-alias"])
            && is_array($extra["branch-alias"])
        ) {
            return $extra["branch-alias"];
        }

        return null;
    }
1305634
public function compareTo($version)
    {
        $cmp = self::parse($version);
        $result = $this->cmp($cmp, $this->numbers);
        if ($result === 0) {
            $result = $this->cmp($this->numbers, $cmp);
            $result = - $result;
        } else {
            return $result;
        }
        return $result;
    }
374592
protected function getFromHash($hash, $version)
    {
        return sprintf('%08s-%04s-%04x-%04x-%12s',
    		// 32 bits for "time_low"
    		substr($hash, 0, 8),
    		// 16 bits for "time_mid"
    		substr($hash, 8, 4),
    		// 16 bits for "time_hi_and_version",
    		// four most significant bits holds version number 4
    		(hexdec(substr($hash, 12, 4)) & 0x0fff) | $version << 12,
    		// 16 bits, 8 bits for "clk_seq_hi_res",
    		// 8 bits for "clk_seq_low",
    		// two most significant bits holds zero and one for variant DCE1.1
    		(hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
    		// 48 bits for "node"
    		substr($hash, 20, 12)
		);
    }
1089690
public function getNextTailVersion()
    {
        if (count($this->stabilityVersion) && $this->stabilityVersion[0] != 'stable') {
            return implode('.', $this->version);
        }
        $v = $this->version;
        $last = count($v) - 1;
        if ($v[$last] !== '*') {
            ++$v[$last];
        }

        return implode('.', $v);
    }
656162
protected function getVersionUrl(Version $version) : string
    {
        if (count($this->versionUrls) === 0) {
            $this->fetchSupportedVersions();
        }

        if (!array_key_exists($version->getAndroidVersion(), $this->versionUrls)) {
            throw new UnsupportedVersionException($version);
        }

        return $this->versionUrls[$version->getAndroidVersion()];
    }
954075
public static function parseStability($version)
    {
        $stability = parent::parseStability($version);

        return false !== strpos($version, '-patch') ? 'dev' : $stability;
    }
773964
public static function isValidProtocolVersion($version)
    {
        if (!is_string($version) || empty($version)) {
            return false;
        }

        return (bool) preg_match('#^(1\.[01]|2)$#', $version);
    }
928014
public static function parse($version, $options = array())
    {
        $options = array_merge(array(
            'removeWildcard' => true
        ), $options);

        // extract meta data
        $vers = explode('+', $version, 2);
        $metadata = '';
        if (count($vers) > 1) {
            $metadata = $vers[1];
        }
        $version = $vers[0];

        // extract secondary version
        $allVersions = preg_split('/(-|:)([0-9]+|\*)($|\.|-)/', $version, 2, PREG_SPLIT_DELIM_CAPTURE);
        $version = $allVersions[0];
        if (count($allVersions) > 1 && $allVersions[1] != '') {
            if ($allVersions[2] == '*' && $options['removeWildcard']) {
                $secondaryVersion = null;
                $secondaryVersionSeparator = '-';
            }
            else {
                $secondaryVersion = self::parse($allVersions[2].$allVersions[3].$allVersions[4], $options);
                $secondaryVersionSeparator = $allVersions[1];
            }
        }
        else {
            $secondaryVersion = null;
            $secondaryVersionSeparator = '-';
        }

        // extract stability part
        $vers = explode('-', $version, 2);
        $stabilityVersion = array();
        if (count($vers) > 1) {
            $stabilityVersion = explode('.', $vers[1]);
        }

        // extract version parts
        $vers = explode('.', $vers[0]);
        foreach ($vers as $k => $number) {
            if (!is_numeric($number)) {
                if (preg_match('/^([0-9]+)(.*)$/', $number, $m)) {
                    $vers[$k] = $m[1];
                    $stabilityVersion = array_merge(
                                            array($m[2]),
                                            array_slice($vers, $k + 1),
                                            $stabilityVersion
                                        );
                    $vers = array_slice($vers, 0, $k + 1);
                    break;
                } elseif ($number == '*') {
                    $vers = array_slice($vers, 0, $k);
                    if (!$options['removeWildcard']) {
                        $vers[$k] = '*';
                    }
                    break;
                } else {
                    throw new \Exception('Bad version syntax');
                }
            } else {
                $vers[$k] = intval($number);
            }
        }

        $stab = array();
        foreach ($stabilityVersion as $k => $part) {
            if (preg_match('/^[a-z]+$/', $part)) {
                $stab[] = self::normalizeStability($part);
            } elseif (preg_match('/^[0-9]+$/', $part)) {
                $stab[] = $part;
            } else {
                $m = preg_split('/([0-9]+)/', $part, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
                foreach ($m as $p) {
                    $stab[] = self::normalizeStability($p);
                }
            }
        }

        if (count($stab) == 0 && $secondaryVersion && !$options['removeWildcard']) {
            if ($secondaryVersion->getMajor() == '*' && $secondaryVersionSeparator == '-') {
                $secondaryVersion = null;
                $stab = array('*');
            }
        }

        return new Version($vers, $stab, $metadata, $secondaryVersion, $secondaryVersionSeparator);
    }
1278880
public function version($version = null)
    {
        if (func_num_args() === 0) {
            return $this->_version;
        }
        $this->_version = $version;
        return $this;
    }
519504
public function getFromRevision($version, $key)
    {
        return ($this->isPassedThrough($key))
            ? $this->passThrough($version, $key)
            : array_get($this->{$version}, $key);
    }