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

basis-company / nats.php / 23489465477

24 Mar 2026 12:29PM UTC coverage: 93.321% (-1.9%) from 95.179%
23489465477

push

github

nekufa
ephermal consumer configuration fix

5 of 6 new or added lines in 3 files covered. (83.33%)

46 existing lines in 3 files now uncovered.

1537 of 1647 relevant lines covered (93.32%)

75.62 hits per line

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

91.95
/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(
116✔
30
        public readonly string $name
31
    ) {
32
    }
116✔
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 static function fromObject(object $object): self
12✔
46
    {
47
        $config = new static($object->name);
12✔
48

49
        $config->setDiscardPolicy($object->discard);
12✔
50
        $config->setMaxConsumers($object->max_consumers);
12✔
51
        $config->setReplicas($object->replicas ?? $object->num_replicas);
12✔
52
        $config->setRetentionPolicy($object->retention);
12✔
53
        $config->setStorageBackend($object->storage);
12✔
54
        $config->setSubjects($object->subjects);
12✔
55

56
        if (isset($object->allow_rollup_hdrs)) {
12✔
57
            $config->setAllowRollupHeaders($object->allow_rollup_hdrs);
12✔
58
        }
59

60
        if (isset($object->deny_delete)) {
12✔
61
            $config->setDenyDelete($object->deny_delete);
12✔
62
        }
63

64
        if (isset($object->description)) {
12✔
UNCOV
65
            $config->setDescription($object->description);
×
66
        }
67

68
        if (isset($object->duplicate_window)) {
12✔
69
            $config->setDuplicateWindow($object->duplicate_window / 1_000_000_000);
12✔
70
        }
71

72
        if (isset($object->max_age)) {
12✔
73
            $config->setMaxAge($object->max_age);
12✔
74
        }
75

76
        if (isset($object->max_bytes)) {
12✔
77
            $config->setMaxBytes($object->max_bytes);
12✔
78
        }
79

80
        if (isset($object->max_msg_size)) {
12✔
81
            $config->setMaxMessageSize($object->max_msg_size);
12✔
82
        }
83

84
        if (isset($object->max_msgs_per_subject)) {
12✔
85
            $config->setMaxMessagesPerSubject($object->max_msgs_per_subject);
12✔
86
        }
87

88
        if (isset($object->consumer_limits)) {
12✔
89
            $config->setConsumerLimits((array) $object->consumer_limits);
12✔
90
        }
91

92
        if (isset($object->allow_msg_schedules)) {
12✔
UNCOV
93
            $config->setAllowMsgSchedules($object->allow_msg_schedules);
×
94
        }
95

96
        return $config;
12✔
97
    }
98

99
    public function getAllowRollupHeaders(): bool
100✔
100
    {
101
        return $this->allowRollupHeaders;
100✔
102
    }
103

104
    public function getDescription(): ?string
100✔
105
    {
106
        return $this->description;
100✔
107
    }
108

109
    public function getDenyDelete(): bool
100✔
110
    {
111
        return $this->denyDelete;
100✔
112
    }
113

114
    public function getDiscardPolicy(): string
100✔
115
    {
116
        return $this->discardPolicy;
100✔
117
    }
118

119
    public function getDuplicateWindow(): ?float
100✔
120
    {
121
        return $this->duplicateWindow;
100✔
122
    }
123

124
    public function getMaxAge(): int
104✔
125
    {
126
        return $this->maxAge;
104✔
127
    }
128

129
    public function getMaxBytes(): ?int
104✔
130
    {
131
        return $this->maxBytes;
104✔
132
    }
133

134
    public function getMaxConsumers(): int
100✔
135
    {
136
        return $this->maxConsumers;
100✔
137
    }
138

139
    public function getMaxMessageSize(): ?int
104✔
140
    {
141
        return $this->maxMessageSize;
104✔
142
    }
143

144
    public function getMaxMessagesPerSubject(): ?int
104✔
145
    {
146
        return $this->maxMessagesPerSubject;
104✔
147
    }
148

149
    public function getName()
100✔
150
    {
151
        return $this->name;
100✔
152
    }
153

154
    public function getReplicas(): int
104✔
155
    {
156
        return $this->replicas;
104✔
157
    }
158

159
    public function getRetentionPolicy(): string
100✔
160
    {
161
        return $this->retentionPolicy;
100✔
162
    }
163

164
    public function getStorageBackend(): string
100✔
165
    {
166
        return $this->storageBackend;
100✔
167
    }
168

169
    public function getSubjects(): array
104✔
170
    {
171
        return $this->subjects;
104✔
172
    }
173

174
    public function setAllowRollupHeaders(bool $allowRollupHeaders): self
32✔
175
    {
176
        $this->allowRollupHeaders = $allowRollupHeaders;
32✔
177
        return $this;
32✔
178
    }
179

180
    public function setDenyDelete(bool $denyDelete): self
32✔
181
    {
182
        $this->denyDelete = $denyDelete;
32✔
183
        return $this;
32✔
184
    }
185

UNCOV
186
    public function setDescription(?string $description): self
