private function addRewriterReferenceByPriority(array $rewriterReferences, $taggedServiceId, array $tag)
    {
        $priority = (
            array_key_exists(self::TAG_ATTRIBUTE_PRIORITY, $tag)
            ? (int) $tag[self::TAG_ATTRIBUTE_PRIORITY]
            : self::DEFAULT_PRIORITY
        );

        if (!array_key_exists($priority, $rewriterReferences)) {
            $rewriterReferences[$priority] = [];
        }

        $rewriterReferences[$priority][] = $this->referenceFactory->createReference($taggedServiceId);

        return $rewriterReferences;
    }