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

basis-company / nats.php / 23217248396

17 Mar 2026 09:28PM UTC coverage: 95.082% (+0.03%) from 95.05%
23217248396

push

github

nekufa
connection get message default timeout

7 of 8 new or added lines in 1 file covered. (87.5%)

33 existing lines in 3 files now uncovered.

1450 of 1525 relevant lines covered (95.08%)

77.94 hits per line

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

94.83
/src/Stream/Configuration.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Basis\Nats\Stream;
6

7
use DomainException;
8

9
class Configuration
10
{
11
    private array $subjects = [];
12
    private bool $allowRollupHeaders = true;
13
    private bool $denyDelete = true;
14
    private int $maxAge = 0;
15
    private int $maxConsumers = -1;
16
    private int $replicas = 1;
17
    private string $discardPolicy = DiscardPolicy::OLD;
18
    private string $retentionPolicy = RetentionPolicy::LIMITS;
19
    private string $storageBackend = StorageBackend::FILE;
20

21
    private ?float $duplicateWindow = null;
22
    private ?int $maxBytes = null;
23
    private ?int $maxMessageSize = null;
24
    private ?int $maxMessagesPerSubject = null;
25
    private ?string $description = null;
26
    private ?array $consumerLimits = null;
27
    private ?bool $allowMsgSchedules = null;
28

29
    public function __construct(
124✔
30
        public readonly string $name
31
    ) {
32
    }
124✔
33

34
    public function fromArray(array $array): self
8✔
35
    {
36
        return $this
8✔
37
            ->setDiscardPolicy($array['discard'])
8✔
38
            ->setMaxConsumers($array['max_consumers'])
8✔
39
            ->setReplicas($array['replicas'] ?? $array['num_replicas'])
8✔
40
            ->setRetentionPolicy($array['retention'])
8✔
41
            ->setStorageBackend($array['storage'])
8✔
42
            ->setSubjects($array['subjects']);
8✔
43
    }
44

45
    public function getAllowRollupHeaders(): bool
96✔
46
    {
47
        return $this->allowRollupHeaders;
96✔
48
    }
49

50
    public function getDescription(): ?string
96✔
51
    {
52
        return $this->description;
96✔
53
    }
54

55
    public function getDenyDelete(): bool
96✔
56
    {
57
        return $this->denyDelete;
96✔
58
    }
59

60
    public function getDiscardPolicy(): string
96✔
61
    {
62
        return $this->discardPolicy;
96✔
63
    }
64

65
    public function getDuplicateWindow(): ?float
96✔
66
    {
67
        return $this->duplicateWindow;
96✔
68
    }
69

70
    public function getMaxAge(): int
100✔
71
    {
72
        return $this->maxAge;
100✔
73
    }
74

75
    public function getMaxBytes(): ?int
100✔
76
    {
77
        return $this->maxBytes;
100✔
78
    }
79

80
    public function getMaxConsumers(): int
96✔
81
    {
82
        return $this->maxConsumers;
96✔
83
    }
84

85
    public function getMaxMessageSize(): ?int
100✔
86
    {
87
        return $this->maxMessageSize;
100✔
88
    }
89

90
    public function getMaxMessagesPerSubject(): ?int
100✔
91
    {
92
        return $this->maxMessagesPerSubject;
100✔
93
    }
94

95
    public function getName()
108✔
96
    {
97
        return $this->name;
108✔
98
    }
99

100
    public function getReplicas(): int
100✔
101
    {
102
        return $this->replicas;
100✔
103
    }
104

105
    public function getRetentionPolicy(): string
96✔
106
    {
107
        return $this->retentionPolicy;
96✔
108
    }
109

110
    public function getStorageBackend(): string
96✔
111
    {
112
        return $this->storageBackend;
96✔
113
    }
114

115
    public function getSubjects(): array
100✔
116
    {
117
        return $this->subjects;
100✔
118
    }
119

120
    public function setAllowRollupHeaders(bool $allowRollupHeaders): self
20✔
121
    {
122
        $this->allowRollupHeaders = $allowRollupHeaders;
20✔
123
        return $this;
20✔
124
    }
125

126
    public function setDenyDelete(bool $denyDelete): self
20✔
127
    {
128
        $this->denyDelete = $denyDelete;
20✔
129
        return $this;
20✔
130
    }
131

132
    public function setDiscardPolicy(string $policy): self
32✔
133
    {
134
        $this->discardPolicy = DiscardPolicy::validate($policy);
32✔
135
        return $this;
28✔
136
    }
137

138
    public function setDuplicateWindow(?float $seconds): self
4✔
139
    {
140
        $this->duplicateWindow = $seconds;
4✔
141
        return $this;
4✔
142
    }
143

144
    /**
145
     * set the max age in nanoSeconds
146
     */
147
    public function setMaxAge(int $maxAgeNanoSeconds): self
24✔
148
    {
149
        $this->maxAge = $maxAgeNanoSeconds;
24✔
150
        return $this;
24✔
151
    }
152

153
    public function setMaxBytes(?int $maxBytes): self
20✔
154
    {
155
        $this->maxBytes = $maxBytes;
20✔
156
        return $this;
20✔
157
    }
158

159
    public function setMaxConsumers(int $maxConsumers): self
8✔
160
    {
161
        $this->maxConsumers = $maxConsumers;
8✔
162
        return $this;
8✔
163
    }
164

165
    public function setMaxMessageSize(?int $maxMessageSize): self
20✔
166
    {
167
        $this->maxMessageSize = $maxMessageSize;
20✔
168
        return $this;
20✔
169
    }
170

171
    public function setMaxMessagesPerSubject(?int $maxMessagesPerSubject): self
20✔
172
    {
173
        $this->maxMessagesPerSubject = $maxMessagesPerSubject;
20✔
174
        return $this;
20✔
175
    }
176

177
    public function setReplicas(int $replicas): self
28✔
178
    {
179
        $this->replicas = $replicas;
28✔
180
        return $this;
28✔
181
    }
182

183
    public function setRetentionPolicy(string $policy): self
60✔
184
    {
185
        $this->retentionPolicy = RetentionPolicy::validate($policy);
60✔
186
        return $this;
56✔
187
    }
188

189
    public function setStorageBackend(string $storage): self
24✔
190
    {
191
        $this->storageBackend = StorageBackend::validate($storage);
24✔
192
        return $this;
20✔
193
    }
194

195
    public function setSubjects(array $subjects): self
96✔
196
    {
197
        $this->subjects = $subjects;
96✔
198
        return $this;
96✔
199
    }
200

201
    public function setConsumerLimits(array $consumerLimits): self
4✔
202
    {
203
        $this->consumerLimits = ConsumerLimits::validate($consumerLimits);
4✔
204
        return $this;
4✔
205
    }
206

207
    public function getConsumerLimits(): ?array
96✔
208
    {
209
        return $this->consumerLimits;
96✔
210
    }
211

UNCOV
212
    public function setAllowMsgSchedules(?bool $allowMsgSchedules): void
×
213
    {
UNCOV
214
        $this->allowMsgSchedules = $allowMsgSchedules;
×
215
    }
216

217
    public function getAllowMsgSchedules(): ?bool
96✔
218
    {
219
        return $this->allowMsgSchedules;
96✔
220
    }
221

222
    public function toArray(): array
96✔
223
    {
224
        $config = [
96✔
225
            'allow_rollup_hdrs' => $this->getAllowRollupHeaders(),
96✔
226
            'deny_delete' => $this->getDenyDelete(),
96✔
227
            'description' => $this->getDescription(),
96✔
228
            'discard' => $this->getDiscardPolicy(),
96✔
229
            'duplicate_window' => $this->getDuplicateWindow() * 1_000_000_000,
96✔
230
            'max_age' => $this->getMaxAge(),
96✔
231
            'max_bytes' => $this->getMaxBytes(),
96✔
232
            'max_consumers' => $this->getMaxConsumers(),
96✔
233
            'max_msg_size' => $this->getMaxMessageSize(),
96✔
234
            'max_msgs_per_subject' => $this->getMaxMessagesPerSubject(),
96✔
235
            'name' => $this->getName(),
96✔
236
            'num_replicas' => $this->getReplicas(),
96✔
237
            'retention' => $this->getRetentionPolicy(),
96✔
238
            'storage' => $this->getStorageBackend(),
96✔
239
            'subjects' => $this->getSubjects(),
96✔
240
            'consumer_limits' => $this->getConsumerLimits(),
96✔
241
            'allow_msg_schedules' => $this->getAllowMsgSchedules(),
96✔
242
        ];
96✔
243

244
        foreach ($config as $k => $v) {
96✔
245
            if ($v === null) {
96✔
246
                unset($config[$k]);
96✔
247
            }
248
        }
249

250
        return $config;
96✔
251
    }
252

UNCOV
253
    public function validateSubject(string $subject): string
×
254
    {
UNCOV
255
        if (!in_array($subject, $this->getSubjects())) {
×
UNCOV
256
            throw new DomainException("Invalid subject $subject");
×
257
        }
258

UNCOV
259
        return $subject;
×
260
    }
261
}
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