×
187
    {
UNCOV
188
        $this->description = $description;
×
UNCOV
189
        return $this;
×
190
    }
191

192
    public function setDiscardPolicy(string $policy): self
36✔
193
    {
194
        $this->discardPolicy = DiscardPolicy::validate($policy);
36✔
195
        return $this;
32✔
196
    }
197

198
    public function setDuplicateWindow(?float $seconds): self
16✔
199
    {
200
        $this->duplicateWindow = $seconds;
16✔
201
        return $this;
16✔
202
    }
203

204
    /**
205
     * set the max age in nanoSeconds
206
     */
207
    public function setMaxAge(int $maxAgeNanoSeconds): self
32✔
208
    {
209
        $this->maxAge = $maxAgeNanoSeconds;
32✔
210
        return $this;
32✔
211
    }
212

213
    public function setMaxBytes(?int $maxBytes): self
32✔
214
    {
215
        $this->maxBytes = $maxBytes;
32✔
216
        return $this;
32✔
217
    }
218

219
    public function setMaxConsumers(int $maxConsumers): self
12✔
220
    {
221
        $this->maxConsumers = $maxConsumers;
12✔
222
        return $this;
12✔
223
    }
224

225
    public function setMaxMessageSize(?int $maxMessageSize): self
32✔
226
    {
227
        $this->maxMessageSize = $maxMessageSize;
32✔
228
        return $this;
32✔
229
    }
230

231
    public function setMaxMessagesPerSubject(?int $maxMessagesPerSubject): self
32✔
232
    {
233
        $this->maxMessagesPerSubject = $maxMessagesPerSubject;
32✔
234
        return $this;
32✔
235
    }
236

237
    public function setReplicas(int $replicas): self
32✔
238
    {
239
        $this->replicas = $replicas;
32✔
240
        return $this;
32✔
241
    }
242

243
    public function setRetentionPolicy(string $policy): self
64✔
244
    {
245
        $this->retentionPolicy = RetentionPolicy::validate($policy);
64✔
246
        return $this;
60✔
247
    }
248

249
    public function setStorageBackend(string $storage): self
28✔
250
    {
251
        $this->storageBackend = StorageBackend::validate($storage);
28✔
252
        return $this;
24✔
253
    }
254

255
    public function setSubjects(array $subjects): self
100✔
256
    {
257
        $this->subjects = $subjects;
100✔
258
        return $this;
100✔
259
    }
260

261
    public function setConsumerLimits(array $consumerLimits): self
16✔
262
    {
263
        $this->consumerLimits = ConsumerLimits::validate($consumerLimits);
16✔
264
        return $this;
16✔
265
    }
266

267
    public function getConsumerLimits(): ?array
100✔
268
    {
269
        return $this->consumerLimits;
100✔
270
    }
271

UNCOV
272
    public function setAllowMsgSchedules(?bool $allowMsgSchedules): self
×
273
    {
UNCOV
274
        $this->allowMsgSchedules = $allowMsgSchedules;
×
UNCOV
275
        return $this;
×
276
    }
277

278
    public function getAllowMsgSchedules(): ?bool
100✔
279
    {
280
        return $this->allowMsgSchedules;
100✔
281
    }
282

283
    public function toArray(): array
100✔
284
    {
285
        $config = [
100✔
286
            'allow_rollup_hdrs' => $this->getAllowRollupHeaders(),
100✔
287
            'deny_delete' => $this->getDenyDelete(),
100✔
288
            'description' => $this->getDescription(),
100✔
289
            'discard' => $this->getDiscardPolicy(),
100✔
290
            'duplicate_window' => $this->getDuplicateWindow() * 1_000_000_000,
100✔
291
            'max_age' => $this->getMaxAge(),
100✔
292
            'max_bytes' => $this->getMaxBytes(),
100✔
293
            'max_consumers' => $this->getMaxConsumers(),
100✔
294
            'max_msg_size' => $this->getMaxMessageSize(),
100✔
295
            'max_msgs_per_subject' => $this->getMaxMessagesPerSubject(),
100✔
296
            'name' => $this->getName(),
100✔
297
            'num_replicas' => $this->getReplicas(),
100✔
298
            'retention' => $this->getRetentionPolicy(),
100✔
299
            'storage' => $this->getStorageBackend(),
100✔
300
            'subjects' => $this->getSubjects(),
100✔
301
            'consumer_limits' => $this->getConsumerLimits(),
100✔
302
            'allow_msg_schedules' => $this->getAllowMsgSchedules(),
100✔
303
        ];
100✔
304

305
        foreach ($config as $k => $v) {
100✔
306
            if ($v === null) {
100✔
307
                unset($config[$k]);
100✔
308
            }
309
        }
310

311
        return $config;
100✔
312
    }
313

UNCOV
314
    public function validateSubject(string $subject): string
×
315
    {
UNCOV
316
        if (!in_array($subject, $this->getSubjects())) {
×
UNCOV
317
            throw new DomainException("Invalid subject $subject");
×
318
        }
319

UNCOV
320
        return $subject;
×
321
    }
322
}
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