protected function replaceSelfVersionDependencies(
        $type,
        array $links,
        RootPackageInterface $root
    ) {
        $linkType = BasePackage::$supportedLinkTypes[$type];
        $version = $root->getVersion();
        $prettyVersion = $root->getPrettyVersion();
        $vp = $this->versionParser;

        $method = 'get' . ucfirst($linkType['method']);
        $packages = $root->$method();

        return array_map(
            function ($link) use ($linkType, $version, $prettyVersion, $vp, $packages) {
                if ('self.version' === $link->getPrettyConstraint()) {
                    if (isset($packages[$link->getSource()])) {
                        /** @var Link $package */
                        $package = $packages[$link->getSource()];
                        return new Link(
                            $link->getSource(),
                            $link->getTarget(),
                            $vp->parseConstraints($package->getConstraint()->getPrettyString()),
                            $linkType['description'],
                            $package->getPrettyConstraint()
                        );
                    }

                    return new Link(
                        $link->getSource(),
                        $link->getTarget(),
                        $vp->parseConstraints($version),
                        $linkType['description'],
                        $prettyVersion
                    );
                }
                return $link;
            },
            $links
        );
    }