private function replaceParameters(ContainerInterface $container, $argument)
    {
        if (preg_match('/^(?<!%)%([^%]+)%(?!%)$/', $argument, $matches)) {
            $replaced = $matches[1];

            if ($container->hasParameter($replaced)) {
                return $container->getParameter($replaced);
            }

            return $replaced;
        }
        
        return preg_replace_callback(
            '/(?<!%)%([^%]+)%(?!%)/',
            function ($matches) use ($container) {
                $parameter = $container->getParameter($matches[1]);

                if (is_array($parameter)) {
                    throw new InvalidArgumentException(
                        'Cannot reference a collection-type parameter with string interpolation.'
                    );
                }

                return $parameter;
            },
            $argument
        );
    }