11
11
12
12
class HttpStatisticsLogger implements StatisticsLogger
13
13
{
14
- /** @var Statistic[] */
14
+ /** @var \BeyondCode\LaravelWebSockets\Statistics\ Statistic[] */
15
15
protected $ statistics = [];
16
16
17
17
/** @var \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager */
18
18
protected $ channelManager ;
19
19
20
- /** @var Browser */
20
+ /** @var \Clue\React\Buzz\ Browser */
21
21
protected $ browser ;
22
22
23
23
public function __construct (ChannelManager $ channelManager , Browser $ browser )
@@ -29,44 +29,46 @@ public function __construct(ChannelManager $channelManager, Browser $browser)
29
29
30
30
public function webSocketMessage (ConnectionInterface $ connection )
31
31
{
32
- $ this -> initializeStatistics ( $ connection -> app -> id );
33
-
34
- $ this -> statistics [ $ connection -> app -> id ] ->webSocketMessage ();
32
+ $ this
33
+ -> findOrMakeStatisticForAppId ( $ connection -> app -> id )
34
+ ->webSocketMessage ();
35
35
}
36
36
37
37
public function apiMessage ($ appId )
38
38
{
39
- $ this -> initializeStatistics ( $ appId );
40
-
41
- $ this -> statistics [ $ appId ] ->apiMessage ();
39
+ $ this
40
+ -> findOrMakeStatisticForAppId ( $ appId )
41
+ ->apiMessage ();
42
42
}
43
43
44
44
public function connection (ConnectionInterface $ connection )
45
45
{
46
- $ this -> initializeStatistics ( $ connection -> app -> id );
47
-
48
- $ this -> statistics [ $ connection -> app -> id ] ->connection ();
46
+ $ this
47
+ -> findOrMakeStatisticForAppId ( $ connection -> app -> id )
48
+ ->connection ();
49
49
}
50
50
51
51
public function disconnection (ConnectionInterface $ connection )
52
52
{
53
- $ this -> initializeStatistics ( $ connection -> app -> id );
54
-
55
- $ this -> statistics [ $ connection -> app -> id ] ->disconnection ();
53
+ $ this
54
+ -> findOrMakeStatisticForAppId ( $ connection -> app -> id )
55
+ ->disconnection ();
56
56
}
57
57
58
- protected function initializeStatistics ( $ id )
58
+ protected function findOrMakeStatisticForAppId ( $ appId ): Statistic
59
59
{
60
- if (!isset ($ this ->statistics [$ id ])) {
61
- $ this ->statistics [$ id ] = new Statistic ($ id );
60
+ if (! isset ($ this ->statistics [$ appId ])) {
61
+ $ this ->statistics [$ appId ] = new Statistic ($ appId );
62
62
}
63
+
64
+ return $ this ->statistics [$ appId ];
63
65
}
64
66
65
67
public function save ()
66
68
{
67
69
foreach ($ this ->statistics as $ appId => $ statistic ) {
68
70
69
- if (!$ statistic ->isEnabled ()) {
71
+ if (! $ statistic ->isEnabled ()) {
70
72
continue ;
71
73
}
72
74
0 commit comments