Repository: symfony/symfony
File: src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php (PHP)

Code before:
        $host = $request->server->get('HTTP_HOST', $request->server->get('SERVER_NAME', 'localhost'));
        $url = $scheme.'://'.$host.$request->getRequestUri();

        if (!empty($request->query->all())) {
            $url .= '?'.http_build_query($request->query->all());
        }

        // Add HTTP method
        $method = $request->getMethod();
        switch ($method) {
            case Request::METHOD_HEAD:
                $command[] = '--head';
                break;
            case Request::METHOD_GET:
                break;
            default:
                $command[] = \sprintf('--request %s', $method);
        }

        $command[] = \sprintf('--url %s', escapeshellarg($url));

        // Add headers
        foreach ($request->headers->all() as $name => $value) {
            if (\is_array($value)) {
                $value = implode(', ', $value);
            }

            // Skip certain headers
            if (\in_array(strtolower($name), ['host', 'cookie'])) {
                continue;
            }

            $command[] = '--header '.escapeshellarg(ucwords($name, '-').': '.$value);
        }

        // Add cookies
        if (!empty($request->cookies->all())) {
            $cookies = [];
            foreach ($request->cookies->all() as $name => $value) {
                $cookies[] = $name.'='.$value;
            }
            $command[] = '--header '.escapeshellarg('Cookie: '.implode('; ', $cookies));
        }

        // Add body data
        $content = $this->data['content'];
        if (!empty($content) && \in_array($method, [Request::METHOD_POST, Request::METHOD_PUT, Request::METHOD_PATCH, Request::METHOD_DELETE])) {
            $command[] = '--data-raw '.$this->escapePayload($content);
        }

        return implode(" \\\n  ", $command);

Review comment (suggestion):
```suggestion
            $value = implode(', ', $value ?? []);
```

Code after:
        if (Request::METHOD_HEAD === $method) {
            $command[] = '--head';
        } elseif (Request::METHOD_GET !== $method) {
            $command[] = \sprintf('--request %s', $method);
        }

        $command[] = \sprintf('--url %s', escapeshellarg($request->getUri()));

        foreach ($request->headers->all() as $name => $values) {
            if (\in_array(strtolower($name), ['host', 'cookie'], true)) {
                continue;
            }

            $command[] = '--header '.escapeshellarg(ucwords($name, '-').': '.implode(', ', $values));
        }

        if ($request->cookies->all()) {
            $cookies = [];
            foreach ($request->cookies->all() as $name => $value) {
                $cookies[] = urlencode($name).'='.urlencode($value);
            }
            $command[] = '--cookie '.escapeshellarg(implode('; ', $cookies));
        }

        if ($content && \in_array($method, [Request::METHOD_POST, Request::METHOD_PUT, Request::METHOD_PATCH, Request::METHOD_DELETE], true)) {
            $command[] = '--data-raw '.$this->escapePayload($content);
        }

        return implode(" \\\n  ", $command);
    }

    public function getCurlCommand(): string
    {
        return $this->data['curlCommand'] ?? '';
    }

    private function escapePayload(string $payload): string
    {
        static $useProcess;

        if ($useProcess ??= \function_exists('proc_open') && class_exists(Process::class)) {
            return substr((new Process(['', $payload]))->getCommandLine(), 3);
        }

        if ('\\' === \DIRECTORY_SEPARATOR) {
            return '"'.str_replace('"', '""', $payload).'"';
        }

        return "'".str_replace("'", "'\\''", $payload)."'";
    }
}