Inpsyde\MultilingualPress\Common\Type\SemanticVersionNumber::format_version PHP Method

format_version() private method

Formats the given number according to the Semantic Versioning specification.
See also: http://semver.org/#semantic-versioning-specification-semver
private format_version ( string $version ) : string
$version string Version number string.
return string Semantic version number string.
    private function format_version($version)
    {
        if (preg_match('~^\\d+\\.\\d+\\.\\d+~', $version)) {
            return $version;
        }
        // Semantic Versioning at least requires the format "X.Y.Z" with X, Y and Z being non-negative integers.
        $parts = [0, 0, 0];
        $replace = true;
        foreach (explode('.', $version) as $index => $level) {
            if ($index < 3 && $replace) {
                if (is_numeric($level)) {
                    $parts[$index] = (int) $level;
                    continue;
                }
                // Since this is a non-numeric part, all other parts will be appended (and not update existing levels).
                $replace = false;
            }
            $parts[] = $level;
        }
        return join('.', $parts);
    }