Code Duplication    Length = 33-33 lines in 2 locations

src/Statistics/Collectors/RedisCollector.php 2 locations

@@ 86-118 (lines=33) @@
83
     * @param  string|int  $appId
84
     * @return void
85
     */
86
    public function connection($appId)
87
    {
88
        // Increment the current connections count by 1.
89
        $this->ensureAppIsInSet($appId)
90
            ->hincrby(
91
                $this->channelManager->getRedisKey($appId, null, ['stats']),
92
                'current_connections_count', 1
93
            )
94
            ->then(function ($currentConnectionsCount) use ($appId) {
95
                // Get the peak connections count from Redis.
96
                $this->channelManager
97
                    ->getPublishClient()
98
                    ->hget(
99
                        $this->channelManager->getRedisKey($appId, null, ['stats']),
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
111
                            ->getPublishClient()
112
                            ->hset(
113
                                $this->channelManager->getRedisKey($appId, null, ['stats']),
114
                                'peak_connections_count', $peakConnectionsCount
115
                            );
116
                    });
117
            });
118
    }
119
120
    /**
121
     * Handle disconnections.
@@ 126-158 (lines=33) @@
123
     * @param  string|int  $appId
124
     * @return void
125
     */
126
    public function disconnection($appId)
127
    {
128
        // Decrement the current connections count by 1.
129
        $this->ensureAppIsInSet($appId)
130
            ->hincrby(
131
                $this->channelManager->getRedisKey($appId, null, ['stats']),
132
                'current_connections_count', -1
133
            )
134
            ->then(function ($currentConnectionsCount) use ($appId) {
135
                // Get the peak connections count from Redis.
136
                $this->channelManager
137
                    ->getPublishClient()
138
                    ->hget(
139
                        $this->channelManager->getRedisKey($appId, null, ['stats']),
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
151
                            ->getPublishClient()
152
                            ->hset(
153
                                $this->channelManager->getRedisKey($appId, null, ['stats']),
154
                                'peak_connections_count', $peakConnectionsCount
155
                            );
156
                    });
157
            });
158
    }
159
160
    /**
161
     * Save all the stored statistics.