private function validateMetadataContainer($metadata, &$type = null, &$bag = null)
    {
        // If variables are provided, clear existing values.
        $type = null;
        $bag  = null;

        if (is_array($metadata)) {
            $type = 'array';
            $bag  = $metadata;
            return true;
        }

        if (is_a($metadata, MetadataInterface::class, true)) {
            if (is_object($metadata)) {
                $type = get_class($metadata);
                $bag  = $metadata;
                return true;
            }
            if (is_string($metadata)) {
                $type = $metadata;
                return true;
            }
        }

        return false;
    }