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

FriendsOfOpenTelemetry / opentelemetry-bundle / 7408750668

04 Jan 2024 11:07AM UTC coverage: 77.097% (-0.2%) from 77.27%
7408750668

push

github

gaelreyrol
refactor(otel/exporter): use Zenstruck\Dsn&Uri for ExporterDsn

13 of 15 new or added lines in 1 file covered. (86.67%)

1195 of 1550 relevant lines covered (77.1%)

13.14 hits per line

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

89.66
/src/OpenTelemetry/Exporter/ExporterDsn.php
1
<?php
2

3
namespace FriendsOfOpenTelemetry\OpenTelemetryBundle\OpenTelemetry\Exporter;
4

5
use Zenstruck\Dsn;
6
use Zenstruck\Uri;
7

8
final class ExporterDsn
9
{
10
    private function __construct(
11
        private readonly Uri $uri,
12
    ) {
13
    }
258✔
14

15
    public static function fromString(#[\SensitiveParameter] string $dsn): self
16
    {
17
        try {
18
            $parsedDsn = Dsn::parse($dsn);
274✔
19
        } catch (Dsn\Exception\UnableToParse $exception) {
12✔
20
            throw new \InvalidArgumentException('The DSN is invalid.', previous: $exception);
12✔
21
        }
22

23
        if (false === $parsedDsn instanceof Uri) {
262✔
NEW
24
            throw new \InvalidArgumentException('The DSN is not an Uri.');
×
25
        }
26

27
        if (true === $parsedDsn->scheme()->isEmpty()) {
262✔
28
            throw new \InvalidArgumentException('The DSN must contain a scheme.');
2✔
29
        }
30

31
        if (true === $parsedDsn->host()->isEmpty()) {
260✔
32
            throw new \InvalidArgumentException('The DSN must contain a host (use "default" by default).');
2✔
33
        }
34

35
        return new self($parsedDsn);
258✔
36
    }
37

38
    public function getScheme(): string
39
    {
NEW
40
        return $this->uri->scheme()->toString();
×
41
    }
42

43
    public function getHost(): string
44
    {
45
        return $this->uri->host()->toString();
152✔
46
    }
47

48
    public function getUser(): ?string
49
    {
50
        return $this->uri->username();
152✔
51
    }
52

53
    public function getPassword(): ?string
54
    {
55
        return $this->uri->password();
24✔
56
    }
57

58
    public function getPath(): ?string
59
    {
60
        return $this->uri->path()->isEmpty() ? null : $this->uri->path()->toString();
180✔
61
    }
62

63
    public function getPort(int $default = null): ?int
64
    {
65
        return $this->uri->port() ?? $default;
152✔
66
    }
67

68
    /**
69
     * @return string[]
70
     */
71
    private function parseScheme(): array
72
    {
73
        return $this->uri->scheme()->segments();
242✔
74
    }
75

76
    public function getExporter(): string
77
    {
78
        $parts = $this->parseScheme();
242✔
79

80
        $exporter = null;
242✔
81
        if (2 === count($parts)) {
242✔
82
            $exporter = $parts[1];
206✔
83
        }
84
        if (1 === count($parts)) {
242✔
85
            $exporter = $parts[0];
36✔
86
        }
87

88
        if ('' === $exporter || null === $exporter) {
242✔
89
            throw new \InvalidArgumentException('The DSN scheme does not contain an exporter.');
×
90
        }
91

92
        return $exporter;
242✔
93
    }
94

95
    public function getTransport(): ?string
96
    {
97
        $parts = $this->parseScheme();
194✔
98

99
        return 2 === count($parts) ? $parts[0] : null;
194✔
100
    }
101
}
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

© 2026 Coveralls, Inc