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

Commit 9ce2cc3

Browse files
authored
Apply fixes from StyleCI (#3)
1 parent b3e5df4 commit 9ce2cc3

File tree

69 files changed

+288
-328
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+288
-328
lines changed

config/websockets.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
* When the clean-command is executed, all recorded statistics older than
6565
* the number of days specified here will be deleted.
6666
*/
67-
'delete_statistics_older_than_days' => 60
67+
'delete_statistics_older_than_days' => 60,
6868
],
6969

7070
/*
@@ -89,6 +89,6 @@
8989
/*
9090
* Passphrase for your local_cert file.
9191
*/
92-
'passphrase' => null
92+
'passphrase' => null,
9393
],
9494
];

src/Apps/App.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ public static function findById($appId)
2929
return app(AppProvider::class)->findById($appId);
3030
}
3131

32-
public static function findByKey(string $appKey): ?App
32+
public static function findByKey(string $appKey): ?self
3333
{
3434
return app(AppProvider::class)->findByKey($appKey);
3535
}
3636

37-
public static function findBySecret(string $appSecret): ?App
37+
public static function findBySecret(string $appSecret): ?self
3838
{
3939
return app(AppProvider::class)->findBySecret($appSecret);
4040
}

src/Apps/AppProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ public function findById($appId): ?App;
1212
public function findByKey(string $appKey): ?App;
1313

1414
public function findBySecret(string $appSecret): ?App;
15-
}
15+
}

src/Apps/ConfigAppProvider.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function findBySecret(string $appSecret): ?App
5353

5454
protected function instanciate(?array $appAttributes): ?App
5555
{
56-
if (!$appAttributes) {
56+
if (! $appAttributes) {
5757
return null;
5858
}
5959

@@ -71,7 +71,6 @@ protected function instanciate(?array $appAttributes): ?App
7171
->enableClientMessages($appAttributes['enable_client_messages'])
7272
->enableStatistics($appAttributes['enable_statistics']);
7373

74-
7574
return $app;
7675
}
77-
}
76+
}

src/Console/CleanStatistics.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
class CleanStatistics extends Command
1010
{
11-
1211
protected $signature = 'websockets:clean
1312
{appId? : (optional) The app id that will be cleaned.}';
1413

@@ -36,4 +35,4 @@ public function handle()
3635

3736
$this->comment('All done!');
3837
}
39-
}
38+
}

src/Console/StartWebSocketServer.php

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,21 @@
22

33
namespace BeyondCode\LaravelWebSockets\Console;
44

5+
use React\Socket\Connector;
6+
use Clue\React\Buzz\Browser;
7+
use Illuminate\Console\Command;
8+
use React\EventLoop\Factory as LoopFactory;
9+
use BeyondCode\LaravelWebSockets\Statistics\DnsResolver;
510
use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger;
611
use BeyondCode\LaravelWebSockets\Facades\WebSocketsRouter;
7-
use BeyondCode\LaravelWebSockets\Server\Logger\ConnectionLogger;
812
use BeyondCode\LaravelWebSockets\Server\Logger\HttpLogger;
13+
use BeyondCode\LaravelWebSockets\Server\WebSocketServerFactory;
14+
use BeyondCode\LaravelWebSockets\Server\Logger\ConnectionLogger;
915
use BeyondCode\LaravelWebSockets\Server\Logger\WebsocketsLogger;
10-
use BeyondCode\LaravelWebSockets\Statistics\DnsResolver;
16+
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
1117
use BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger;
1218
use BeyondCode\LaravelWebSockets\Statistics\Logger\StatisticsLogger as StatisticsLoggerInterface;
1319

