Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 19ca49a

Browse files
committed
wip formatting
1 parent 908f147 commit 19ca49a

File tree

11 files changed

+52
-76
lines changed

11 files changed

+52
-76
lines changed

src/API/Controller.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ protected function handleRequest(ConnectionInterface $connection)
176176

177177
$laravelRequest = Request::createFromBase((new HttpFoundationFactory)->createRequest($serverRequest));
178178

179-
$this
180-
->ensureValidAppId($laravelRequest->appId)
179+
$this->ensureValidAppId($laravelRequest->appId)
181180
->ensureValidSignature($laravelRequest);
182181

183182
// Invoke the controller action

src/Apps/ConfigAppManager.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ public function __construct()
3030
*/
3131
public function all(): array
3232
{
33-
return $this->apps
34-
->map(function (array $appAttributes) {
35-
return $this->convertIntoApp($appAttributes);
36-
})
37-
->toArray();
33+
return $this->apps->map(function (array $appAttributes) {
34+
return $this->convertIntoApp($appAttributes);
35+
})->toArray();
3836
}
3937

4038
/**
@@ -106,8 +104,7 @@ protected function convertIntoApp(?array $appAttributes): ?App
106104
$app->setPath($appAttributes['path']);
107105
}
108106

109-
$app
110-
->enableClientMessages($appAttributes['enable_client_messages'])
107+
$app->enableClientMessages($appAttributes['enable_client_messages'])
111108
->enableStatistics($appAttributes['enable_statistics'])
112109
->setCapacity($appAttributes['capacity'] ?? null)
113110
->setAllowedOrigins($appAttributes['allowed_origins'] ?? []);

src/ChannelManagers/LocalChannelManager.php

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,12 @@ public function findOrCreate($appId, string $channel)
111111
*/
112112
public function getLocalConnections(): PromiseInterface
113113
{
114-
$connections = collect($this->channels)
115-
->map(function ($channelsWithConnections, $appId) {
116-
return collect($channelsWithConnections)->values();
117-
})
118-
->values()->collapse()
119-
->map(function ($channel) {
120-
return collect($channel->getConnections());
121-
})
122-
->values()->collapse()
123-
->toArray();
114+
$connections = collect($this->channels)->map(function ($channelsWithConnections, $appId) {
115+
return collect($channelsWithConnections)->values();
116+
})->values()->collapse()
117+
->map(function ($channel) {
118+
return collect($channel->getConnections());
119+
})->values()->collapse()->toArray();
124120

125121
return Helpers::createFulfilledPromise($connections);
126122
}
@@ -166,11 +162,9 @@ public function unsubscribeFromAllChannels(ConnectionInterface $connection): Pro
166162
$this->getLocalChannels($connection->app->id)->then(function ($channels) use ($connection) {
167163
collect($channels)->each->unsubscribe($connection);
168164

169-
collect($channels)
170-
->reject->hasConnections()
171-
->each(function (Channel $channel, string $channelName) use ($connection) {
172-
unset($this->channels[$connection->app->id][$channelName]);
173-
});
165+
collect($channels)->reject->hasConnections()->each(function (Channel $channel, string $channelName) use ($connection) {
166+
unset($this->channels[$connection->app->id][$channelName]);
167+
});
174168
});
175169

176170
$this->getLocalChannels($connection->app->id)->then(function ($channels) use ($connection) {
@@ -255,11 +249,9 @@ public function getLocalConnectionsCount($appId, string $channelName = null): Pr
255249
return $collection->filter(function (Channel $channel) use ($channelName) {
256250
return $channel->getName() === $channelName;
257251
});
258-
})
259-
->flatMap(function (Channel $channel) {
252+
})->flatMap(function (Channel $channel) {
260253
return collect($channel->getConnections())->pluck('socketId');
261-
})
262-
->unique()->count();
254+
})->unique()->count();
263255
});
264256
}
265257

@@ -378,14 +370,13 @@ public function getChannelMember(ConnectionInterface $connection, string $channe
378370
*/
379371
public function getChannelsMembersCount($appId, array $channelNames): PromiseInterface
380372
{
381-
$results = collect($channelNames)
382-
->reduce(function ($results, $channel) use ($appId) {
383-
$results[$channel] = isset($this->users["{$appId}:{$channel}"])
384-
? count($this->users["{$appId}:{$channel}"])
385-
: 0;
386-
387-
return $results;
388-
}, []);
373+
$results = collect($channelNames)->reduce(function ($results, $channel) use ($appId) {
374+
$results[$channel] = isset($this->users["{$appId}:{$channel}"])
375+
? count($this->users["{$appId}:{$channel}"])
376+
: 0;
377+
378+
return $results;
379+
}, []);
389380

390381
return Helpers::createFulfilledPromise($results);
391382
}

src/ChannelManagers/RedisChannelManager.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -412,14 +412,13 @@ public function connectionPonged(ConnectionInterface $connection): PromiseInterf
412412
public function removeObsoleteConnections(): PromiseInterface
413413
{
414414
$this->lock()->get(function () {
415-
$this->getConnectionsFromSet(0, now()->subMinutes(2)->format('U'))
416-
->then(function ($connections) {
417-
foreach ($connections as $socketId => $appId) {
418-
$connection = $this->fakeConnectionForApp($appId, $socketId);
419-
420-
$this->unsubscribeFromAllChannels($connection);
421-
}
422-
});
415+
$this->getConnectionsFromSet(0, now()->subMinutes(2)->format('U'))->then(function ($connections) {
416+
foreach ($connections as $socketId => $appId) {
417+
$connection = $this->fakeConnectionForApp($appId, $socketId);
418+
419+
$this->unsubscribeFromAllChannels($connection);
420+
}
421+
});
423422
});
424423

425424
return parent::removeObsoleteConnections();

src/Channels/Channel.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ public function saveConnection(ConnectionInterface $connection)
155155
*/
156156
public function broadcast($appId, stdClass $payload, bool $replicate = true): bool
157157
{
158-
collect($this->getConnections())
159-
->each->send(json_encode($payload));
158+
collect($this->getConnections())->each->send(json_encode($payload));
160159

161160
if ($replicate) {
162161
$this->channelManager->broadcastAcrossServers($appId, null, $this->getName(), $payload);

src/Statistics/Collectors/MemoryCollector.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ public function __construct()
4343
*/
4444
public function webSocketMessage($appId)
4545
{
46-
$this->findOrMake($appId)
47-
->webSocketMessage();
46+
$this->findOrMake($appId)->webSocketMessage();
4847
}
4948

5049
/**
@@ -55,8 +54,7 @@ public function webSocketMessage($appId)
5554
*/
5655
public function apiMessage($appId)
5756
{
58-
$this->findOrMake($appId)
59-
->apiMessage();
57+
$this->findOrMake($appId)->apiMessage();
6058
}
6159

6260
/**
@@ -67,8 +65,7 @@ public function apiMessage($appId)
6765
*/
6866
public function connection($appId)
6967
{
70-
$this->findOrMake($appId)
71-
->connection();
68+
$this->findOrMake($appId)->connection();
7269
}
7370

7471
/**
@@ -79,8 +76,7 @@ public function connection($appId)
7976
*/
8077
public function disconnection($appId)
8178
{
82-
$this->findOrMake($appId)
83-
->disconnection();
79+
$this->findOrMake($appId)->disconnection();
8480
}
8581

8682
/**

src/Statistics/Collectors/RedisCollector.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ public function __construct()
5555
*/
5656
public function webSocketMessage($appId)
5757
{
58-
$this->ensureAppIsInSet($appId)
59-
->hincrby($this->channelManager->getRedisKey($appId, null, ['stats']), 'websocket_messages_count', 1);
58+
$this->ensureAppIsInSet($appId)->hincrby(
59+
$this->channelManager->getRedisKey($appId, null, ['stats']), 'websocket_messages_count', 1
60+
);
6061
}
6162

6263
/**
@@ -67,8 +68,9 @@ public function webSocketMessage($appId)
6768
*/
6869
public function apiMessage($appId)
6970
{
70-
$this->ensureAppIsInSet($appId)
71-
->hincrby($this->channelManager->getRedisKey($appId, null, ['stats']), 'api_messages_count', 1);
71+
$this->ensureAppIsInSet($appId)->hincrby(
72+
$this->channelManager->getRedisKey($appId, null, ['stats']), 'api_messages_count', 1
73+
);
7274
}
7375

7476
/**

src/Statistics/Stores/DatabaseStore.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ public static function delete(Carbon $moment, $appId = null): int
4242
return static::$model::where('created_at', '<', $moment->toDateTimeString())
4343
->when(! is_null($appId), function ($query) use ($appId) {
4444
return $query->whereAppId($appId);
45-
})
46-
->delete();
45+
})->delete();
4746
}
4847

4948
/**
@@ -54,12 +53,11 @@ public static function delete(Carbon $moment, $appId = null): int
5453
*/
5554
public function getRawRecords(callable $processQuery = null)
5655
{
57-
return static::$model::query()
58-
->when(! is_null($processQuery), function ($query) use ($processQuery) {
59-
return call_user_func($processQuery, $query);
60-
}, function ($query) {
61-
return $query->latest()->limit(120);
62-
})->get();
56+
return static::$model::query()->when(! is_null($processQuery), function ($query) use ($processQuery) {
57+
return call_user_func($processQuery, $query);
58+
}, function ($query) {
59+
return $query->latest()->limit(120);
60+
})->get();
6361
}
6462

6563
/**
@@ -74,11 +72,9 @@ public function getRecords(callable $processQuery = null, callable $processColle
7472
return $this->getRawRecords($processQuery)
7573
->when(! is_null($processCollection), function ($collection) use ($processCollection) {
7674
return call_user_func($processCollection, $collection);
77-
})
78-
->map(function (Model $statistic) {
75+
})->map(function (Model $statistic) {
7976
return $this->statisticToArray($statistic);
80-
})
81-
->toArray();
77+
})->toArray();
8278
}
8379

8480
/**

tests/PresenceChannelTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,7 @@ public function test_events_get_replicated_across_connections_for_presence_chann
371371

372372
$receiver->assertSentEvent('some-event', $message->getPayloadAsArray());
373373

374-
$this->getSubscribeClient()
375-
->assertNothingDispatched();
374+
$this->getSubscribeClient()->assertNothingDispatched();
376375

377376
$this->getPublishClient()->assertCalledWithArgs('publish', [
378377
$this->channelManager->getRedisKey('1234', 'presence-channel'),

tests/PrivateChannelTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,7 @@ public function test_events_get_replicated_across_connections_for_private_channe
205205

206206
$receiver->assertSentEvent('some-event', $message->getPayloadAsArray());
207207

208-
$this->getSubscribeClient()
209-
->assertNothingDispatched();
208+
$this->getSubscribeClient()->assertNothingDispatched();
210209

211210
$this->getPublishClient()->assertCalledWithArgs('publish', [
212211
$this->channelManager->getRedisKey('1234', 'private-channel'),

0 commit comments

Comments
 (0)