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

basis-company / nats.php / 23218288118

17 Mar 2026 09:57PM UTC coverage: 94.977% (-0.1%) from 95.104%
23218288118

push

github

nekufa
pong msg should be returned from connection #119

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

5 existing lines in 2 files now uncovered.

1456 of 1533 relevant lines covered (94.98%)

79.92 hits per line

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

95.45
/src/Configuration.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Basis\Nats;
6

7
use InvalidArgumentException;
8

9
class Configuration
10
{
11
    public const DELAY_CONSTANT = 'constant';
12
    public const DELAY_LINEAR = 'linear';
13
    public const DELAY_EXPONENTIAL = 'exponential';
14

15
    protected float $delay;
16
    protected string $delayMode;
17

18
    /**
19
     * @param array<string, string|int|bool|null> $options
20
     */
21
    public function __construct(
296✔
22
        array $options = [], // deprecated
23
        array $options2 = [], // deprecated multi option array support
24
        array $options3 = [], // deprecated multi option array support
25
        public string $host = 'localhost',
26
        public int $port = 4222,
27
        public ?string $user = null,
28
        public ?string $jwt = null,
29
        public ?string $pass = null,
30
        public ?string $token = null,
31
        public ?string $nkey = null,
32
        public ?string $tlsKeyFile = null,
33
        public ?string $tlsCertFile = null,
34
        public ?string $tlsCaFile = null,
35
        public bool $tlsHandshakeFirst = false,
36
        public bool $pedantic = false,
37
        public bool $reconnect = true,
38
        public bool $verbose = false,
39
        public float $timeout = 1,
40
        public int $pingInterval = 2,
41
        float $delay = 0.001,
42
        string $delayMode = self::DELAY_CONSTANT,
43
        public string $lang = 'php',
44
        public string $version = 'dev',
45
        public string $inboxPrefix = '_INBOX',
46
    ) {
47

48
        $this->setDelay($delay, $delayMode);
296✔
49

50
        foreach (array_merge($options, $options2, $options3) as $k => $v) {
296✔
51
            if (!property_exists($this, $k)) {
80✔
52
                throw new InvalidArgumentException("Invalid config option $k");
4✔
53
            }
54
            if ($k == 'delayMode') {
76✔
55
                $this->setDelay($this->delay, $v);
4✔
56
            } elseif ($k == 'delay') {
72✔
57
                $this->setDelay($v, $this->delayMode);
4✔
58
            } else {
59
                $this->$k = $v;
72✔
60
            }
61
        }
62
    }
63

64
    public function getOptions(): array
280✔
65
    {
66
        $options = [
280✔
67
            'lang' => $this->lang,
280✔
68
            'pedantic' => $this->pedantic,
280✔
69
            'verbose' => $this->verbose,
280✔
70
            'version' => $this->version,
280✔
71
            'headers' => true,
280✔
72
        ];
280✔
73

74
        if ($this->user !== null) {
280✔
75
            $options['user'] = $this->user;
4✔
76
            $options['pass'] = $this->pass;
4✔
77
        } elseif ($this->token !== null) {
276✔
78
            $options['auth_token'] = $this->token;
4✔
79
        } elseif ($this->jwt !== null) {
272✔
80
            $options['jwt'] = $this->jwt;
12✔
81
        }
82

83
        return $options;
280✔
84
    }
85

86
    public function delay(int $iteration)
5✔
87
    {
88
        $milliseconds = intval($this->delay * 1_000);
5✔
89

90
        switch ($this->delayMode) {
5✔
91
            case self::DELAY_EXPONENTIAL:
92
                $milliseconds = $milliseconds ** $iteration;
4✔
93
                break;
4✔
94

95
            case self::DELAY_LINEAR:
UNCOV
96
                $milliseconds = $milliseconds * $iteration;
×
UNCOV
97
                break;
×
98
        }
99

100
        usleep($milliseconds * 1_000);
5✔
101
    }
102

103
    public function setDelay(float $delay, string $mode = self::DELAY_CONSTANT): self
296✔
104
    {
105
        if (!in_array($mode, [self::DELAY_CONSTANT, self::DELAY_EXPONENTIAL, self::DELAY_LINEAR])) {
296✔
106
            throw new InvalidArgumentException("Invalid mode: $mode");
4✔
107
        }
108

109
        $this->delay = $delay;
296✔
110
        $this->delayMode = $mode;
296✔
111

112
        return $this;
296✔
113
    }
114

115
    public function getDelay(): float
4✔
116
    {
117
        return $this->delay;
4✔
118
    }
119

120
    public function getDelayMode(): string
4✔
121
    {
122
        return $this->delayMode;
4✔
123
    }
124
}
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