14-
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
15-
use Clue\React\Buzz\Browser;
16-
use Illuminate\Console\Command;
17-
use BeyondCode\LaravelWebSockets\Server\WebSocketServerFactory;
18-
19-
use React\EventLoop\Factory as LoopFactory;
20-
use React\Socket\Connector;
21-
2220
class StartWebSocketServer extends Command
2321
{
2422
protected $signature = 'websockets:serve {--host=0.0.0.0} {--port=6001} ';
@@ -49,16 +47,16 @@ public function handle()
4947
protected function configureStatisticsLogger()
5048
{
5149
$connector = new Connector($this->loop, [
52-
'dns' => new DnsResolver()
50+
'dns' => new DnsResolver(),
5351
]);
5452

5553
$browser = new Browser($this->loop, $connector);
5654

57-
app()->singleton(StatisticsLoggerInterface::class, function() use ($browser) {
55+
app()->singleton(StatisticsLoggerInterface::class, function () use ($browser) {
5856
return new HttpStatisticsLogger(app(ChannelManager::class), $browser);
5957
});
6058

61-
$this->loop->addPeriodicTimer(config('websockets.statistics.interval_in_seconds'), function() {
59+
$this->loop->addPeriodicTimer(config('websockets.statistics.interval_in_seconds'), function () {
6260
StatisticsLogger::save();
6361
});
6462

@@ -67,7 +65,7 @@ protected function configureStatisticsLogger()
6765

6866
protected function configureHttpLogger()
6967
{
70-
app()->singleton(HttpLogger::class, function() {
68+
app()->singleton(HttpLogger::class, function () {
7169
return (new HttpLogger($this->output))
7270
->enable(config('app.debug'))
7371
->verbose($this->output->isVerbose());
@@ -78,7 +76,7 @@ protected function configureHttpLogger()
7876

7977
protected function configureMessageLogger()
8078
{
81-
app()->singleton(WebsocketsLogger::class, function() {
79+
app()->singleton(WebsocketsLogger::class, function () {
8280
return (new WebsocketsLogger($this->output))
8381
->enable(config('app.debug'))
8482
->verbose($this->output->isVerbose());
@@ -89,7 +87,7 @@ protected function configureMessageLogger()
8987

9088
protected function configureConnectionLogger()
9189
{
92-
app()->bind(ConnectionLogger::class, function() {
90+
app()->bind(ConnectionLogger::class, function () {
9391
return (new ConnectionLogger($this->output))
9492
->enable(config('app.debug'))
9593
->verbose($this->output->isVerbose());
@@ -111,7 +109,7 @@ protected function startWebSocketServer()
111109

112110
$routes = WebSocketsRouter::getRoutes();
113111

114-
/** 🛰 Start the server 🛰 */
112+
/* 🛰 Start the server 🛰 */
115113
(new WebSocketServerFactory())
116114
->setLoop($this->loop)
117115
->useRoutes($routes)

src/Dashboard/DashboardLogger.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace BeyondCode\LaravelWebSockets\Dashboard;
44

5+
use stdClass;
56
use Ratchet\ConnectionInterface;
67
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
7-
use stdClass;
88

99
class DashboardLogger
1010
{
@@ -76,7 +76,7 @@ public static function apiMessage($appId, string $channel, string $event, string
7676

7777
public static function log($appId, string $type, array $attributes = [])
7878
{
79-
$channelName = static::LOG_CHANNEL_PREFIX . $type;
79+
$channelName = static::LOG_CHANNEL_PREFIX.$type;
8080

8181
$channel = app(ChannelManager::class)->find($appId, $channelName);
8282

@@ -85,9 +85,8 @@ public static function log($appId, string $type, array $attributes = [])
8585
'channel' => $channelName,
8686
'data' => [
8787
'type' => $type,
88-
'time' => strftime("%H:%M:%S")
88+
'time' => strftime('%H:%M:%S'),
8989
] + $attributes,
9090
]);
9191
}
92-
93-
}
92+
}

src/Dashboard/Http/Controllers/AuthenticateDashboard.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ public function __invoke(Request $request, Broadcaster $broadcaster)
1616
*/
1717
return $broadcaster->validAuthenticationResponse($request, []);
1818
}
19-
}
19+
}

src/Dashboard/Http/Controllers/DashboardApiController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public function getStatistics($appId)
1111

1212
$statisticData = $statistics->map(function ($statistic) {
1313
return [
14-
'timestamp' => (string)$statistic->created_at,
14+
'timestamp' => (string) $statistic->created_at,
1515
'peak_connection_count' => $statistic->peak_connection_count,
1616
'websocket_message_count' => $statistic->websocket_message_count,
1717
'api_message_count' => $statistic->api_message_count,
@@ -30,7 +30,7 @@ public function getStatistics($appId)
3030
'api_message_count' => [
3131
'x' => $statisticData->pluck('timestamp'),
3232
'y' => $statisticData->pluck('api_message_count'),
33-
]
33+
],
3434
];
3535
}
36-
}
36+
}

src/Dashboard/Http/Controllers/SendMessage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers;
44

5-
use BeyondCode\LaravelWebSockets\Statistics\Rules\AppId;
65
use Pusher\Pusher;
76
use Illuminate\Http\Request;
7+
use BeyondCode\LaravelWebSockets\Statistics\Rules\AppId;
88
use Illuminate\Broadcasting\Broadcasters\PusherBroadcaster;
99

1010
class SendMessage

src/Dashboard/Http/Controllers/ShowDashboard.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ public function __invoke(Request $request, AppProvider $apps)
1313
'apps' => $apps->all(),
1414
]);
1515
}
16-
}
16+
}

src/Dashboard/Http/Middleware/Authorize.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ public function handle($request, $next)
1010
{
1111
return Gate::check('viewWebSocketsDashboard') ? $next($request) : abort(403);
1212
}
13-
}
13+
}

src/Exceptions/InvalidApp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ public static function valueIsRequired($name, $appId)
1515
{
1616
return new static("{$name} is required but was empty for app id `{$appId}`.");
1717
}
18-
}
18+
}

src/Exceptions/InvalidWebSocketController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ public static function withController(string $controllerClass)
1212

1313
return new static("Invalid WebSocket Controller provided. Expected instance of `{$messageComponentInterfaceClass}`, but received `{$controllerClass}`.");
1414
}
15-
}
15+
}

src/Facades/StatisticsLogger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace BeyondCode\LaravelWebSockets\Facades;
44

5+
use Illuminate\Support\Facades\Facade;
56
use BeyondCode\LaravelWebSockets\Statistics\Logger\FakeStatisticsLogger;
67
use BeyondCode\LaravelWebSockets\Statistics\Logger\StatisticsLogger as StatisticsLoggerInterface;
7-
use Illuminate\Support\Facades\Facade;
88

99
/** @see \BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger */
1010
class StatisticsLogger extends Facade

src/HttpApi/Controllers/Controller.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
namespace BeyondCode\LaravelWebSockets\HttpApi\Controllers;
44

5-
use BeyondCode\LaravelWebSockets\Apps\App;
6-
use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger;
7-
use BeyondCode\LaravelWebSockets\Events\ExceptionThrown;
8-
use BeyondCode\LaravelWebSockets\QueryParameters;
95
use Exception;
106
use Illuminate\Http\Request;
117
use GuzzleHttp\Psr7\Response;
@@ -14,6 +10,8 @@
1410
use GuzzleHttp\Psr7\ServerRequest;
1511
use Ratchet\Http\HttpServerInterface;
1612
use Psr\Http\Message\RequestInterface;
13+
use BeyondCode\LaravelWebSockets\Apps\App;
14+
use BeyondCode\LaravelWebSockets\QueryParameters;
1715
use Symfony\Component\HttpKernel\Exception\HttpException;
1816
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
1917
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
@@ -50,24 +48,24 @@ public function onOpen(ConnectionInterface $connection, RequestInterface $reques
5048
$connection->close();
5149
}
5250

53-
function onMessage(ConnectionInterface $from, $msg)
51+
public function onMessage(ConnectionInterface $from, $msg)
5452
{
5553
}
5654

57-
function onClose(ConnectionInterface $connection)
55+
public function onClose(ConnectionInterface $connection)
5856
{
5957
}
6058

61-
function onError(ConnectionInterface $connection, Exception $exception)
59+
public function onError(ConnectionInterface $connection, Exception $exception)
6260
{
6361
if (! $exception instanceof HttpException) {
6462
return;
6563
}
6664

6765
$response = new Response($exception->getStatusCode(), [
68-
'Content-Type' => 'application/json'
66+
'Content-Type' => 'application/json',
6967
], json_encode([
70-
'error' => $exception->getMessage()
68+
'error' => $exception->getMessage(),
7169
]));
7270

7371
$connection->send(\GuzzleHttp\Psr7\str($response));
@@ -86,11 +84,10 @@ public function ensureValidAppId(string $appId)
8684

8785
protected function ensureValidSignature(Request $request)
8886
{
89-
9087
$signature =
91-
"{$request->getMethod()}\n/{$request->path()}\n" .
92-
"auth_key={$request->get('auth_key')}" .
93-
"&auth_timestamp={$request->get('auth_timestamp')}" .
88+
"{$request->getMethod()}\n/{$request->path()}\n".
89+
"auth_key={$request->get('auth_key')}".
90+
"&auth_timestamp={$request->get('auth_timestamp')}".
9491
"&auth_version={$request->get('auth_version')}";
9592

9693
if ($request->getContent() !== '') {
@@ -109,4 +106,4 @@ protected function ensureValidSignature(Request $request)
109106
}
110107

111108
abstract public function __invoke(Request $request);
112-
}
109+
}

src/HttpApi/Controllers/FetchChannelController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace BeyondCode\LaravelWebSockets\HttpApi\Controllers;
44

5-
use BeyondCode\LaravelWebSockets\HttpApi\Controllers\Controller;
65
use Illuminate\Http\Request;
76
use Symfony\Component\HttpKernel\Exception\HttpException;
87

@@ -18,4 +17,4 @@ public function __invoke(Request $request)
1817

1918
return $channel->toArray();
2019
}
21-
}
20+
}

src/HttpApi/Controllers/FetchChannelsController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace BeyondCode\LaravelWebSockets\HttpApi\Controllers;
44

5-
use BeyondCode\LaravelWebSockets\HttpApi\Controllers\Controller;
65
use Illuminate\Http\Request;
76
use Illuminate\Support\Collection;
87
use BeyondCode\LaravelWebSockets\WebSockets\Channels\PresenceChannel;
@@ -26,7 +25,7 @@ public function __invoke(Request $request)
2625
return [
2726
'user_count' => count($channel->getUsers()),
2827
];
29-
})->toArray()
28+
})->toArray(),
3029
];
3130
}
32-
}
31+
}

src/HttpApi/Controllers/FetchUsersController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace BeyondCode\LaravelWebSockets\HttpApi\Controllers;
44

5-
use BeyondCode\LaravelWebSockets\HttpApi\Controllers\Controller;
65
use Illuminate\Http\Request;
76
use Illuminate\Support\Collection;
87
use Symfony\Component\HttpKernel\Exception\HttpException;
@@ -25,7 +24,7 @@ public function __invoke(Request $request)
2524
return [
2625
'users' => Collection::make($channel->getUsers())->map(function ($user) {
2726
return ['id' => $user->user_id];
28-
})->values()
27+
})->values(),
2928
];
3029
}
31-
}
30+
}

0 commit comments

Comments
 (0)