public function compareTo($version)
    {
        $major = $version->getMajor();
        $minor = $version->getMinor();
        $patch = $version->getPatch();
        $pre = $version->getPreRelease();
        $build = $version->getBuild();

        switch (true) {
            case ($this->major < $major):
                return 1;
            case ($this->major > $major):
                return -1;
            case ($this->minor > $minor):
                return -1;
            case ($this->minor < $minor):
                return 1;
            case ($this->patch > $patch):
                return -1;
            case ($this->patch < $patch):
                return 1;
            // @codeCoverageIgnoreStart
        }
        // @codeCoverageIgnoreEnd

        if ($pre || $this->pre) {
            if (empty($this->pre) && $pre) {
                return -1;
            }

            if ($this->pre && empty($pre)) {
                return 1;
            }

            if (0 !== ($weight = $this->precedence($this->pre, $pre))) {
                return $weight;
            }
        }

        if ($build || $this->build) {
            if ((null === $this->build) && $build) {
                return 1;
            }

            if ($this->build && (null === $build)) {
                return -1;
            }

            return $this->precedence($this->build, $build);
        }

        return 0;
    }