• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openzipkin / zipkin-php / #597

pending completion
#597

push

php-coveralls

web-flow
Convert carrier key to string. (#226)

1 of 1 new or added line in 1 file covered. (100.0%)

811 of 997 relevant lines covered (81.34%)

10.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.18
/src/Zipkin/Reporters/Http/CurlFactory.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Zipkin\Reporters\Http;
6

7
use RuntimeException;
8
use BadFunctionCallException;
9

10
final class CurlFactory implements ClientFactory
11
{
12
    private function __construct()
13
    {
14
    }
6✔
15

16
    /**
17
     * @return CurlFactory
18
     * @throws \BadFunctionCallException if the curl extension is not installed.
19
     */
20
    public static function create(): self
21
    {
22
        if (!\function_exists('curl_init')) {
6✔
23
            throw new BadFunctionCallException('cURL is not enabled');
×
24
        }
25

26
        return new self();
6✔
27
    }
28

29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function build(array $options): callable
33
    {
34
        /**
35
         * @param string $payload
36
         * @throws RuntimeException
37
         * @return void
38
         */
39
        return static function (string $payload) use ($options): void {
6✔
40
            $handle = \curl_init($options['endpoint_url']);
6✔
41
            if ($handle === false) {
6✔
42
                throw new RuntimeException(
×
43
                    \sprintf('failed to create the handle for url "%s"', $options['endpoint_url'])
×
44
                );
×
45
            }
46

47
            \curl_setopt($handle, CURLOPT_POST, 1);
6✔
48
            \curl_setopt($handle, CURLOPT_POSTFIELDS, $payload);
6✔
49
            \curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
6✔
50
            $requiredHeaders = [
6✔
51
                'Content-Type' => 'application/json',
6✔
52
                'Content-Length' => \strlen($payload),
6✔
53
                'b3' => '0',
6✔
54
            ];
6✔
55
            $additionalHeaders = $options['headers'] ?? [];
6✔
56
            $headers = \array_merge($additionalHeaders, $requiredHeaders);
6✔
57
            $formattedHeaders = \array_map(function ($key, $value) {
6✔
58
                return $key . ': ' . $value;
6✔
59
            }, \array_keys($headers), $headers);
6✔
60
            \curl_setopt($handle, CURLOPT_HTTPHEADER, $formattedHeaders);
6✔
61

62
            if (isset($options['timeout'])) {
6✔
63
                \curl_setopt($handle, CURLOPT_TIMEOUT, $options['timeout']);
×
64
            }
65

66
            if (\curl_exec($handle) !== false) {
6✔
67
                $statusCode = \curl_getinfo($handle, CURLINFO_HTTP_CODE);
5✔
68
                \curl_close($handle);
5✔
69

70
                if ($statusCode !== 202) {
5✔
71
                    throw new RuntimeException(
5✔
72
                        \sprintf('Reporting of spans failed, status code %d', $statusCode)
5✔
73
                    );
5✔
74
                }
75
            } else {
76
                throw new RuntimeException(\sprintf(
1✔
77
                    'Reporting of spans failed: %s, error code %s',
1✔
78
                    \curl_error($handle),
1✔
79
                    \curl_errno($handle)
1✔
80
                ));
1✔
81
            }
82
        };
6✔
83
    }
84
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc