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

Commit c203d24

Browse files
committed
Clean up some typos, add some type hints, StyleCI fixes
1 parent b584d0c commit c203d24

File tree

10 files changed

+55
-34
lines changed

10 files changed

+55
-34
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ composer.lock
33
docs
44
vendor
55
coverage
6-
.phpunit.result.cache
6+
.phpunit.result.cache
7+
.idea/

config/websockets.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@
137137
],
138138
],
139139

140-
141140
/*
142141
* Channel Manager
143142
* This class handles how channel persistence is handled.

src/Apps/ConfigAppProvider.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function all(): array
1919
{
2020
return $this->apps
2121
->map(function (array $appAttributes) {
22-
return $this->instanciate($appAttributes);
22+
return $this->instantiate($appAttributes);
2323
})
2424
->toArray();
2525
}
@@ -30,7 +30,7 @@ public function findById($appId): ?App
3030
->apps
3131
->firstWhere('id', $appId);
3232

33-
return $this->instanciate($appAttributes);
33+
return $this->instantiate($appAttributes);
3434
}
3535

3636
public function findByKey(string $appKey): ?App
@@ -39,7 +39,7 @@ public function findByKey(string $appKey): ?App
3939
->apps
4040
->firstWhere('key', $appKey);
4141

42-
return $this->instanciate($appAttributes);
42+
return $this->instantiate($appAttributes);
4343
}
4444

4545
public function findBySecret(string $appSecret): ?App
@@ -48,10 +48,10 @@ public function findBySecret(string $appSecret): ?App
4848
->apps
4949
->firstWhere('secret', $appSecret);
5050

51-
return $this->instanciate($appAttributes);
51+
return $this->instantiate($appAttributes);
5252
}
5353

54-
protected function instanciate(?array $appAttributes): ?App
54+
protected function instantiate(?array $appAttributes): ?App
5555
{
5656
if (! $appAttributes) {
5757
return null;

src/Console/StartWebSocketServer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
use React\Dns\Resolver\Factory as DnsFactory;
1212
use BeyondCode\LaravelWebSockets\Statistics\DnsResolver;
1313
use BeyondCode\LaravelWebSockets\PubSub\PubSubInterface;
14-
use BeyondCode\LaravelWebSockets\PubSub\Redis\RedisClient;
14+
use BeyondCode\LaravelWebSockets\Statistics\DnsResolver;
1515
use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger;
1616
use BeyondCode\LaravelWebSockets\Facades\WebSocketsRouter;
17+
use BeyondCode\LaravelWebSockets\PubSub\Redis\RedisClient;
1718
use BeyondCode\LaravelWebSockets\Server\Logger\HttpLogger;
1819
use BeyondCode\LaravelWebSockets\Server\WebSocketServerFactory;
1920
use BeyondCode\LaravelWebSockets\Server\Logger\ConnectionLogger;

src/Facades/StatisticsLogger.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
use Illuminate\Support\Facades\Facade;
66
use BeyondCode\LaravelWebSockets\Statistics\Logger\StatisticsLogger as StatisticsLoggerInterface;
77

8-
/** @see \BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger */
8+
/**
9+
* @see \BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger
10+
* @mixin \BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger
11+
*/
912
class StatisticsLogger extends Facade
1013
{
1114
protected static function getFacadeAccessor()

src/Facades/WebSocketsRouter.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
use Illuminate\Support\Facades\Facade;
66

7-
/** @see \BeyondCode\LaravelWebSockets\Server\Router */
7+
/**
8+
* @see \BeyondCode\LaravelWebSockets\Server\Router
9+
* @mixin \BeyondCode\LaravelWebSockets\Server\Router
10+
*/
811
class WebSocketsRouter extends Facade
912
{
1013
protected static function getFacadeAccessor()

src/HttpApi/Controllers/Controller.php

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ public function onOpen(ConnectionInterface $connection, RequestInterface $reques
4646

4747
$this->requestBuffer = (string) $request->getBody();
4848

49-
$this->checkContentLength($connection);
49+
if (! $this->checkContentLength()) {
50+
return;
51+
}
52+
53+
$this->handleRequest($connection);
5054
}
5155

5256
protected function findContentLength(array $headers): int
@@ -60,31 +64,38 @@ public function onMessage(ConnectionInterface $from, $msg)
6064
{
6165
$this->requestBuffer .= $msg;
6266

63-
$this->checkContentLength($from);
67+
if (! $this->checkContentLength()) {
68+
return;
69+
}
70+
71+
$this->handleRequest($from);
6472
}
6573

66-
protected function checkContentLength(ConnectionInterface $connection)
74+
protected function checkContentLength()
6775
{
68-
if (strlen($this->requestBuffer) === $this->contentLength) {
69-
$serverRequest = (new ServerRequest(
70-
$this->request->getMethod(),
71-
$this->request->getUri(),
72-
$this->request->getHeaders(),
73-
$this->requestBuffer,
74-
$this->request->getProtocolVersion()
75-
))->withQueryParams(QueryParameters::create($this->request)->all());
76+
return strlen($this->requestBuffer) !== $this->contentLength;
77+
}
7678

77-
$laravelRequest = Request::createFromBase((new HttpFoundationFactory)->createRequest($serverRequest));
79+
protected function handleRequest(ConnectionInterface $connection)
80+
{
81+
$serverRequest = (new ServerRequest(
82+
$this->request->getMethod(),
83+
$this->request->getUri(),
84+
$this->request->getHeaders(),
85+
$this->requestBuffer,
86+
$this->request->getProtocolVersion()
87+
))->withQueryParams(QueryParameters::create($this->request)->all());
7888

79-
$this
80-
->ensureValidAppId($laravelRequest->appId)
81-
->ensureValidSignature($laravelRequest);
89+
$laravelRequest = Request::createFromBase((new HttpFoundationFactory)->createRequest($serverRequest));
8290

83-
$response = $this($laravelRequest);
91+
$this
92+
->ensureValidAppId($laravelRequest->appId)
93+
->ensureValidSignature($laravelRequest);
8494

85-
$connection->send(JsonResponse::create($response));
86-
$connection->close();
87-
}
95+
$response = $this($laravelRequest);
96+
97+
$connection->send(JsonResponse::create($response));
98+
$connection->close();
8899
}
89100

90101
public function onClose(ConnectionInterface $connection)
@@ -122,7 +133,7 @@ protected function ensureValidSignature(Request $request)
122133
/*
123134
* The `auth_signature` & `body_md5` parameters are not included when calculating the `auth_signature` value.
124135
*
125-
* The `appId`, `appKey` & `channelName` parameters are actually route paramaters and are never supplied by the client.
136+
* The `appId`, `appKey` & `channelName` parameters are actually route parameters and are never supplied by the client.
126137
*/
127138
$params = Arr::except($request->query(), ['auth_signature', 'body_md5', 'appId', 'appKey', 'channelName']);
128139

src/Server/Router.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ protected function getRoute(string $method, string $uri, $action): Route
9494
* If the given action is a class that handles WebSockets, then it's not a regular
9595
* controller but a WebSocketHandler that needs to converted to a WsServer.
9696
*
97-
* If the given action is a regular controller we'll just instanciate it.
97+
* If the given action is a regular controller we'll just instantiate it.
9898
*/
9999
$action = is_subclass_of($action, MessageComponentInterface::class)
100100
? $this->createWebSocketsServer($action)

src/WebSockets/Channels/Channel.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,14 @@ public function broadcastToOthers(ConnectionInterface $connection, $payload)
9595
public function broadcastToEveryoneExcept($payload, ?string $socketId = null, ?string $appId = null)
9696
{
9797
if (config('websockets.replication.enabled') === true) {
98-
app()->get(PubSubInterface::class)->publish($appId, $payload);
98+
// Also broadcast via the other websocket instances
99+
app()->get(PubSubInterface::class)
100+
->publish($appId, $payload);
99101
}
100102

101103
if (is_null($socketId)) {
102-
return $this->broadcast($payload);
104+
$this->broadcast($payload);
105+
return;
103106
}
104107

105108
foreach ($this->subscribedConnections as $connection) {

src/WebSockets/Channels/ChannelManagers/ArrayChannelManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ArrayChannelManager implements ChannelManager
1515
/** @var string */
1616
protected $appId;
1717

18-
/** @var array */
18+
/** @var Channel[][] */
1919
protected $channels = [];
2020

2121
public function findOrCreate(string $appId, string $channelName): Channel

0 commit comments

Comments
 (0)