Completed
Pull Request — master (#447)
by Alexandru
01:32
created

RedisCollector::connection()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 33

Duplication

Lines 33
Ratio 100 %

Importance

Changes 0
Metric Value
dl 33
loc 33
rs 9.392
c 0
b 0
f 0
cc 2
nc 1
nop 1
1
<?php
2
3
namespace BeyondCode\LaravelWebSockets\Statistics\Collectors;
4
5
use BeyondCode\LaravelWebSockets\Helpers;
6
use BeyondCode\LaravelWebSockets\Statistics\Statistic;
7
use Illuminate\Cache\RedisLock;
8
use Illuminate\Support\Facades\Redis;
9
use React\Promise\PromiseInterface;
10
11
class RedisCollector extends MemoryCollector
12
{
13
    /**
14
     * The Redis manager instance.
15
     *
16
     * @var \Illuminate\Redis\RedisManager
17
     */
18
    protected $redis;
19
20
    /**
21
     * The set name for the Redis storage.
22
     *
23
     * @var string
24
     */
25
    protected static $redisSetName = 'laravel-websockets:apps';
26
27
    /**
28
     * The lock name to use on Redis to avoid multiple
29
     * collector-to-store actions that may result
30
     * in multiple data points set to the store.
31
     *
32
     * @var string
33
     */
34
    protected static $redisLockName = 'laravel-websockets:collector:lock';
35
36
    /**
37
     * Initialize the logger.
38
     *
39
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
40
     */
41
    public function __construct()
42
    {
43
        parent::__construct();
44
45
        $this->redis = Redis::connection(
0 ignored issues
show
Documentation Bug introduced by
It seems like \Illuminate\Support\Faca...onnection', 'default')) of type object<Illuminate\Redis\Connections\Connection> is incompatible with the declared type object<Illuminate\Redis\RedisManager> of property $redis.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
46
            config('websockets.replication.modes.redis.connection', 'default')
47
        );
48
    }
49
50
    /**
51
     * Handle the incoming websocket message.
52
     *
53
     * @param  string|int  $appId
54
     * @return void
55
     */
56
    public function webSocketMessage($appId)
57
    {
58
        $this->ensureAppIsInSet($appId)
59
            ->hincrby(
60
                $this->channelManager->getRedisKey($appId, null, ['stats']),
0 ignored issues
show
Bug introduced by
The method getRedisKey() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
61
                'websocket_messages_count', 1
62
            );
63
    }
64
65
    /**
66
     * Handle the incoming API message.
67
     *
68
     * @param  string|int  $appId
69
     * @return void
70
     */
71
    public function apiMessage($appId)
72
    {
73
        $this->ensureAppIsInSet($appId)
74
            ->hincrby(
75
                $this->channelManager->getRedisKey($appId, null, ['stats']),
0 ignored issues
show
Bug introduced by
The method getRedisKey() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
76
                'api_messages_count', 1
77
            );
78
    }
79
80
    /**
81
     * Handle the new conection.
82
     *
83
     * @param  string|int  $appId
84
     * @return void
85
     */
86 View Code Duplication
    public function connection($appId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
87
    {
88
        // Increment the current connections count by 1.
89
        $this->ensureAppIsInSet($appId)
90
            ->hincrby(
91
                $this->channelManager->getRedisKey($appId, null, ['stats']),
0 ignored issues
show
Bug introduced by
The method getRedisKey() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
92
                'current_connections_count', 1
93
            )
94
            ->then(function ($currentConnectionsCount) use ($appId) {
95
                // Get the peak connections count from Redis.
96
                $this->channelManager
0 ignored issues
show
Bug introduced by
The method getPublishClient() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
97
                    ->getPublishClient()
98
                    ->hget(
99
                        $this->channelManager->getRedisKey($appId, null, ['stats']),
0 ignored issues
show
Bug introduced by
The method getRedisKey() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
100
                        'peak_connections_count'
101
                    )
102
                    ->then(function ($currentPeakConnectionCount) use ($currentConnectionsCount, $appId) {
103
                        // Extract the greatest number between the current peak connection count
104
                        // and the current connection number.
105
                        $peakConnectionsCount = is_null($currentPeakConnectionCount)
106
                            ? $currentConnectionsCount
107
                            : max($currentPeakConnectionCount, $currentConnectionsCount);
108
109
                        // Then set it to the database.
110
                        $this->channelManager
0 ignored issues
show
Bug introduced by
The method getPublishClient() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
111
                            ->getPublishClient()
112
                            ->hset(
113
                                $this->channelManager->getRedisKey($appId, null, ['stats']),
0 ignored issues
show
Bug introduced by
The method getRedisKey() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
114
                                'peak_connections_count', $peakConnectionsCount
115
                            );
116
                    });
117
            });
118
    }
119
120
    /**
121
     * Handle disconnections.
122
     *
123
     * @param  string|int  $appId
124
     * @return void
125
     */
126 View Code Duplication
    public function disconnection($appId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
127
    {
128
        // Decrement the current connections count by 1.
129
        $this->ensureAppIsInSet($appId)
130
            ->hincrby(
131
                $this->channelManager->getRedisKey($appId, null, ['stats']),
0 ignored issues
show
Bug introduced by
The method getRedisKey() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
132
                'current_connections_count', -1
133
            )
134
            ->then(function ($currentConnectionsCount) use ($appId) {
135
                // Get the peak connections count from Redis.
136
                $this->channelManager
0 ignored issues
show
Bug introduced by
The method getPublishClient() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
137
                    ->getPublishClient()
138
                    ->hget(
139
                        $this->channelManager->getRedisKey($appId, null, ['stats']),
0 ignored issues
show
Bug introduced by
The method getRedisKey() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
140
                        'peak_connections_count'
141
                    )
142
                    ->then(function ($currentPeakConnectionCount) use ($currentConnectionsCount, $appId) {
143
                        // Extract the greatest number between the current peak connection count
144
                        // and the current connection number.
145
                        $peakConnectionsCount = is_null($currentPeakConnectionCount)
146
                            ? $currentConnectionsCount
147
                            : max($currentPeakConnectionCount, $currentConnectionsCount);
148
149
                        // Then set it to the database.
150
                        $this->channelManager
0 ignored issues
show
Bug introduced by
The method getPublishClient() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
151
                            ->getPublishClient()
152
                            ->hset(
153
                                $this->channelManager->getRedisKey($appId, null, ['stats']),
0 ignored issues
show
Bug introduced by
The method getRedisKey() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
154
                                'peak_connections_count', $peakConnectionsCount
155
                            );
156
                    });
157
            });
158
    }
159
160
    /**
161
     * Save all the stored statistics.
162
     *
163
     * @return void
164
     */
165
    public function save()
166
    {
167
        $this->lock()->get(function () {
168
            $this->channelManager
0 ignored issues
show
Bug introduced by
The method getPublishClient() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
169
                ->getPublishClient()
170
                ->smembers(static::$redisSetName)
171
                ->then(function ($members) {
172
                    foreach ($members as $appId) {
173
                        $this->channelManager
0 ignored issues
show
Bug introduced by
The method getPublishClient() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
174
                            ->getPublishClient()
175
                            ->hgetall($this->channelManager->getRedisKey($appId, null, ['stats']))
0 ignored issues
show
Bug introduced by
The method getRedisKey() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
176
                            ->then(function ($list) use ($appId) {
177
                                if (! $list) {
178
                                    return;
179
                                }
180
181
                                $statistic = $this->arrayToStatisticInstance(
182
                                    $appId, Helpers::redisListToArray($list)
183
                                );
184
185
                                $this->createRecord($statistic, $appId);
186
187
                                $this->channelManager
188
                                    ->getGlobalConnectionsCount($appId)
189
                                    ->then(function ($currentConnectionsCount) use ($appId) {
190
                                        $currentConnectionsCount === 0 || is_null($currentConnectionsCount)
191
                                            ? $this->resetAppTraces($appId)
192
                                            : $this->resetStatistics($appId, $currentConnectionsCount);
193
                                    });
194
                            });
195
                    }
196
                });
197
        });
198
    }
199
200
    /**
201
     * Flush the stored statistics.
202
     *
203
     * @return void
204
     */
205
    public function flush()
206
    {
207
        $this->getStatistics()->then(function ($statistics) {
208
            foreach ($statistics as $appId => $statistic) {
209
                $this->resetAppTraces($appId);
210
            }
211
        });
212
    }
213
214
    /**
215
     * Get the saved statistics.
216
     *
217
     * @return PromiseInterface[array]
0 ignored issues
show
Documentation introduced by
The doc-type PromiseInterface[array] could not be parsed: Expected "]" at position 2, but found "array". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
218
     */
219
    public function getStatistics(): PromiseInterface
220
    {
221
        return $this->channelManager
0 ignored issues
show
Bug introduced by
The method getPublishClient() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
222
            ->getPublishClient()
223
            ->smembers(static::$redisSetName)
224
            ->then(function ($members) {
225
                $appsWithStatistics = [];
226
227
                foreach ($members as $appId) {
228
                    $this->channelManager
0 ignored issues
show
Bug introduced by
The method getPublishClient() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
229
                        ->getPublishClient()
230
                        ->hgetall($this->channelManager->getRedisKey($appId, null, ['stats']))
0 ignored issues
show
Bug introduced by
The method getRedisKey() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
231
                        ->then(function ($list) use ($appId, &$appsWithStatistics) {
232
                            $appsWithStatistics[$appId] = $this->arrayToStatisticInstance(
233
                                $appId, Helpers::redisListToArray($list)
234
                            );
235
                        });
236
                }
237
238
                return $appsWithStatistics;
239
            });
240
    }
241
242
    /**
243
     * Get the saved statistics for an app.
244
     *
245
     * @param  string|int  $appId
246
     * @return PromiseInterface[\BeyondCode\LaravelWebSockets\Statistics\Statistic|null]
0 ignored issues
show
Documentation introduced by
The doc-type PromiseInterface[\Beyond...tistics\Statistic|null] could not be parsed: Expected "]" at position 2, but found "\BeyondCode\LaravelWebSockets\Statistics\Statistic". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
247
     */
248
    public function getAppStatistics($appId): PromiseInterface
249
    {
250
        return $this->channelManager
0 ignored issues
show
Bug introduced by
The method getPublishClient() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
251
            ->getPublishClient()
252
            ->hgetall($this->channelManager->getRedisKey($appId, null, ['stats']))
0 ignored issues
show
Bug introduced by
The method getRedisKey() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
253
            ->then(function ($list) use ($appId) {
254
                return $this->arrayToStatisticInstance(
255
                    $appId, Helpers::redisListToArray($list)
256
                );
257
            });
258
    }
259
260
    /**
261
     * Reset the statistics to a specific connection count.
262
     *
263
     * @param  string|int  $appId
264
     * @param  int  $currentConnectionCount
265
     * @return void
266
     */
267
    public function resetStatistics($appId, int $currentConnectionCount)
268
    {
269
        $this->channelManager
0 ignored issues
show
Bug introduced by
The method getPublishClient() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
270
            ->getPublishClient()
271
            ->hset(
272
                $this->channelManager->getRedisKey($appId, null, ['stats']),
0 ignored issues
show
Bug introduced by
The method getRedisKey() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
273
                'current_connections_count', $currentConnectionCount
274
            );
275
276
        $this->channelManager
0 ignored issues
show
Bug introduced by
The method getPublishClient() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
277
            ->getPublishClient()
278
            ->hset(
279
                $this->channelManager->getRedisKey($appId, null, ['stats']),
0 ignored issues
show
Bug introduced by
The method getRedisKey() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
280
                'peak_connections_count', $currentConnectionCount
281
            );
282
283
        $this->channelManager
0 ignored issues
show
Bug introduced by
The method getPublishClient() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
284
            ->getPublishClient()
285
            ->hset(
286
                $this->channelManager->getRedisKey($appId, null, ['stats']),
0 ignored issues
show
Bug introduced by
The method getRedisKey() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
287
                'websocket_messages_count', 0
288
            );
289
290
        $this->channelManager
0 ignored issues
show
Bug introduced by
The method getPublishClient() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
291
            ->getPublishClient()
292
            ->hset(
293
                $this->channelManager->getRedisKey($appId, null, ['stats']),
0 ignored issues
show
Bug introduced by
The method getRedisKey() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
294
                'api_messages_count', 0
295
            );
296
    }
297
298
    /**
299
     * Remove all app traces from the database if no connections have been set
300
     * in the meanwhile since last save.
301
     *
302
     * @param  string|int  $appId
303
     * @return void
304
     */
305
    public function resetAppTraces($appId)
306
    {
307
        $this->channelManager
0 ignored issues
show
Bug introduced by
The method getPublishClient() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
308
            ->getPublishClient()
309
            ->hdel(
310
                $this->channelManager->getRedisKey($appId, null, ['stats']),
0 ignored issues
show
Bug introduced by
The method getRedisKey() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
311
                'current_connections_count'
312
            );
313
314
        $this->channelManager
0 ignored issues
show
Bug introduced by
The method getPublishClient() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
315
            ->getPublishClient()
316
            ->hdel(
317
                $this->channelManager->getRedisKey($appId, null, ['stats']),
0 ignored issues
show
Bug introduced by
The method getRedisKey() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
318
                'peak_connections_count'
319
            );
320
321
        $this->channelManager
0 ignored issues
show
Bug introduced by
The method getPublishClient() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
322
            ->getPublishClient()
323
            ->hdel(
324
                $this->channelManager->getRedisKey($appId, null, ['stats']),
0 ignored issues
show
Bug introduced by
The method getRedisKey() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
325
                'websocket_messages_count'
326
            );
327
328
        $this->channelManager
0 ignored issues
show
Bug introduced by
The method getPublishClient() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
329
            ->getPublishClient()
330
            ->hdel(
331
                $this->channelManager->getRedisKey($appId, null, ['stats']),
0 ignored issues
show
Bug introduced by
The method getRedisKey() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
332
                'api_messages_count'
333
            );
334
335
        $this->channelManager
0 ignored issues
show
Bug introduced by
The method getPublishClient() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
336
            ->getPublishClient()
337
            ->srem(static::$redisSetName, $appId);
338
    }
339
340
    /**
341
     * Ensure the app id is stored in the Redis database.
342
     *
343
     * @param  string|int  $appId
344
     * @return \Clue\React\Redis\Client
345
     */
346
    protected function ensureAppIsInSet($appId)
347
    {
348
        $this->channelManager
0 ignored issues
show
Bug introduced by
The method getPublishClient() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
349
            ->getPublishClient()
350
            ->sadd(static::$redisSetName, $appId);
351
352
        return $this->channelManager->getPublishClient();
0 ignored issues
show
Bug introduced by
The method getPublishClient() does not seem to exist on object<BeyondCode\Larave...ntracts\ChannelManager>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
353
    }
354
355
    /**
356
     * Get a new RedisLock instance to avoid race conditions.
357
     *
358
     * @return \Illuminate\Cache\CacheLock
359
     */
360
    protected function lock()
361
    {
362
        return new RedisLock($this->redis, static::$redisLockName, 0);
0 ignored issues
show
Documentation introduced by
$this->redis is of type object<Illuminate\Redis\RedisManager>, but the function expects a object<Illuminate\Redis\Connections\Connection>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
363
    }
364
365
    /**
366
     * Transform a key-value pair to a Statistic instance.
367
     *
368
     * @param  string|int  $appId
369
     * @param  array  $stats
370
     * @return \BeyondCode\LaravelWebSockets\Statistics\Statistic
371
     */
372
    protected function arrayToStatisticInstance($appId, array $stats)
373
    {
374
        return Statistic::new($appId)
375
            ->setCurrentConnectionsCount($stats['current_connections_count'] ?? 0)
376
            ->setPeakConnectionsCount($stats['peak_connections_count'] ?? 0)
377
            ->setWebSocketMessagesCount($stats['websocket_messages_count'] ?? 0)
378
            ->setApiMessagesCount($stats['api_messages_count'] ?? 0);
379
    }
380
}
381