diff --git a/config/websockets.php b/config/websockets.php index 508a0b0ece..40aaa24eeb 100644 --- a/config/websockets.php +++ b/config/websockets.php @@ -64,7 +64,7 @@ * When the clean-command is executed, all recorded statistics older than * the number of days specified here will be deleted. */ - 'delete_statistics_older_than_days' => 60 + 'delete_statistics_older_than_days' => 60, ], /* @@ -89,6 +89,6 @@ /* * Passphrase for your local_cert file. */ - 'passphrase' => null + 'passphrase' => null, ], ]; diff --git a/src/Apps/App.php b/src/Apps/App.php index 9d14cb811d..dcb17843f4 100644 --- a/src/Apps/App.php +++ b/src/Apps/App.php @@ -29,12 +29,12 @@ public static function findById($appId) return app(AppProvider::class)->findById($appId); } - public static function findByKey(string $appKey): ?App + public static function findByKey(string $appKey): ?self { return app(AppProvider::class)->findByKey($appKey); } - public static function findBySecret(string $appSecret): ?App + public static function findBySecret(string $appSecret): ?self { return app(AppProvider::class)->findBySecret($appSecret); } diff --git a/src/Apps/AppProvider.php b/src/Apps/AppProvider.php index d022d95005..02de343563 100644 --- a/src/Apps/AppProvider.php +++ b/src/Apps/AppProvider.php @@ -12,4 +12,4 @@ public function findById($appId): ?App; public function findByKey(string $appKey): ?App; public function findBySecret(string $appSecret): ?App; -} \ No newline at end of file +} diff --git a/src/Apps/ConfigAppProvider.php b/src/Apps/ConfigAppProvider.php index 8e5297d6c6..a0ded0f665 100644 --- a/src/Apps/ConfigAppProvider.php +++ b/src/Apps/ConfigAppProvider.php @@ -53,7 +53,7 @@ public function findBySecret(string $appSecret): ?App protected function instanciate(?array $appAttributes): ?App { - if (!$appAttributes) { + if (! $appAttributes) { return null; } @@ -71,7 +71,6 @@ protected function instanciate(?array $appAttributes): ?App ->enableClientMessages($appAttributes['enable_client_messages']) ->enableStatistics($appAttributes['enable_statistics']); - return $app; } -} \ No newline at end of file +} diff --git a/src/Console/CleanStatistics.php b/src/Console/CleanStatistics.php index 23e3d1eb9c..aba815f51a 100644 --- a/src/Console/CleanStatistics.php +++ b/src/Console/CleanStatistics.php @@ -8,7 +8,6 @@ class CleanStatistics extends Command { - protected $signature = 'websockets:clean {appId? : (optional) The app id that will be cleaned.}'; @@ -36,4 +35,4 @@ public function handle() $this->comment('All done!'); } -} \ No newline at end of file +} diff --git a/src/Console/StartWebSocketServer.php b/src/Console/StartWebSocketServer.php index 65933f1c26..e7ae29a5f4 100644 --- a/src/Console/StartWebSocketServer.php +++ b/src/Console/StartWebSocketServer.php @@ -2,23 +2,21 @@ namespace BeyondCode\LaravelWebSockets\Console; +use React\Socket\Connector; +use Clue\React\Buzz\Browser; +use Illuminate\Console\Command; +use React\EventLoop\Factory as LoopFactory; +use BeyondCode\LaravelWebSockets\Statistics\DnsResolver; use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger; use BeyondCode\LaravelWebSockets\Facades\WebSocketsRouter; -use BeyondCode\LaravelWebSockets\Server\Logger\ConnectionLogger; use BeyondCode\LaravelWebSockets\Server\Logger\HttpLogger; +use BeyondCode\LaravelWebSockets\Server\WebSocketServerFactory; +use BeyondCode\LaravelWebSockets\Server\Logger\ConnectionLogger; use BeyondCode\LaravelWebSockets\Server\Logger\WebsocketsLogger; -use BeyondCode\LaravelWebSockets\Statistics\DnsResolver; +use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; use BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger; use BeyondCode\LaravelWebSockets\Statistics\Logger\StatisticsLogger as StatisticsLoggerInterface; -use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; -use Clue\React\Buzz\Browser; -use Illuminate\Console\Command; -use BeyondCode\LaravelWebSockets\Server\WebSocketServerFactory; - -use React\EventLoop\Factory as LoopFactory; -use React\Socket\Connector; - class StartWebSocketServer extends Command { protected $signature = 'websockets:serve {--host=0.0.0.0} {--port=6001} '; @@ -49,16 +47,16 @@ public function handle() protected function configureStatisticsLogger() { $connector = new Connector($this->loop, [ - 'dns' => new DnsResolver() + 'dns' => new DnsResolver(), ]); $browser = new Browser($this->loop, $connector); - app()->singleton(StatisticsLoggerInterface::class, function() use ($browser) { + app()->singleton(StatisticsLoggerInterface::class, function () use ($browser) { return new HttpStatisticsLogger(app(ChannelManager::class), $browser); }); - $this->loop->addPeriodicTimer(config('websockets.statistics.interval_in_seconds'), function() { + $this->loop->addPeriodicTimer(config('websockets.statistics.interval_in_seconds'), function () { StatisticsLogger::save(); }); @@ -67,7 +65,7 @@ protected function configureStatisticsLogger() protected function configureHttpLogger() { - app()->singleton(HttpLogger::class, function() { + app()->singleton(HttpLogger::class, function () { return (new HttpLogger($this->output)) ->enable(config('app.debug')) ->verbose($this->output->isVerbose()); @@ -78,7 +76,7 @@ protected function configureHttpLogger() protected function configureMessageLogger() { - app()->singleton(WebsocketsLogger::class, function() { + app()->singleton(WebsocketsLogger::class, function () { return (new WebsocketsLogger($this->output)) ->enable(config('app.debug')) ->verbose($this->output->isVerbose()); @@ -89,7 +87,7 @@ protected function configureMessageLogger() protected function configureConnectionLogger() { - app()->bind(ConnectionLogger::class, function() { + app()->bind(ConnectionLogger::class, function () { return (new ConnectionLogger($this->output)) ->enable(config('app.debug')) ->verbose($this->output->isVerbose()); @@ -111,7 +109,7 @@ protected function startWebSocketServer() $routes = WebSocketsRouter::getRoutes(); - /** 🛰 Start the server 🛰 */ + /* 🛰 Start the server 🛰 */ (new WebSocketServerFactory()) ->setLoop($this->loop) ->useRoutes($routes) diff --git a/src/Dashboard/DashboardLogger.php b/src/Dashboard/DashboardLogger.php index a15d4958dd..315135fbde 100644 --- a/src/Dashboard/DashboardLogger.php +++ b/src/Dashboard/DashboardLogger.php @@ -2,9 +2,9 @@ namespace BeyondCode\LaravelWebSockets\Dashboard; +use stdClass; use Ratchet\ConnectionInterface; use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; -use stdClass; class DashboardLogger { @@ -76,7 +76,7 @@ public static function apiMessage($appId, string $channel, string $event, string public static function log($appId, string $type, array $attributes = []) { - $channelName = static::LOG_CHANNEL_PREFIX . $type; + $channelName = static::LOG_CHANNEL_PREFIX.$type; $channel = app(ChannelManager::class)->find($appId, $channelName); @@ -85,9 +85,8 @@ public static function log($appId, string $type, array $attributes = []) 'channel' => $channelName, 'data' => [ 'type' => $type, - 'time' => strftime("%H:%M:%S") + 'time' => strftime('%H:%M:%S'), ] + $attributes, ]); } - -} \ No newline at end of file +} diff --git a/src/Dashboard/Http/Controllers/AuthenticateDashboard.php b/src/Dashboard/Http/Controllers/AuthenticateDashboard.php index dd7da7f5d4..8e58775fca 100644 --- a/src/Dashboard/Http/Controllers/AuthenticateDashboard.php +++ b/src/Dashboard/Http/Controllers/AuthenticateDashboard.php @@ -16,4 +16,4 @@ public function __invoke(Request $request, Broadcaster $broadcaster) */ return $broadcaster->validAuthenticationResponse($request, []); } -} \ No newline at end of file +} diff --git a/src/Dashboard/Http/Controllers/DashboardApiController.php b/src/Dashboard/Http/Controllers/DashboardApiController.php index f7eecb525d..1d77b9d874 100644 --- a/src/Dashboard/Http/Controllers/DashboardApiController.php +++ b/src/Dashboard/Http/Controllers/DashboardApiController.php @@ -11,7 +11,7 @@ public function getStatistics($appId) $statisticData = $statistics->map(function ($statistic) { return [ - 'timestamp' => (string)$statistic->created_at, + 'timestamp' => (string) $statistic->created_at, 'peak_connection_count' => $statistic->peak_connection_count, 'websocket_message_count' => $statistic->websocket_message_count, 'api_message_count' => $statistic->api_message_count, @@ -30,7 +30,7 @@ public function getStatistics($appId) 'api_message_count' => [ 'x' => $statisticData->pluck('timestamp'), 'y' => $statisticData->pluck('api_message_count'), - ] + ], ]; } -} \ No newline at end of file +} diff --git a/src/Dashboard/Http/Controllers/SendMessage.php b/src/Dashboard/Http/Controllers/SendMessage.php index eea53a3e37..5c4461af62 100644 --- a/src/Dashboard/Http/Controllers/SendMessage.php +++ b/src/Dashboard/Http/Controllers/SendMessage.php @@ -2,9 +2,9 @@ namespace BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers; -use BeyondCode\LaravelWebSockets\Statistics\Rules\AppId; use Pusher\Pusher; use Illuminate\Http\Request; +use BeyondCode\LaravelWebSockets\Statistics\Rules\AppId; use Illuminate\Broadcasting\Broadcasters\PusherBroadcaster; class SendMessage diff --git a/src/Dashboard/Http/Controllers/ShowDashboard.php b/src/Dashboard/Http/Controllers/ShowDashboard.php index 3541c45c7d..5e04c7aa12 100644 --- a/src/Dashboard/Http/Controllers/ShowDashboard.php +++ b/src/Dashboard/Http/Controllers/ShowDashboard.php @@ -13,4 +13,4 @@ public function __invoke(Request $request, AppProvider $apps) 'apps' => $apps->all(), ]); } -} \ No newline at end of file +} diff --git a/src/Dashboard/Http/Middleware/Authorize.php b/src/Dashboard/Http/Middleware/Authorize.php index 0314cb8702..772107fc78 100644 --- a/src/Dashboard/Http/Middleware/Authorize.php +++ b/src/Dashboard/Http/Middleware/Authorize.php @@ -10,4 +10,4 @@ public function handle($request, $next) { return Gate::check('viewWebSocketsDashboard') ? $next($request) : abort(403); } -} \ No newline at end of file +} diff --git a/src/Exceptions/InvalidApp.php b/src/Exceptions/InvalidApp.php index 49b230bed1..1d20402589 100644 --- a/src/Exceptions/InvalidApp.php +++ b/src/Exceptions/InvalidApp.php @@ -15,4 +15,4 @@ public static function valueIsRequired($name, $appId) { return new static("{$name} is required but was empty for app id `{$appId}`."); } -} \ No newline at end of file +} diff --git a/src/Exceptions/InvalidWebSocketController.php b/src/Exceptions/InvalidWebSocketController.php index 2c03d9c863..96c1a4ae8b 100644 --- a/src/Exceptions/InvalidWebSocketController.php +++ b/src/Exceptions/InvalidWebSocketController.php @@ -12,4 +12,4 @@ public static function withController(string $controllerClass) return new static("Invalid WebSocket Controller provided. Expected instance of `{$messageComponentInterfaceClass}`, but received `{$controllerClass}`."); } -} \ No newline at end of file +} diff --git a/src/Facades/StatisticsLogger.php b/src/Facades/StatisticsLogger.php index 6bb86c9d76..c43aab492c 100644 --- a/src/Facades/StatisticsLogger.php +++ b/src/Facades/StatisticsLogger.php @@ -2,9 +2,9 @@ namespace BeyondCode\LaravelWebSockets\Facades; +use Illuminate\Support\Facades\Facade; use BeyondCode\LaravelWebSockets\Statistics\Logger\FakeStatisticsLogger; use BeyondCode\LaravelWebSockets\Statistics\Logger\StatisticsLogger as StatisticsLoggerInterface; -use Illuminate\Support\Facades\Facade; /** @see \BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger */ class StatisticsLogger extends Facade diff --git a/src/HttpApi/Controllers/Controller.php b/src/HttpApi/Controllers/Controller.php index b2da458dc2..f88c49c640 100644 --- a/src/HttpApi/Controllers/Controller.php +++ b/src/HttpApi/Controllers/Controller.php @@ -2,10 +2,6 @@ namespace BeyondCode\LaravelWebSockets\HttpApi\Controllers; -use BeyondCode\LaravelWebSockets\Apps\App; -use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger; -use BeyondCode\LaravelWebSockets\Events\ExceptionThrown; -use BeyondCode\LaravelWebSockets\QueryParameters; use Exception; use Illuminate\Http\Request; use GuzzleHttp\Psr7\Response; @@ -14,6 +10,8 @@ use GuzzleHttp\Psr7\ServerRequest; use Ratchet\Http\HttpServerInterface; use Psr\Http\Message\RequestInterface; +use BeyondCode\LaravelWebSockets\Apps\App; +use BeyondCode\LaravelWebSockets\QueryParameters; use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory; use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; @@ -50,24 +48,24 @@ public function onOpen(ConnectionInterface $connection, RequestInterface $reques $connection->close(); } - function onMessage(ConnectionInterface $from, $msg) + public function onMessage(ConnectionInterface $from, $msg) { } - function onClose(ConnectionInterface $connection) + public function onClose(ConnectionInterface $connection) { } - function onError(ConnectionInterface $connection, Exception $exception) + public function onError(ConnectionInterface $connection, Exception $exception) { if (! $exception instanceof HttpException) { return; } $response = new Response($exception->getStatusCode(), [ - 'Content-Type' => 'application/json' + 'Content-Type' => 'application/json', ], json_encode([ - 'error' => $exception->getMessage() + 'error' => $exception->getMessage(), ])); $connection->send(\GuzzleHttp\Psr7\str($response)); @@ -86,11 +84,10 @@ public function ensureValidAppId(string $appId) protected function ensureValidSignature(Request $request) { - $signature = - "{$request->getMethod()}\n/{$request->path()}\n" . - "auth_key={$request->get('auth_key')}" . - "&auth_timestamp={$request->get('auth_timestamp')}" . + "{$request->getMethod()}\n/{$request->path()}\n". + "auth_key={$request->get('auth_key')}". + "&auth_timestamp={$request->get('auth_timestamp')}". "&auth_version={$request->get('auth_version')}"; if ($request->getContent() !== '') { @@ -109,4 +106,4 @@ protected function ensureValidSignature(Request $request) } abstract public function __invoke(Request $request); -} \ No newline at end of file +} diff --git a/src/HttpApi/Controllers/FetchChannelController.php b/src/HttpApi/Controllers/FetchChannelController.php index af7a96ed01..6a24fd5e2c 100644 --- a/src/HttpApi/Controllers/FetchChannelController.php +++ b/src/HttpApi/Controllers/FetchChannelController.php @@ -2,7 +2,6 @@ namespace BeyondCode\LaravelWebSockets\HttpApi\Controllers; -use BeyondCode\LaravelWebSockets\HttpApi\Controllers\Controller; use Illuminate\Http\Request; use Symfony\Component\HttpKernel\Exception\HttpException; @@ -18,4 +17,4 @@ public function __invoke(Request $request) return $channel->toArray(); } -} \ No newline at end of file +} diff --git a/src/HttpApi/Controllers/FetchChannelsController.php b/src/HttpApi/Controllers/FetchChannelsController.php index 26564d6f13..937000e08b 100644 --- a/src/HttpApi/Controllers/FetchChannelsController.php +++ b/src/HttpApi/Controllers/FetchChannelsController.php @@ -2,7 +2,6 @@ namespace BeyondCode\LaravelWebSockets\HttpApi\Controllers; -use BeyondCode\LaravelWebSockets\HttpApi\Controllers\Controller; use Illuminate\Http\Request; use Illuminate\Support\Collection; use BeyondCode\LaravelWebSockets\WebSockets\Channels\PresenceChannel; @@ -26,7 +25,7 @@ public function __invoke(Request $request) return [ 'user_count' => count($channel->getUsers()), ]; - })->toArray() + })->toArray(), ]; } -} \ No newline at end of file +} diff --git a/src/HttpApi/Controllers/FetchUsersController.php b/src/HttpApi/Controllers/FetchUsersController.php index 9b3551d0c3..87960e44f9 100644 --- a/src/HttpApi/Controllers/FetchUsersController.php +++ b/src/HttpApi/Controllers/FetchUsersController.php @@ -2,7 +2,6 @@ namespace BeyondCode\LaravelWebSockets\HttpApi\Controllers; -use BeyondCode\LaravelWebSockets\HttpApi\Controllers\Controller; use Illuminate\Http\Request; use Illuminate\Support\Collection; use Symfony\Component\HttpKernel\Exception\HttpException; @@ -25,7 +24,7 @@ public function __invoke(Request $request) return [ 'users' => Collection::make($channel->getUsers())->map(function ($user) { return ['id' => $user->user_id]; - })->values() + })->values(), ]; } -} \ No newline at end of file +} diff --git a/src/HttpApi/Controllers/TriggerEventController.php b/src/HttpApi/Controllers/TriggerEventController.php index cd81729fae..076407126c 100644 --- a/src/HttpApi/Controllers/TriggerEventController.php +++ b/src/HttpApi/Controllers/TriggerEventController.php @@ -2,9 +2,9 @@ namespace BeyondCode\LaravelWebSockets\HttpApi\Controllers; -use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger; -use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger; use Illuminate\Http\Request; +use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger; +use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger; class TriggerEventController extends Controller { @@ -33,4 +33,4 @@ public function __invoke(Request $request) return $request->json()->all(); } -} \ No newline at end of file +} diff --git a/src/QueryParameters.php b/src/QueryParameters.php index 85fecffc7c..85ee8af9a2 100644 --- a/src/QueryParameters.php +++ b/src/QueryParameters.php @@ -32,4 +32,4 @@ public function get(string $name): string { return $this->all()[$name] ?? ''; } -} \ No newline at end of file +} diff --git a/src/Server/HttpServer.php b/src/Server/HttpServer.php index 82a26d45d5..2c33737275 100644 --- a/src/Server/HttpServer.php +++ b/src/Server/HttpServer.php @@ -12,4 +12,4 @@ public function __construct(HttpServerInterface $component, int $maxRequestSize $this->_reqParser->maxSize = $maxRequestSize; } -} \ No newline at end of file +} diff --git a/src/Server/Logger/ConnectionLogger.php b/src/Server/Logger/ConnectionLogger.php index 6e0676258d..154c6c2588 100644 --- a/src/Server/Logger/ConnectionLogger.php +++ b/src/Server/Logger/ConnectionLogger.php @@ -9,9 +9,9 @@ class ConnectionLogger extends Logger implements ConnectionInterface /** @var \Ratchet\ConnectionInterface */ protected $connection; - public static function decorate(ConnectionInterface $app): ConnectionLogger + public static function decorate(ConnectionInterface $app): self { - $logger = app(ConnectionLogger::class); + $logger = app(self::class); return $logger->setConnection($app); } @@ -54,11 +54,13 @@ public function __get($name) return $this->connection->$name; } - public function __isset($name) { + public function __isset($name) + { return isset($this->connection->$name); } - public function __unset($name) { + public function __unset($name) + { unset($this->connection->$name); } -} \ No newline at end of file +} diff --git a/src/Server/Logger/HttpLogger.php b/src/Server/Logger/HttpLogger.php index 7058bad192..b60b09983e 100644 --- a/src/Server/Logger/HttpLogger.php +++ b/src/Server/Logger/HttpLogger.php @@ -11,9 +11,9 @@ class HttpLogger extends Logger implements MessageComponentInterface /** @var \Ratchet\Http\HttpServerInterface */ protected $app; - public static function decorate(MessageComponentInterface $app): HttpLogger + public static function decorate(MessageComponentInterface $app): self { - $logger = app(HttpLogger::class); + $logger = app(self::class); return $logger->setApp($app); } @@ -54,5 +54,4 @@ public function onError(ConnectionInterface $connection, Exception $exception) $this->app->onError($connection, $exception); } - -} \ No newline at end of file +} diff --git a/src/Server/Logger/Logger.php b/src/Server/Logger/Logger.php index 434d4c845f..742230971b 100644 --- a/src/Server/Logger/Logger.php +++ b/src/Server/Logger/Logger.php @@ -67,4 +67,4 @@ protected function line(string $message, string $style) $this->consoleOutput->writeln($styled); } -} \ No newline at end of file +} diff --git a/src/Server/Logger/WebsocketsLogger.php b/src/Server/Logger/WebsocketsLogger.php index d4defc159a..2088ae3322 100644 --- a/src/Server/Logger/WebsocketsLogger.php +++ b/src/Server/Logger/WebsocketsLogger.php @@ -2,20 +2,20 @@ namespace BeyondCode\LaravelWebSockets\Server\Logger; -use BeyondCode\LaravelWebSockets\QueryParameters; use Exception; use Ratchet\ConnectionInterface; use Ratchet\RFC6455\Messaging\MessageInterface; use Ratchet\WebSocket\MessageComponentInterface; +use BeyondCode\LaravelWebSockets\QueryParameters; class WebsocketsLogger extends Logger implements MessageComponentInterface { /** @var \Ratchet\Http\HttpServerInterface */ protected $app; - public static function decorate(MessageComponentInterface $app): WebsocketsLogger + public static function decorate(MessageComponentInterface $app): self { - $logger = app(WebsocketsLogger::class); + $logger = app(self::class); return $logger->setApp($app); } @@ -68,5 +68,4 @@ public function onError(ConnectionInterface $connection, Exception $exception) $this->app->onError(ConnectionLogger::decorate($connection), $exception); } - -} \ No newline at end of file +} diff --git a/src/Server/OriginCheck.php b/src/Server/OriginCheck.php index 883efb72d0..dfebfff435 100644 --- a/src/Server/OriginCheck.php +++ b/src/Server/OriginCheck.php @@ -5,8 +5,8 @@ use Ratchet\ConnectionInterface; use Ratchet\Http\CloseResponseTrait; use Ratchet\Http\HttpServerInterface; -use Ratchet\MessageComponentInterface; use Psr\Http\Message\RequestInterface; +use Ratchet\MessageComponentInterface; class OriginCheck implements HttpServerInterface { @@ -33,28 +33,28 @@ public function onOpen(ConnectionInterface $connection, RequestInterface $reques return $this->_component->onOpen($connection, $request); } - function onMessage(ConnectionInterface $from, $msg) + public function onMessage(ConnectionInterface $from, $msg) { return $this->_component->onMessage($from, $msg); } - function onClose(ConnectionInterface $connection) + public function onClose(ConnectionInterface $connection) { return $this->_component->onClose($connection); } - function onError(ConnectionInterface $connection, \Exception $e) + public function onError(ConnectionInterface $connection, \Exception $e) { return $this->_component->onError($connection, $e); } protected function verifyOrigin(ConnectionInterface $connection, RequestInterface $request) { - $header = (string)$request->getHeader('Origin')[0]; + $header = (string) $request->getHeader('Origin')[0]; $origin = parse_url($header, PHP_URL_HOST) ?: $header; - if (!empty($this->allowedOrigins) && !in_array($origin, $this->allowedOrigins)) { + if (! empty($this->allowedOrigins) && ! in_array($origin, $this->allowedOrigins)) { return $this->close($connection, 403); } } -} \ No newline at end of file +} diff --git a/src/Server/Router.php b/src/Server/Router.php index d68c8e1ed6..25dbb77385 100644 --- a/src/Server/Router.php +++ b/src/Server/Router.php @@ -2,17 +2,17 @@ namespace BeyondCode\LaravelWebSockets\Server; -use BeyondCode\LaravelWebSockets\Server\Logger\WebsocketsLogger; -use BeyondCode\LaravelWebSockets\HttpApi\Controllers\FetchChannelController; -use BeyondCode\LaravelWebSockets\HttpApi\Controllers\FetchChannelsController; -use BeyondCode\LaravelWebSockets\HttpApi\Controllers\FetchUsersController; -use BeyondCode\LaravelWebSockets\HttpApi\Controllers\TriggerEventController; -use BeyondCode\LaravelWebSockets\WebSockets\WebSocketHandler; -use Ratchet\WebSocket\MessageComponentInterface; use Ratchet\WebSocket\WsServer; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; +use Ratchet\WebSocket\MessageComponentInterface; +use BeyondCode\LaravelWebSockets\WebSockets\WebSocketHandler; +use BeyondCode\LaravelWebSockets\Server\Logger\WebsocketsLogger; use BeyondCode\LaravelWebSockets\Exceptions\InvalidWebSocketController; +use BeyondCode\LaravelWebSockets\HttpApi\Controllers\FetchUsersController; +use BeyondCode\LaravelWebSockets\HttpApi\Controllers\FetchChannelController; +use BeyondCode\LaravelWebSockets\HttpApi\Controllers\TriggerEventController; +use BeyondCode\LaravelWebSockets\HttpApi\Controllers\FetchChannelsController; class Router { @@ -66,7 +66,7 @@ public function delete(string $uri, $action) public function webSocket(string $uri, $action) { - if (!is_subclass_of($action, MessageComponentInterface::class)) { + if (! is_subclass_of($action, MessageComponentInterface::class)) { throw InvalidWebSocketController::withController($action); } @@ -103,4 +103,4 @@ protected function createWebSocketsServer(string $action): WsServer return new WsServer($app); } -} \ No newline at end of file +} diff --git a/src/Server/WebSocketServerFactory.php b/src/Server/WebSocketServerFactory.php index aabdaf2b26..e7bdd82a9b 100644 --- a/src/Server/WebSocketServerFactory.php +++ b/src/Server/WebSocketServerFactory.php @@ -2,17 +2,17 @@ namespace BeyondCode\LaravelWebSockets\Server; -use BeyondCode\LaravelWebSockets\Server\Logger\HttpLogger; use Ratchet\Http\Router; -use React\Socket\SecureServer; use React\Socket\Server; use Ratchet\Server\IoServer; +use React\Socket\SecureServer; use React\EventLoop\LoopInterface; use React\EventLoop\Factory as LoopFactory; -use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Routing\RequestContext; -use Symfony\Component\Routing\Matcher\UrlMatcher; use Symfony\Component\Routing\RouteCollection; +use Symfony\Component\Routing\Matcher\UrlMatcher; +use Symfony\Component\Console\Output\OutputInterface; +use BeyondCode\LaravelWebSockets\Server\Logger\HttpLogger; class WebSocketServerFactory { diff --git a/src/Statistics/DnsResolver.php b/src/Statistics/DnsResolver.php index 29816a4866..824167c84d 100644 --- a/src/Statistics/DnsResolver.php +++ b/src/Statistics/DnsResolver.php @@ -19,4 +19,4 @@ public function resolve($domain) { return new FulfilledPromise('127.0.0.1'); } -} \ No newline at end of file +} diff --git a/src/Statistics/Events/StatisticsUpdated.php b/src/Statistics/Events/StatisticsUpdated.php index 9368309686..2a420fb133 100644 --- a/src/Statistics/Events/StatisticsUpdated.php +++ b/src/Statistics/Events/StatisticsUpdated.php @@ -2,11 +2,11 @@ namespace BeyondCode\LaravelWebsockets\Statistics\Events; -use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger; -use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry; +use Illuminate\Queue\SerializesModels; use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; -use Illuminate\Queue\SerializesModels; +use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger; +use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry; class StatisticsUpdated implements ShouldBroadcast { @@ -23,7 +23,7 @@ public function __construct(WebSocketsStatisticsEntry $webSocketsStatisticsEntry public function broadcastWith() { return [ - 'time' => (string)$this->webSocketsStatisticsEntry->created_at, + 'time' => (string) $this->webSocketsStatisticsEntry->created_at, 'app_id' => $this->webSocketsStatisticsEntry->app_id, 'peak_connection_count' => $this->webSocketsStatisticsEntry->peak_connection_count, 'websocket_message_count' => $this->webSocketsStatisticsEntry->websocket_message_count, @@ -33,7 +33,7 @@ public function broadcastWith() public function broadcastOn() { - $channelName = str_after(DashboardLogger::LOG_CHANNEL_PREFIX . 'statistics', 'private-'); + $channelName = str_after(DashboardLogger::LOG_CHANNEL_PREFIX.'statistics', 'private-'); return new PrivateChannel($channelName); } @@ -42,4 +42,4 @@ public function broadcastAs() { return 'statistics-updated'; } -} \ No newline at end of file +} diff --git a/src/Statistics/Http/Controllers/WebSocketStatisticsEntriesController.php b/src/Statistics/Http/Controllers/WebSocketStatisticsEntriesController.php index f898b2e607..39ea041748 100644 --- a/src/Statistics/Http/Controllers/WebSocketStatisticsEntriesController.php +++ b/src/Statistics/Http/Controllers/WebSocketStatisticsEntriesController.php @@ -2,9 +2,9 @@ namespace BeyondCode\LaravelWebSockets\Statistics\Http\Controllers; -use BeyondCode\LaravelWebSockets\Statistics\Events\StatisticsUpdated; -use BeyondCode\LaravelWebSockets\Statistics\Rules\AppId; use Illuminate\Http\Request; +use BeyondCode\LaravelWebSockets\Statistics\Rules\AppId; +use BeyondCode\LaravelWebSockets\Statistics\Events\StatisticsUpdated; class WebSocketStatisticsEntriesController { @@ -25,4 +25,4 @@ public function store(Request $request) return 'ok'; } -} \ No newline at end of file +} diff --git a/src/Statistics/Http/Middleware/Authorize.php b/src/Statistics/Http/Middleware/Authorize.php index 32e19a6578..277d8e401b 100644 --- a/src/Statistics/Http/Middleware/Authorize.php +++ b/src/Statistics/Http/Middleware/Authorize.php @@ -10,4 +10,4 @@ public function handle($request, $next) { return is_null(App::findBySecret($request->secret)) ? abort(403) : $next($request); } -} \ No newline at end of file +} diff --git a/src/Statistics/Logger/FakeStatisticsLogger.php b/src/Statistics/Logger/FakeStatisticsLogger.php index d6bc7590aa..63a8640115 100644 --- a/src/Statistics/Logger/FakeStatisticsLogger.php +++ b/src/Statistics/Logger/FakeStatisticsLogger.php @@ -2,41 +2,31 @@ namespace BeyondCode\LaravelWebSockets\Statistics\Logger; -use BeyondCode\LaravelWebSockets\Statistics\Http\Controllers\WebSocketStatisticsEntriesController; -use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; -use GuzzleHttp\Client; use Ratchet\ConnectionInterface; class FakeStatisticsLogger implements StatisticsLogger { - public function webSocketMessage(ConnectionInterface $connection) { - } public function apiMessage($appId) { - } public function connection(ConnectionInterface $connection) { - } public function disconnection(ConnectionInterface $connection) { - } protected function initializeStatistics($id) { - } public function save() { - } -} \ No newline at end of file +} diff --git a/src/Statistics/Logger/HttpStatisticsLogger.php b/src/Statistics/Logger/HttpStatisticsLogger.php index 7543d328ca..a23f7a9003 100644 --- a/src/Statistics/Logger/HttpStatisticsLogger.php +++ b/src/Statistics/Logger/HttpStatisticsLogger.php @@ -2,13 +2,13 @@ namespace BeyondCode\LaravelWebSockets\Statistics\Logger; +use Clue\React\Buzz\Browser; +use Ratchet\ConnectionInterface; +use function GuzzleHttp\Psr7\stream_for; use BeyondCode\LaravelWebSockets\Apps\App; -use BeyondCode\LaravelWebSockets\Statistics\Http\Controllers\WebSocketStatisticsEntriesController; use BeyondCode\LaravelWebSockets\Statistics\Statistic; use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; -use Clue\React\Buzz\Browser; -use function GuzzleHttp\Psr7\stream_for; -use Ratchet\ConnectionInterface; +use BeyondCode\LaravelWebSockets\Statistics\Http\Controllers\WebSocketStatisticsEntriesController; class HttpStatisticsLogger implements StatisticsLogger { @@ -58,7 +58,7 @@ public function disconnection(ConnectionInterface $connection) protected function findOrMakeStatisticForAppId($appId): Statistic { - if (!isset($this->statistics[$appId])) { + if (! isset($this->statistics[$appId])) { $this->statistics[$appId] = new Statistic($appId); } @@ -68,13 +68,12 @@ protected function findOrMakeStatisticForAppId($appId): Statistic public function save() { foreach ($this->statistics as $appId => $statistic) { - - if (!$statistic->isEnabled()) { + if (! $statistic->isEnabled()) { continue; } $postData = array_merge($statistic->toArray(), [ - 'secret' => App::findById($appId)->secret + 'secret' => App::findById($appId)->secret, ]); $this @@ -89,4 +88,4 @@ public function save() $statistic->reset($currentConnectionCount); } } -} \ No newline at end of file +} diff --git a/src/Statistics/Logger/StatisticsLogger.php b/src/Statistics/Logger/StatisticsLogger.php index 5b82884411..402a58a23c 100644 --- a/src/Statistics/Logger/StatisticsLogger.php +++ b/src/Statistics/Logger/StatisticsLogger.php @@ -15,4 +15,4 @@ public function connection(connectionInterface $connection); public function disconnection(connectionInterface $connection); public function save(); -} \ No newline at end of file +} diff --git a/src/Statistics/Models/WebSocketsStatisticsEntry.php b/src/Statistics/Models/WebSocketsStatisticsEntry.php index 637047e73d..24f0a7f87c 100644 --- a/src/Statistics/Models/WebSocketsStatisticsEntry.php +++ b/src/Statistics/Models/WebSocketsStatisticsEntry.php @@ -9,4 +9,4 @@ class WebSocketsStatisticsEntry extends Model protected $guarded = []; protected $table = 'websockets_statistics_entries'; -} \ No newline at end of file +} diff --git a/src/Statistics/Rules/AppId.php b/src/Statistics/Rules/AppId.php index da6d62f692..a6fc6d28a6 100644 --- a/src/Statistics/Rules/AppId.php +++ b/src/Statistics/Rules/AppId.php @@ -2,8 +2,8 @@ namespace BeyondCode\LaravelWebSockets\Statistics\Rules; -use BeyondCode\LaravelWebSockets\Apps\AppProvider; use Illuminate\Contracts\Validation\Rule; +use BeyondCode\LaravelWebSockets\Apps\AppProvider; class AppId implements Rule { @@ -17,4 +17,5 @@ public function passes($attribute, $value) public function message() { return 'There is no app registered with the given id. Make sure the websockets config file contains an app for this id or that your custom AppProvider returns an app for this id.'; -}} \ No newline at end of file + } +} diff --git a/src/Statistics/Statistic.php b/src/Statistics/Statistic.php index 8fda8cc186..93765fb384 100644 --- a/src/Statistics/Statistic.php +++ b/src/Statistics/Statistic.php @@ -72,4 +72,4 @@ public function toArray() 'api_message_count' => $this->apiMessageCount, ]; } -} \ No newline at end of file +} diff --git a/src/WebSockets/Channels/Channel.php b/src/WebSockets/Channels/Channel.php index b3094661c9..8735d781c6 100644 --- a/src/WebSockets/Channels/Channel.php +++ b/src/WebSockets/Channels/Channel.php @@ -2,11 +2,10 @@ namespace BeyondCode\LaravelWebSockets\WebSockets\Channels; +use stdClass; +use Ratchet\ConnectionInterface; use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger; use BeyondCode\LaravelWebSockets\WebSockets\Exceptions\InvalidSignature; -use Illuminate\Support\Collection; -use Ratchet\ConnectionInterface; -use stdClass; class Channel { @@ -53,7 +52,7 @@ public function subscribe(ConnectionInterface $connection, stdClass $payload) $connection->send(json_encode([ 'event' => 'pusher_internal:subscription_succeeded', - 'channel' => $this->channelName + 'channel' => $this->channelName, ])); } @@ -108,7 +107,7 @@ public function toArray(): array { return [ 'occupied' => count($this->subscribedConnections) > 0, - 'subscription_count' => count($this->subscribedConnections) + 'subscription_count' => count($this->subscribedConnections), ]; } -} \ No newline at end of file +} diff --git a/src/WebSockets/Channels/ChannelManager.php b/src/WebSockets/Channels/ChannelManager.php index 7dd4e53158..53391920c0 100644 --- a/src/WebSockets/Channels/ChannelManager.php +++ b/src/WebSockets/Channels/ChannelManager.php @@ -14,7 +14,7 @@ class ChannelManager public function findOrCreate(string $appId, string $channelName): Channel { - if (!isset($this->channels[$appId][$channelName])) { + if (! isset($this->channels[$appId][$channelName])) { $channelClass = $this->determineChannelClass($channelName); $this->channels[$appId][$channelName] = new $channelClass($channelName); @@ -56,16 +56,16 @@ public function getConnectionCount(string $appId): int public function removeFromAllChannels(ConnectionInterface $connection) { - if (!isset($connection->app)) { + if (! isset($connection->app)) { return; } - /** + /* * Remove the connection from all channels. */ collect(array_get($this->channels, $connection->app->id, []))->each->unsubscribe($connection); - /** + /* * Unset all channels that have no connections so we don't leak memory. */ collect(array_get($this->channels, $connection->app->id, [])) @@ -76,6 +76,6 @@ public function removeFromAllChannels(ConnectionInterface $connection) if (count(array_get($this->channels, $connection->app->id, [])) === 0) { unset($this->channels[$connection->app->id]); - }; + } } -} \ No newline at end of file +} diff --git a/src/WebSockets/Channels/PresenceChannel.php b/src/WebSockets/Channels/PresenceChannel.php index 1d5ee9994c..bb6ec45f3c 100644 --- a/src/WebSockets/Channels/PresenceChannel.php +++ b/src/WebSockets/Channels/PresenceChannel.php @@ -2,8 +2,8 @@ namespace BeyondCode\LaravelWebSockets\WebSockets\Channels; -use Ratchet\ConnectionInterface; use stdClass; +use Ratchet\ConnectionInterface; class PresenceChannel extends Channel { @@ -30,13 +30,13 @@ public function subscribe(ConnectionInterface $connection, stdClass $payload) $connection->send(json_encode([ 'event' => 'pusher_internal:subscription_succeeded', 'channel' => $this->channelName, - 'data' => json_encode($this->getChannelData()) + 'data' => json_encode($this->getChannelData()), ])); $this->broadcastToOthers($connection, [ 'event' => 'pusher_internal:member_added', 'channel' => $this->channelName, - 'data' => json_encode($channelData) + 'data' => json_encode($channelData), ]); } @@ -52,8 +52,8 @@ public function unsubscribe(ConnectionInterface $connection) 'event' => 'pusher_internal:member_removed', 'channel' => $this->channelName, 'data' => json_encode([ - 'user_id' => $this->users[$connection->socketId]->user_id - ]) + 'user_id' => $this->users[$connection->socketId]->user_id, + ]), ]); unset($this->users[$connection->socketId]); @@ -80,7 +80,7 @@ public function toArray(): array protected function getUserIds(): array { $userIds = array_map(function ($channelData) { - return (string)$channelData->user_id; + return (string) $channelData->user_id; }, $this->users); return array_values($userIds); @@ -96,4 +96,4 @@ protected function getHash(): array return $hash; } -} \ No newline at end of file +} diff --git a/src/WebSockets/Channels/PrivateChannel.php b/src/WebSockets/Channels/PrivateChannel.php index d758ed1441..34f3ac0fe7 100644 --- a/src/WebSockets/Channels/PrivateChannel.php +++ b/src/WebSockets/Channels/PrivateChannel.php @@ -2,8 +2,8 @@ namespace BeyondCode\LaravelWebSockets\WebSockets\Channels; -use Ratchet\ConnectionInterface; use stdClass; +use Ratchet\ConnectionInterface; class PrivateChannel extends Channel { @@ -13,4 +13,4 @@ public function subscribe(ConnectionInterface $connection, stdClass $payload) parent::subscribe($connection, $payload); } -} \ No newline at end of file +} diff --git a/src/WebSockets/Exceptions/InvalidConnection.php b/src/WebSockets/Exceptions/InvalidConnection.php index bbad9e3444..9a80077bc6 100644 --- a/src/WebSockets/Exceptions/InvalidConnection.php +++ b/src/WebSockets/Exceptions/InvalidConnection.php @@ -10,4 +10,4 @@ public function __construct() $this->code = 4009; } -} \ No newline at end of file +} diff --git a/src/WebSockets/Exceptions/InvalidSignature.php b/src/WebSockets/Exceptions/InvalidSignature.php index 2341bb5349..71f87a17f4 100644 --- a/src/WebSockets/Exceptions/InvalidSignature.php +++ b/src/WebSockets/Exceptions/InvalidSignature.php @@ -10,4 +10,4 @@ public function __construct() $this->code = 4009; } -} \ No newline at end of file +} diff --git a/src/WebSockets/Exceptions/UnknownAppKey.php b/src/WebSockets/Exceptions/UnknownAppKey.php index 7f5285e995..6fe5c83765 100644 --- a/src/WebSockets/Exceptions/UnknownAppKey.php +++ b/src/WebSockets/Exceptions/UnknownAppKey.php @@ -10,4 +10,4 @@ public function __construct(string $appKey) $this->code = 4001; } -} \ No newline at end of file +} diff --git a/src/WebSockets/Exceptions/WebSocketException.php b/src/WebSockets/Exceptions/WebSocketException.php index 3832e12204..5c83cca21e 100644 --- a/src/WebSockets/Exceptions/WebSocketException.php +++ b/src/WebSockets/Exceptions/WebSocketException.php @@ -12,8 +12,8 @@ public function getPayload() 'event' => 'pusher:error', 'data' => [ 'message' => $this->getMessage(), - 'code' => $this->getCode() - ] + 'code' => $this->getCode(), + ], ]; } -} \ No newline at end of file +} diff --git a/src/WebSockets/Messages/PusherChannelProtocolMessage.php b/src/WebSockets/Messages/PusherChannelProtocolMessage.php index 47835e74ee..b2f3cb982f 100644 --- a/src/WebSockets/Messages/PusherChannelProtocolMessage.php +++ b/src/WebSockets/Messages/PusherChannelProtocolMessage.php @@ -2,9 +2,9 @@ namespace BeyondCode\LaravelWebSockets\WebSockets\Messages; -use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; -use Ratchet\ConnectionInterface; use stdClass; +use Ratchet\ConnectionInterface; +use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; class PusherChannelProtocolMessage implements PusherMessage { diff --git a/src/WebSockets/Messages/PusherClientMessage.php b/src/WebSockets/Messages/PusherClientMessage.php index 656737dab0..8a1ac7d9ee 100644 --- a/src/WebSockets/Messages/PusherClientMessage.php +++ b/src/WebSockets/Messages/PusherClientMessage.php @@ -2,11 +2,10 @@ namespace BeyondCode\LaravelWebSockets\WebSockets\Messages; +use stdClass; +use Ratchet\ConnectionInterface; use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger; -use BeyondCode\LaravelWebSockets\Events\ClientMessageSent; use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; -use Ratchet\ConnectionInterface; -use stdClass; class PusherClientMessage implements PusherMessage { @@ -30,7 +29,7 @@ public function __construct(stdClass $payload, ConnectionInterface $connection, public function respond() { - if (!starts_with($this->payload->event, 'client-')) { + if (! starts_with($this->payload->event, 'client-')) { return; } @@ -44,4 +43,4 @@ public function respond() optional($channel)->broadcastToOthers($this->connection, $this->payload); } -} \ No newline at end of file +} diff --git a/src/WebSockets/Messages/PusherMessage.php b/src/WebSockets/Messages/PusherMessage.php index 0d0d08618a..bed95507b4 100644 --- a/src/WebSockets/Messages/PusherMessage.php +++ b/src/WebSockets/Messages/PusherMessage.php @@ -1,7 +1,8 @@ httpRequest)->get('appKey'); - if (!$app = App::findByKey($appKey)) { + if (! $app = App::findByKey($appKey)) { throw new UnknownAppKey($appKey); } @@ -75,7 +75,7 @@ protected function verifyAppKey(ConnectionInterface $connection) protected function generateSocketId(ConnectionInterface $connection) { - $socketId = sprintf("%d.%d", random_int(1, 1000000000), random_int(1, 1000000000)); + $socketId = sprintf('%d.%d', random_int(1, 1000000000), random_int(1, 1000000000)); $connection->socketId = $socketId; @@ -89,7 +89,7 @@ protected function establishConnection(ConnectionInterface $connection) 'data' => json_encode([ 'socket_id' => $connection->socketId, 'activity_timeout' => 30, - ]) + ]), ])); DashboardLogger::connection($connection); @@ -98,4 +98,4 @@ protected function establishConnection(ConnectionInterface $connection) return $this; } -} \ No newline at end of file +} diff --git a/src/WebSocketsServiceProvider.php b/src/WebSocketsServiceProvider.php index bd895b74a3..3c821260a4 100644 --- a/src/WebSocketsServiceProvider.php +++ b/src/WebSocketsServiceProvider.php @@ -2,33 +2,31 @@ namespace BeyondCode\LaravelWebSockets; -use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\AuthenticateDashboard; -use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\DashboardApiController; +use Illuminate\Support\Facades\Gate; +use Illuminate\Support\Facades\Route; +use Illuminate\Support\ServiceProvider; +use BeyondCode\LaravelWebSockets\Server\Router; +use BeyondCode\LaravelWebSockets\Apps\AppProvider; +use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\SendMessage; use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\ShowDashboard; +use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\AuthenticateDashboard; +use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\DashboardApiController; use BeyondCode\LaravelWebSockets\Dashboard\Http\Middleware\Authorize as AuthorizeDashboard; use BeyondCode\LaravelWebSockets\Statistics\Http\Middleware\Authorize as AuthorizeStatistics; -use BeyondCode\LaravelWebSockets\Server\Router; use BeyondCode\LaravelWebSockets\Statistics\Http\Controllers\WebSocketStatisticsEntriesController; -use BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger; -use Illuminate\Support\Facades\Gate; -use Illuminate\Support\Facades\Route; -use BeyondCode\LaravelWebSockets\Apps\AppProvider; -use Illuminate\Support\ServiceProvider; -use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; -use Illuminate\Support\Str; class WebSocketsServiceProvider extends ServiceProvider { public function boot() { $this->publishes([ - __DIR__ . '/../config/websockets.php' => base_path('config/websockets.php'), + __DIR__.'/../config/websockets.php' => base_path('config/websockets.php'), ], 'config'); - if (!class_exists('CreateWebSocketsStatisticsEntries')) { + if (! class_exists('CreateWebSocketsStatisticsEntries')) { $this->publishes([ - __DIR__ . '/../database/migrations/create_websockets_statistics_entries_table.php.stub' => database_path('migrations/' . date('Y_m_d_His', time()) . '_create_websockets_statistics_entries_table.php'), + __DIR__.'/../database/migrations/create_websockets_statistics_entries_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_websockets_statistics_entries_table.php'), ], 'migrations'); } @@ -36,7 +34,7 @@ public function boot() ->registerRoutes() ->registerDashboardGate(); - $this->loadViewsFrom(__DIR__ . '/../resources/views/', 'websockets'); + $this->loadViewsFrom(__DIR__.'/../resources/views/', 'websockets'); $this->commands([ Console\StartWebSocketServer::class, @@ -46,7 +44,7 @@ public function boot() public function register() { - $this->mergeConfigFrom(__DIR__ . '/../config/websockets.php', 'websockets'); + $this->mergeConfigFrom(__DIR__.'/../config/websockets.php', 'websockets'); $this->app->singleton('websockets.router', function () { return new Router(); @@ -63,15 +61,15 @@ public function register() protected function registerRoutes() { - Route::prefix(config('websockets.path'))->group(function() { - Route::middleware(AuthorizeDashboard::class)->group(function() { + Route::prefix(config('websockets.path'))->group(function () { + Route::middleware(AuthorizeDashboard::class)->group(function () { Route::get('/', ShowDashboard::class); Route::get('/api/{appId}/statistics', [DashboardApiController::class, 'getStatistics']); Route::post('auth', AuthenticateDashboard::class); Route::post('event', SendMessage::class); }); - Route::middleware(AuthorizeStatistics::class)->group(function() { + Route::middleware(AuthorizeStatistics::class)->group(function () { Route::post('statistics', [WebSocketStatisticsEntriesController::class, 'store']); }); }); diff --git a/tests/Channels/ChannelTest.php b/tests/Channels/ChannelTest.php index 2cc7a7b623..f51259c04f 100644 --- a/tests/Channels/ChannelTest.php +++ b/tests/Channels/ChannelTest.php @@ -2,8 +2,8 @@ namespace BeyondCode\LaravelWebsockets\Tests\Channels; -use BeyondCode\LaravelWebSockets\Tests\Mocks\Message; use BeyondCode\LaravelWebSockets\Tests\TestCase; +use BeyondCode\LaravelWebSockets\Tests\Mocks\Message; class ChannelTest extends TestCase { @@ -15,7 +15,7 @@ public function clients_can_subscribe_to_channels() $message = new Message(json_encode([ 'event' => 'pusher:subscribe', 'data' => [ - 'channel' => 'basic-channel' + 'channel' => 'basic-channel', ], ])); @@ -24,7 +24,7 @@ public function clients_can_subscribe_to_channels() $this->pusherServer->onMessage($connection, $message); $connection->assertSentEvent('pusher_internal:subscription_succeeded', [ - 'channel' => 'basic-channel' + 'channel' => 'basic-channel', ]); } @@ -40,7 +40,7 @@ public function clients_can_unsubscribe_from_channels() $message = new Message(json_encode([ 'event' => 'pusher:unsubscribe', 'data' => [ - 'channel' => 'test-channel' + 'channel' => 'test-channel', ], ])); @@ -108,7 +108,7 @@ public function channels_can_broadcast_messages_to_all_connections() $channel->broadcast([ 'event' => 'broadcasted-event', - 'channel' => 'test-channel' + 'channel' => 'test-channel', ]); $connection1->assertSentEvent('broadcasted-event'); @@ -125,7 +125,7 @@ public function channels_can_broadcast_messages_to_all_connections_except_the_gi $channel->broadcastToOthers($connection1, [ 'event' => 'broadcasted-event', - 'channel' => 'test-channel' + 'channel' => 'test-channel', ]); $connection1->assertNotSentEvent('broadcasted-event'); @@ -145,4 +145,4 @@ public function it_responds_correctly_to_the_ping_message() $connection->assertSentEvent('pusher:pong'); } -} \ No newline at end of file +} diff --git a/tests/Channels/PresenceChannelTest.php b/tests/Channels/PresenceChannelTest.php index def322bd31..0d2d0939aa 100644 --- a/tests/Channels/PresenceChannelTest.php +++ b/tests/Channels/PresenceChannelTest.php @@ -2,8 +2,8 @@ namespace BeyondCode\LaravelWebsockets\Tests\Channels; -use BeyondCode\LaravelWebSockets\Tests\Mocks\Message; use BeyondCode\LaravelWebSockets\Tests\TestCase; +use BeyondCode\LaravelWebSockets\Tests\Mocks\Message; use BeyondCode\LaravelWebSockets\WebSockets\Exceptions\InvalidSignature; class PresenceChannelTest extends TestCase @@ -19,7 +19,7 @@ public function clients_need_valid_auth_signatures_to_join_presence_channels() 'event' => 'pusher:subscribe', 'data' => [ 'auth' => 'invalid', - 'channel' => 'presence-channel' + 'channel' => 'presence-channel', ], ])); @@ -38,8 +38,8 @@ public function clients_with_valid_auth_signatures_can_join_presence_channels() $channelData = [ 'user_id' => 1, 'user_info' => [ - 'name' => 'Marcel' - ] + 'name' => 'Marcel', + ], ]; $signature = "{$connection->socketId}:presence-channel:".json_encode($channelData); @@ -49,7 +49,7 @@ public function clients_with_valid_auth_signatures_can_join_presence_channels() 'data' => [ 'auth' => $connection->app->key.':'.hash_hmac('sha256', $signature, $connection->app->secret), 'channel' => 'presence-channel', - 'channel_data' => json_encode($channelData) + 'channel_data' => json_encode($channelData), ], ])); @@ -59,4 +59,4 @@ public function clients_with_valid_auth_signatures_can_join_presence_channels() 'channel' => 'presence-channel', ]); } -} \ No newline at end of file +} diff --git a/tests/Channels/PrivateChannelTest.php b/tests/Channels/PrivateChannelTest.php index e0ee0d9884..c933d9807f 100644 --- a/tests/Channels/PrivateChannelTest.php +++ b/tests/Channels/PrivateChannelTest.php @@ -2,8 +2,8 @@ namespace BeyondCode\LaravelWebsockets\Tests\Channels; -use BeyondCode\LaravelWebSockets\Tests\Mocks\Message; use BeyondCode\LaravelWebSockets\Tests\TestCase; +use BeyondCode\LaravelWebSockets\Tests\Mocks\Message; use BeyondCode\LaravelWebSockets\WebSockets\Exceptions\InvalidSignature; class PrivateChannelTest extends TestCase @@ -19,7 +19,7 @@ public function clients_need_valid_auth_signatures_to_join_private_channels() 'event' => 'pusher:subscribe', 'data' => [ 'auth' => 'invalid', - 'channel' => 'private-channel' + 'channel' => 'private-channel', ], ])); @@ -43,14 +43,14 @@ public function clients_with_valid_auth_signatures_can_join_private_channels() 'event' => 'pusher:subscribe', 'data' => [ 'auth' => "{$connection->app->key}:{$hashedAppSecret}", - 'channel' => 'private-channel' + 'channel' => 'private-channel', ], ])); $this->pusherServer->onMessage($connection, $message); $connection->assertSentEvent('pusher_internal:subscription_succeeded', [ - 'channel' => 'private-channel' + 'channel' => 'private-channel', ]); } -} \ No newline at end of file +} diff --git a/tests/ClientProviders/AppTest.php b/tests/ClientProviders/AppTest.php index 12dd4c31b1..71393d7dae 100644 --- a/tests/ClientProviders/AppTest.php +++ b/tests/ClientProviders/AppTest.php @@ -3,8 +3,8 @@ namespace BeyondCode\LaravelWebSockets\Tests\ClientProviders; use BeyondCode\LaravelWebSockets\Apps\App; -use BeyondCode\LaravelWebSockets\Exceptions\InvalidApp; use BeyondCode\LaravelWebSockets\Tests\TestCase; +use BeyondCode\LaravelWebSockets\Exceptions\InvalidApp; class AppTest extends TestCase { @@ -31,4 +31,4 @@ public function it_will_not_accept_an_empty_appSecret() new App(1, 'appKey', '', 'new'); } -} \ No newline at end of file +} diff --git a/tests/ClientProviders/ConfigAppProviderTest.php b/tests/ClientProviders/ConfigAppProviderTest.php index 421a73bd71..f8909dbf20 100644 --- a/tests/ClientProviders/ConfigAppProviderTest.php +++ b/tests/ClientProviders/ConfigAppProviderTest.php @@ -2,8 +2,8 @@ namespace BeyondCode\LaravelWebSockets\Tests\ClientProviders; -use BeyondCode\LaravelWebSockets\Apps\ConfigAppProvider; use BeyondCode\LaravelWebSockets\Tests\TestCase; +use BeyondCode\LaravelWebSockets\Apps\ConfigAppProvider; class ConfigAppProviderTest extends TestCase { @@ -24,7 +24,7 @@ public function it_can_get_apps_from_the_config_file() $this->assertCount(1, $apps); - /** @var $app */ + /** @var $app */ $app = $apps[0]; $this->assertEquals('Test App', $app->name); @@ -85,4 +85,4 @@ public function it_can_find_app_by_secret() $this->assertFalse($app->clientMessagesEnabled); $this->assertTrue($app->statisticsEnabled); } -} \ No newline at end of file +} diff --git a/tests/Commands/CleanStatisticsTest.php b/tests/Commands/CleanStatisticsTest.php index 5605ce4686..0c7fd2815e 100644 --- a/tests/Commands/CleanStatisticsTest.php +++ b/tests/Commands/CleanStatisticsTest.php @@ -3,14 +3,13 @@ namespace BeyondCode\LaravelWebSockets\Tests\Commands; use Artisan; -use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry; use Carbon\Carbon; -use BeyondCode\LaravelWebSockets\Tests\TestCase; use Illuminate\Support\Collection; +use BeyondCode\LaravelWebSockets\Tests\TestCase; +use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry; class CleanStatisticsTest extends TestCase { - public function setUp() { parent::setUp(); @@ -20,7 +19,6 @@ public function setUp() $this->app['config']->set('websockets.statistics.delete_statistics_older_than_days', 31); } - /** @test */ public function it_can_clean_the_statistics() { @@ -44,4 +42,4 @@ public function it_can_clean_the_statistics() $this->assertCount(0, WebSocketsStatisticsEntry::where('created_at', '<', $cutOffDate)->get()); } -} \ No newline at end of file +} diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index caad118ebe..62cf1543dc 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -3,12 +3,11 @@ namespace BeyondCode\LaravelWebSockets\Tests; use BeyondCode\LaravelWebSockets\Apps\App; -use BeyondCode\LaravelWebSockets\WebSockets\Exceptions\UnknownAppKey; use BeyondCode\LaravelWebSockets\Tests\Mocks\Message; +use BeyondCode\LaravelWebSockets\WebSockets\Exceptions\UnknownAppKey; class ConnectionTest extends TestCase { - /** @test */ public function unknown_app_keys_can_not_connect() { @@ -54,4 +53,4 @@ public function ping_returns_pong() $connection->assertSentEvent('pusher:pong'); } -} \ No newline at end of file +} diff --git a/tests/HttpApi/FetchChannelTest.php b/tests/HttpApi/FetchChannelTest.php index 34643bd36c..cabc459204 100644 --- a/tests/HttpApi/FetchChannelTest.php +++ b/tests/HttpApi/FetchChannelTest.php @@ -2,16 +2,15 @@ namespace BeyondCode\LaravelWebSockets\Tests\HttpApi; -use BeyondCode\LaravelWebSockets\HttpApi\Controllers\FetchChannelController; -use BeyondCode\LaravelWebSockets\Tests\Mocks\Connection; -use BeyondCode\LaravelWebSockets\Tests\TestCase; use GuzzleHttp\Psr7\Request; use Illuminate\Http\JsonResponse; +use BeyondCode\LaravelWebSockets\Tests\TestCase; +use BeyondCode\LaravelWebSockets\Tests\Mocks\Connection; use Symfony\Component\HttpKernel\Exception\HttpException; +use BeyondCode\LaravelWebSockets\HttpApi\Controllers\FetchChannelController; class FetchChannelTest extends TestCase { - /** @test */ public function invalid_signatures_can_not_access_the_api() { @@ -24,12 +23,12 @@ public function invalid_signatures_can_not_access_the_api() $auth_timestamp = time(); $auth_version = '1.0'; - $queryParameters = http_build_query(compact('auth_key','auth_timestamp','auth_version')); + $queryParameters = http_build_query(compact('auth_key', 'auth_timestamp', 'auth_version')); $signature = - "GET\n/apps/1234/channels\n" . - "auth_key={$auth_key}" . - "&auth_timestamp={$auth_timestamp}" . + "GET\n/apps/1234/channels\n". + "auth_key={$auth_key}". + "&auth_timestamp={$auth_timestamp}". "&auth_version={$auth_version}"; $auth_signature = hash_hmac('sha256', $signature, 'InvalidSecret'); @@ -53,12 +52,12 @@ public function it_returns_the_channel_information() $auth_timestamp = time(); $auth_version = '1.0'; - $queryParameters = http_build_query(compact('auth_key','auth_timestamp','auth_version')); + $queryParameters = http_build_query(compact('auth_key', 'auth_timestamp', 'auth_version')); $signature = - "GET\n/apps/1234/channel/my-channel\n" . - "auth_key={$auth_key}" . - "&auth_timestamp={$auth_timestamp}" . + "GET\n/apps/1234/channel/my-channel\n". + "auth_key={$auth_key}". + "&auth_timestamp={$auth_timestamp}". "&auth_version={$auth_version}"; $auth_signature = hash_hmac('sha256', $signature, 'TestSecret'); @@ -74,7 +73,7 @@ public function it_returns_the_channel_information() $this->assertSame([ 'occupied' => true, - 'subscription_count' => 2 + 'subscription_count' => 2, ], json_decode($response->getContent(), true)); } @@ -92,12 +91,12 @@ public function it_returns_404_for_invalid_channels() $auth_timestamp = time(); $auth_version = '1.0'; - $queryParameters = http_build_query(compact('auth_key','auth_timestamp','auth_version')); + $queryParameters = http_build_query(compact('auth_key', 'auth_timestamp', 'auth_version')); $signature = - "GET\n/apps/1234/channel/my-channel\n" . - "auth_key={$auth_key}" . - "&auth_timestamp={$auth_timestamp}" . + "GET\n/apps/1234/channel/my-channel\n". + "auth_key={$auth_key}". + "&auth_timestamp={$auth_timestamp}". "&auth_version={$auth_version}"; $auth_signature = hash_hmac('sha256', $signature, 'TestSecret'); @@ -113,8 +112,7 @@ public function it_returns_404_for_invalid_channels() $this->assertSame([ 'occupied' => true, - 'subscription_count' => 2 + 'subscription_count' => 2, ], json_decode($response->getContent(), true)); } - -} \ No newline at end of file +} diff --git a/tests/HttpApi/FetchChannelsTest.php b/tests/HttpApi/FetchChannelsTest.php index 78f8cc6ab7..088dabfe5b 100644 --- a/tests/HttpApi/FetchChannelsTest.php +++ b/tests/HttpApi/FetchChannelsTest.php @@ -2,17 +2,15 @@ namespace BeyondCode\LaravelWebSockets\Tests\HttpApi; -use BeyondCode\LaravelWebSockets\HttpApi\Controllers\FetchChannelsController; -use BeyondCode\LaravelWebSockets\Tests\Mocks\Connection; -use BeyondCode\LaravelWebSockets\Tests\Mocks\Message; -use BeyondCode\LaravelWebSockets\Tests\TestCase; use GuzzleHttp\Psr7\Request; use Illuminate\Http\JsonResponse; +use BeyondCode\LaravelWebSockets\Tests\TestCase; +use BeyondCode\LaravelWebSockets\Tests\Mocks\Connection; use Symfony\Component\HttpKernel\Exception\HttpException; +use BeyondCode\LaravelWebSockets\HttpApi\Controllers\FetchChannelsController; class FetchChannelsTest extends TestCase { - /** @test */ public function invalid_signatures_can_not_access_the_api() { @@ -25,12 +23,12 @@ public function invalid_signatures_can_not_access_the_api() $auth_timestamp = time(); $auth_version = '1.0'; - $queryParameters = http_build_query(compact('auth_key','auth_timestamp','auth_version')); + $queryParameters = http_build_query(compact('auth_key', 'auth_timestamp', 'auth_version')); $signature = - "GET\n/apps/1234/channels\n" . - "auth_key={$auth_key}" . - "&auth_timestamp={$auth_timestamp}" . + "GET\n/apps/1234/channels\n". + "auth_key={$auth_key}". + "&auth_timestamp={$auth_timestamp}". "&auth_version={$auth_version}"; $auth_signature = hash_hmac('sha256', $signature, 'InvalidSecret'); @@ -55,12 +53,12 @@ public function it_returns_the_channel_information() $auth_timestamp = time(); $auth_version = '1.0'; - $queryParameters = http_build_query(compact('auth_key','auth_timestamp','auth_version')); + $queryParameters = http_build_query(compact('auth_key', 'auth_timestamp', 'auth_version')); $signature = - "GET\n/apps/1234/channels\n" . - "auth_key={$auth_key}" . - "&auth_timestamp={$auth_timestamp}" . + "GET\n/apps/1234/channels\n". + "auth_key={$auth_key}". + "&auth_timestamp={$auth_timestamp}". "&auth_version={$auth_version}"; $auth_signature = hash_hmac('sha256', $signature, 'TestSecret'); @@ -77,10 +75,9 @@ public function it_returns_the_channel_information() $this->assertSame([ 'channels' => [ 'presence-channel' => [ - 'user_count' => 3 - ] - ] + 'user_count' => 3, + ], + ], ], json_decode($response->getContent(), true)); } - -} \ No newline at end of file +} diff --git a/tests/HttpApi/FetchUsersTest.php b/tests/HttpApi/FetchUsersTest.php index 0881e37082..543aeb0b5c 100644 --- a/tests/HttpApi/FetchUsersTest.php +++ b/tests/HttpApi/FetchUsersTest.php @@ -2,17 +2,14 @@ namespace BeyondCode\LaravelWebSockets\Tests\HttpApi; -use BeyondCode\LaravelWebSockets\HttpApi\Controllers\FetchChannelController; -use BeyondCode\LaravelWebSockets\HttpApi\Controllers\FetchUsersController; -use BeyondCode\LaravelWebSockets\Tests\Mocks\Connection; -use BeyondCode\LaravelWebSockets\Tests\TestCase; use GuzzleHttp\Psr7\Request; -use Illuminate\Http\JsonResponse; +use BeyondCode\LaravelWebSockets\Tests\TestCase; +use BeyondCode\LaravelWebSockets\Tests\Mocks\Connection; use Symfony\Component\HttpKernel\Exception\HttpException; +use BeyondCode\LaravelWebSockets\HttpApi\Controllers\FetchUsersController; class FetchUsersTest extends TestCase { - /** @test */ public function invalid_signatures_can_not_access_the_api() { @@ -25,12 +22,12 @@ public function invalid_signatures_can_not_access_the_api() $auth_timestamp = time(); $auth_version = '1.0'; - $queryParameters = http_build_query(compact('auth_key','auth_timestamp','auth_version')); + $queryParameters = http_build_query(compact('auth_key', 'auth_timestamp', 'auth_version')); $signature = - "GET\n/apps/1234/channels\n" . - "auth_key={$auth_key}" . - "&auth_timestamp={$auth_timestamp}" . + "GET\n/apps/1234/channels\n". + "auth_key={$auth_key}". + "&auth_timestamp={$auth_timestamp}". "&auth_version={$auth_version}"; $auth_signature = hash_hmac('sha256', $signature, 'InvalidSecret'); @@ -56,12 +53,12 @@ public function it_only_returns_data_for_presence_channels() $auth_timestamp = time(); $auth_version = '1.0'; - $queryParameters = http_build_query(compact('auth_key','auth_timestamp','auth_version')); + $queryParameters = http_build_query(compact('auth_key', 'auth_timestamp', 'auth_version')); $signature = - "GET\n/apps/1234/channel/my-channel/users\n" . - "auth_key={$auth_key}" . - "&auth_timestamp={$auth_timestamp}" . + "GET\n/apps/1234/channel/my-channel/users\n". + "auth_key={$auth_key}". + "&auth_timestamp={$auth_timestamp}". "&auth_version={$auth_version}"; $auth_signature = hash_hmac('sha256', $signature, 'TestSecret'); @@ -87,12 +84,12 @@ public function it_returns_404_for_invalid_channels() $auth_timestamp = time(); $auth_version = '1.0'; - $queryParameters = http_build_query(compact('auth_key','auth_timestamp','auth_version')); + $queryParameters = http_build_query(compact('auth_key', 'auth_timestamp', 'auth_version')); $signature = - "GET\n/apps/1234/channel/my-channel/users\n" . - "auth_key={$auth_key}" . - "&auth_timestamp={$auth_timestamp}" . + "GET\n/apps/1234/channel/my-channel/users\n". + "auth_key={$auth_key}". + "&auth_timestamp={$auth_timestamp}". "&auth_version={$auth_version}"; $auth_signature = hash_hmac('sha256', $signature, 'TestSecret'); @@ -115,12 +112,12 @@ public function it_returns_connected_user_information() $auth_timestamp = time(); $auth_version = '1.0'; - $queryParameters = http_build_query(compact('auth_key','auth_timestamp','auth_version')); + $queryParameters = http_build_query(compact('auth_key', 'auth_timestamp', 'auth_version')); $signature = - "GET\n/apps/1234/channel/my-channel/users\n" . - "auth_key={$auth_key}" . - "&auth_timestamp={$auth_timestamp}" . + "GET\n/apps/1234/channel/my-channel/users\n". + "auth_key={$auth_key}". + "&auth_timestamp={$auth_timestamp}". "&auth_version={$auth_version}"; $auth_signature = hash_hmac('sha256', $signature, 'TestSecret'); @@ -137,9 +134,9 @@ public function it_returns_connected_user_information() $this->assertSame([ 'users' => [ [ - 'id' => 1 - ] - ] + 'id' => 1, + ], + ], ], json_decode($response->getContent(), true)); } -} \ No newline at end of file +} diff --git a/tests/Messages/PusherClientMessageTest.php b/tests/Messages/PusherClientMessageTest.php index d16d64043b..855ceeeacc 100644 --- a/tests/Messages/PusherClientMessageTest.php +++ b/tests/Messages/PusherClientMessageTest.php @@ -16,7 +16,7 @@ public function client_messages_do_not_work_when_disabled() 'event' => 'client-test', 'channel' => 'test-channel', 'data' => [ - 'client-event' => 'test' + 'client-event' => 'test', ], ])); @@ -46,7 +46,7 @@ public function client_messages_get_broadcasted_when_enabled() 'event' => 'client-test', 'channel' => 'test-channel', 'data' => [ - 'client-event' => 'test' + 'client-event' => 'test', ], ])); @@ -56,8 +56,8 @@ public function client_messages_get_broadcasted_when_enabled() $connection2->assertSentEvent('client-test', [ 'data' => [ - 'client-event' => 'test' - ] + 'client-event' => 'test', + ], ]); } -} \ No newline at end of file +} diff --git a/tests/Mocks/Connection.php b/tests/Mocks/Connection.php index 1ecfbca243..a0c37d06ca 100644 --- a/tests/Mocks/Connection.php +++ b/tests/Mocks/Connection.php @@ -54,4 +54,4 @@ public function assertClosed() { PHPUnit::assertTrue($this->closed); } -} \ No newline at end of file +} diff --git a/tests/Mocks/Message.php b/tests/Mocks/Message.php index 8b68e6aed7..3b0706c1ad 100644 --- a/tests/Mocks/Message.php +++ b/tests/Mocks/Message.php @@ -2,7 +2,6 @@ namespace BeyondCode\LaravelWebSockets\Tests\Mocks; - class Message extends \Ratchet\RFC6455\Messaging\Message { protected $payload; @@ -16,4 +15,4 @@ public function getPayload() { return $this->payload; } -} \ No newline at end of file +} diff --git a/tests/Statistics/Controllers/WebSocketsStatisticsControllerTest.php b/tests/Statistics/Controllers/WebSocketsStatisticsControllerTest.php index a38f6a8cc6..482f50b894 100644 --- a/tests/Statistics/Controllers/WebSocketsStatisticsControllerTest.php +++ b/tests/Statistics/Controllers/WebSocketsStatisticsControllerTest.php @@ -2,9 +2,9 @@ namespace BeyondCode\LaravelWebSockets\Tests\Statistics\Controllers; -use BeyondCode\LaravelWebSockets\Statistics\Http\Controllers\WebSocketStatisticsEntriesController; -use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry; use BeyondCode\LaravelWebSockets\Tests\TestCase; +use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry; +use BeyondCode\LaravelWebSockets\Statistics\Http\Controllers\WebSocketStatisticsEntriesController; class WebSocketsStatisticsControllerTest extends TestCase { @@ -34,4 +34,4 @@ protected function payload(): array 'api_message_count' => 3, ]; } -} \ No newline at end of file +} diff --git a/tests/Statistics/Rules/AppIdTest.php b/tests/Statistics/Rules/AppIdTest.php index 56d344c385..3176d0927d 100644 --- a/tests/Statistics/Rules/AppIdTest.php +++ b/tests/Statistics/Rules/AppIdTest.php @@ -2,8 +2,8 @@ namespace BeyondCode\LaravelWebSockets\Tests\Statistics\Rules; -use BeyondCode\LaravelWebSockets\Statistics\Rules\AppId; use BeyondCode\LaravelWebSockets\Tests\TestCase; +use BeyondCode\LaravelWebSockets\Statistics\Rules\AppId; class AppIdTest extends TestCase { @@ -15,4 +15,4 @@ public function it_can_validate_an_app_id() $this->assertTrue($rule->passes('app_id', config('websockets.apps.0.id'))); $this->assertFalse($rule->passes('app_id', 'invalid-app-id')); } -} \ No newline at end of file +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 1a51144cd8..d863cbab51 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,16 +2,14 @@ namespace BeyondCode\LaravelWebSockets\Tests; -use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger; -use BeyondCode\LaravelWebSockets\Tests\Mocks\Message; -use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; -use BeyondCode\LaravelWebSockets\WebSockets\WebSocketHandler; -use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; +use Ratchet\ConnectionInterface; +use BeyondCode\LaravelWebSockets\Tests\Mocks\Message; use BeyondCode\LaravelWebSockets\Tests\Mocks\Connection; +use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger; use BeyondCode\LaravelWebSockets\WebSocketsServiceProvider; -use Illuminate\Support\Facades\Route; -use Ratchet\ConnectionInterface; +use BeyondCode\LaravelWebSockets\WebSockets\WebSocketHandler; +use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; abstract class TestCase extends \Orchestra\Testbench\TestCase { @@ -53,8 +51,6 @@ protected function getEnvironmentSetUp($app) include_once __DIR__.'/../database/migrations/create_websockets_statistics_entries_table.php.stub'; (new \CreateWebSocketsStatisticsEntriesTable())->up(); - - } protected function getWebSocketConnection(string $url = '/?appKey=TestKey'): Connection @@ -78,7 +74,7 @@ protected function getConnectedWebSocketConnection(array $channelsToJoin = [], s $message = new Message(json_encode([ 'event' => 'pusher:subscribe', 'data' => [ - 'channel' => $channel + 'channel' => $channel, ], ])); @@ -97,8 +93,8 @@ protected function joinPresenceChannel($channel): Connection $channelData = [ 'user_id' => 1, 'user_info' => [ - 'name' => 'Marcel' - ] + 'name' => 'Marcel', + ], ]; $signature = "{$connection->socketId}:{$channel}:".json_encode($channelData); @@ -108,7 +104,7 @@ protected function joinPresenceChannel($channel): Connection 'data' => [ 'auth' => $connection->app->key.':'.hash_hmac('sha256', $signature, $connection->app->secret), 'channel' => $channel, - 'channel_data' => json_encode($channelData) + 'channel_data' => json_encode($channelData), ], ])); @@ -126,4 +122,4 @@ protected function markTestAsPassed() { $this->assertTrue(true); } -} \ No newline at end of file +}