public function replaceEdge($graph, $edgeId, $label, Edge $document, array $options = [], $collection = null)
    {
        if ($graph instanceof Graph) {
            $graph = $graph->getKey();
        }
        $parts = explode('/', $edgeId);
        if (count($parts) === 2) {
            list($collection, $edgeId) = $parts;
        }

        if ($collection === null) {
            $edgeCollections      = $this->getEdgeCollections($graph);
            $edgeCollectionsCount = count($edgeCollections);
            if ($edgeCollectionsCount !== 1) {
                throw new ClientException('A collection must be provided.');
            }

            if ($edgeCollectionsCount === 1) {
                $collection = $edgeCollections[0];
            }
        }

        $options = array_merge([self::OPTION_REVISION => false], $options);

        $params = $this->includeOptionsInParams(
            $options, [
                'waitForSync' => $this->getConnectionOption(ConnectionOptions::OPTION_WAIT_SYNC),
                'silent'      => false,
                'ignoreRevs'  => true,
                'policy'      => $this->getConnectionOption(ConnectionOptions::OPTION_REPLACE_POLICY),
            ]
        );

        //Include the revision for conditional updates if required
        $headers = [];
        if ($options[self::OPTION_REVISION] === true) {
            $revision = $document->getRevision();

            if (null !== $revision) {
                $params['ignoreRevs'] = false;
                $headers['if-match']  = '"' . $revision . '"';
            }
        } elseif ($options[self::OPTION_REVISION]) {
            $revision             = $options[self::OPTION_REVISION];
            $params['ignoreRevs'] = false;
            $headers['if-match']  = '"' . $revision . '"';
        }

        $data = $document->getAllForInsertUpdate();
        if (null !== $label) {
            $document->set('$label', $label);
        }

        $url = UrlHelper::buildUrl(Urls::URL_GRAPH, [$graph, Urls::URLPART_EDGE, $collection, $edgeId]);
        $url = UrlHelper::appendParamsUrl($url, $params);

        $response = $this->getConnection()->put($url, $this->json_encode_wrapper($data), $headers);

        $jsonArray = $response->getJson();
        $edge      = $jsonArray['edge'];

        $document->setInternalId($edge[Edge::ENTRY_ID]);
        $document->setRevision($edge[Edge::ENTRY_REV]);

        return true;
    }