diff --git a/config/websockets.php b/config/websockets.php index 508a0b0..40aaa24 100644 --- a/config/websockets.php +++ b/config/websockets.php @@ -64,7 +64,7 @@ return [ * 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 @@ return [ /* * Passphrase for your local_cert file. */ - 'passphrase' => null + 'passphrase' => null, ], ]; diff --git a/src/Apps/App.php b/src/Apps/App.php index 9d14cb8..dcb1784 100644 --- a/src/Apps/App.php +++ b/src/Apps/App.php @@ -29,12 +29,12 @@ class App 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 d022d95..02de343 100644 --- a/src/Apps/AppProvider.php +++ b/src/Apps/AppProvider.php @@ -12,4 +12,4 @@ interface AppProvider 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 8e5297d..a0ded0f 100644 --- a/src/Apps/ConfigAppProvider.php +++ b/src/Apps/ConfigAppProvider.php @@ -53,7 +53,7 @@ class ConfigAppProvider implements AppProvider protected function instanciate(?array $appAttributes): ?App { - if (!$appAttributes) { + if (! $appAttributes) { return null; } @@ -71,7 +71,6 @@ class ConfigAppProvider implements AppProvider ->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 23e3d1e..aba815f 100644 --- a/src/Console/CleanStatistics.php +++ b/src/Console/CleanStatistics.php @@ -8,7 +8,6 @@ use Illuminate\Database\Eloquent\Builder; class CleanStatistics extends Command { - protected $signature = 'websockets:clean {appId? : (optional) The app id that will be cleaned.}'; @@ -36,4 +35,4 @@ class CleanStatistics extends Command $this->comment('All done!'); } -} \ No newline at end of file +} diff --git a/src/Console/StartWebSocketServer.php b/src/Console/StartWebSocketServer.php index 65933f1..e7ae29a 100644 --- a/src/Console/StartWebSocketServer.php +++ b/src/Console/StartWebSocketServer.php @@ -2,22 +2,20 @@ namespace BeyondCode\LaravelWebSockets\Console; -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\Logger\WebsocketsLogger; -use BeyondCode\LaravelWebSockets\Statistics\DnsResolver; -use BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger; -use BeyondCode\LaravelWebSockets\Statistics\Logger\StatisticsLogger as StatisticsLoggerInterface; - -use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; +use React\Socket\Connector; use Clue\React\Buzz\Browser; use Illuminate\Console\Command; -use BeyondCode\LaravelWebSockets\Server\WebSocketServerFactory; - use React\EventLoop\Factory as LoopFactory; -use React\Socket\Connector; +use BeyondCode\LaravelWebSockets\Statistics\DnsResolver; +use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger; +use BeyondCode\LaravelWebSockets\Facades\WebSocketsRouter; +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\WebSockets\Channels\ChannelManager; +use BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger; +use BeyondCode\LaravelWebSockets\Statistics\Logger\StatisticsLogger as StatisticsLoggerInterface; class StartWebSocketServer extends Command { @@ -49,16 +47,16 @@ class StartWebSocketServer extends Command 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 @@ class StartWebSocketServer extends Command 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 @@ class StartWebSocketServer extends Command 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 @@ class StartWebSocketServer extends Command 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 @@ class StartWebSocketServer extends Command $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 a15d495..315135f 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 @@ class DashboardLogger 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 @@ class DashboardLogger '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 dd7da7f..8e58775 100644 --- a/src/Dashboard/Http/Controllers/AuthenticateDashboard.php +++ b/src/Dashboard/Http/Controllers/AuthenticateDashboard.php @@ -16,4 +16,4 @@ class AuthenticateDashboard */ 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 f7eecb5..1d77b9d 100644 --- a/src/Dashboard/Http/Controllers/DashboardApiController.php +++ b/src/Dashboard/Http/Controllers/DashboardApiController.php @@ -11,7 +11,7 @@ class DashboardApiController $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 @@ class DashboardApiController '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 eea53a3..5c4461a 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 3541c45..5e04c7a 100644 --- a/src/Dashboard/Http/Controllers/ShowDashboard.php +++ b/src/Dashboard/Http/Controllers/ShowDashboard.php @@ -13,4 +13,4 @@ class ShowDashboard '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 0314cb8..772107f 100644 --- a/src/Dashboard/Http/Middleware/Authorize.php +++ b/src/Dashboard/Http/Middleware/Authorize.php @@ -10,4 +10,4 @@ class Authorize { 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 49b230b..1d20402 100644 --- a/src/Exceptions/InvalidApp.php +++ b/src/Exceptions/InvalidApp.php @@ -15,4 +15,4 @@ class InvalidApp extends Exception { 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 2c03d9c..96c1a4a 100644 --- a/src/Exceptions/InvalidWebSocketController.php +++ b/src/Exceptions/InvalidWebSocketController.php @@ -12,4 +12,4 @@ class InvalidWebSocketController extends \Exception 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 6bb86c9..c43aab4 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 b2da458..f88c49c 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 Illuminate\Http\JsonResponse; 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 @@ abstract class Controller implements HttpServerInterface $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 @@ abstract class Controller implements HttpServerInterface 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 @@ abstract class Controller implements HttpServerInterface } 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 af7a96e..6a24fd5 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 @@ class FetchChannelController extends Controller return $channel->toArray(); } -} \ No newline at end of file +} diff --git a/src/HttpApi/Controllers/FetchChannelsController.php b/src/HttpApi/Controllers/FetchChannelsController.php index 26564d6..937000e 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 @@ class FetchChannelsController extends Controller 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 9b3551d..87960e4 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 @@ class FetchUsersController extends Controller 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 cd81729..0764071 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 @@ class TriggerEventController extends Controller return $request->json()->all(); } -} \ No newline at end of file +} diff --git a/src/QueryParameters.php b/src/QueryParameters.php index 85fecff..85ee8af 100644 --- a/src/QueryParameters.php +++ b/src/QueryParameters.php @@ -32,4 +32,4 @@ class QueryParameters { return $this->all()[$name] ?? ''; } -} \ No newline at end of file +} diff --git a/src/Server/HttpServer.php b/src/Server/HttpServer.php index 82a26d4..2c33737 100644 --- a/src/Server/HttpServer.php +++ b/src/Server/HttpServer.php @@ -12,4 +12,4 @@ class HttpServer extends \Ratchet\Http\HttpServer $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 6e06762..154c6c2 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 @@ class ConnectionLogger extends Logger implements ConnectionInterface 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 7058bad..b60b099 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 @@ class HttpLogger extends Logger implements MessageComponentInterface $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 434d4c8..7422309 100644 --- a/src/Server/Logger/Logger.php +++ b/src/Server/Logger/Logger.php @@ -67,4 +67,4 @@ class Logger $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 d4defc1..2088ae3 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 @@ class WebsocketsLogger extends Logger implements MessageComponentInterface $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 883efb7..dfebfff 100644 --- a/src/Server/OriginCheck.php +++ b/src/Server/OriginCheck.php @@ -5,8 +5,8 @@ namespace BeyondCode\LaravelWebSockets\Server; 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 @@ class OriginCheck implements HttpServerInterface 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 d68c8e1..25dbb77 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 @@ class Router 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 @@ class Router return new WsServer($app); } -} \ No newline at end of file +} diff --git a/src/Server/WebSocketServerFactory.php b/src/Server/WebSocketServerFactory.php index aabdaf2..e7bdd82 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 29816a4..824167c 100644 --- a/src/Statistics/DnsResolver.php +++ b/src/Statistics/DnsResolver.php @@ -19,4 +19,4 @@ class DnsResolver extends Resolver { 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 9368309..2a420fb 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 @@ class StatisticsUpdated implements ShouldBroadcast 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 @@ class StatisticsUpdated implements ShouldBroadcast 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 @@ class StatisticsUpdated implements ShouldBroadcast { 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 f898b2e..39ea041 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 @@ class WebSocketStatisticsEntriesController 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 32e19a6..277d8e4 100644 --- a/src/Statistics/Http/Middleware/Authorize.php +++ b/src/Statistics/Http/Middleware/Authorize.php @@ -10,4 +10,4 @@ class Authorize { 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 d6bc759..63a8640 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 7543d32..a23f7a9 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 @@ class HttpStatisticsLogger implements StatisticsLogger 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 @@ class HttpStatisticsLogger implements StatisticsLogger 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 @@ class HttpStatisticsLogger implements StatisticsLogger $statistic->reset($currentConnectionCount); } } -} \ No newline at end of file +} diff --git a/src/Statistics/Logger/StatisticsLogger.php b/src/Statistics/Logger/StatisticsLogger.php index 5b82884..402a58a 100644 --- a/src/Statistics/Logger/StatisticsLogger.php +++ b/src/Statistics/Logger/StatisticsLogger.php @@ -15,4 +15,4 @@ interface StatisticsLogger 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 637047e..24f0a7f 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 da6d62f..a6fc6d2 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 @@ class AppId implements Rule 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 8fda8cc..93765fb 100644 --- a/src/Statistics/Statistic.php +++ b/src/Statistics/Statistic.php @@ -72,4 +72,4 @@ class Statistic '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 b309466..8735d78 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 @@ class Channel $connection->send(json_encode([ 'event' => 'pusher_internal:subscription_succeeded', - 'channel' => $this->channelName + 'channel' => $this->channelName, ])); } @@ -108,7 +107,7 @@ class Channel { 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 7dd4e53..5339192 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 @@ class ChannelManager 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 @@ class ChannelManager 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 1d5ee99..bb6ec45 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 @@ class PresenceChannel extends Channel $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 @@ class PresenceChannel extends Channel '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 @@ class PresenceChannel extends Channel 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 @@ class PresenceChannel extends Channel return $hash; } -} \ No newline at end of file +} diff --git a/src/WebSockets/Channels/PrivateChannel.php b/src/WebSockets/Channels/PrivateChannel.php index d758ed1..34f3ac0 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 @@ class PrivateChannel extends Channel 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 bbad9e3..9a80077 100644 --- a/src/WebSockets/Exceptions/InvalidConnection.php +++ b/src/WebSockets/Exceptions/InvalidConnection.php @@ -10,4 +10,4 @@ class InvalidConnection extends WebSocketException $this->code = 4009; } -} \ No newline at end of file +} diff --git a/src/WebSockets/Exceptions/InvalidSignature.php b/src/WebSockets/Exceptions/InvalidSignature.php index 2341bb5..71f87a1 100644 --- a/src/WebSockets/Exceptions/InvalidSignature.php +++ b/src/WebSockets/Exceptions/InvalidSignature.php @@ -10,4 +10,4 @@ class InvalidSignature extends WebSocketException $this->code = 4009; } -} \ No newline at end of file +} diff --git a/src/WebSockets/Exceptions/UnknownAppKey.php b/src/WebSockets/Exceptions/UnknownAppKey.php index 7f5285e..6fe5c83 100644 --- a/src/WebSockets/Exceptions/UnknownAppKey.php +++ b/src/WebSockets/Exceptions/UnknownAppKey.php @@ -10,4 +10,4 @@ class UnknownAppKey extends WebSocketException $this->code = 4001; } -} \ No newline at end of file +} diff --git a/src/WebSockets/Exceptions/WebSocketException.php b/src/WebSockets/Exceptions/WebSocketException.php index 3832e12..5c83cca 100644 --- a/src/WebSockets/Exceptions/WebSocketException.php +++ b/src/WebSockets/Exceptions/WebSocketException.php @@ -12,8 +12,8 @@ class WebSocketException extends Exception '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 47835e7..b2f3cb9 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 656737d..8a1ac7d 100644 --- a/src/WebSockets/Messages/PusherClientMessage.php +++ b/src/WebSockets/Messages/PusherClientMessage.php @@ -2,11 +2,10 @@ namespace BeyondCode\LaravelWebSockets\WebSockets\Messages; -use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger; -use BeyondCode\LaravelWebSockets\Events\ClientMessageSent; -use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; -use Ratchet\ConnectionInterface; use stdClass; +use Ratchet\ConnectionInterface; +use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger; +use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; class PusherClientMessage implements PusherMessage { @@ -30,7 +29,7 @@ class PusherClientMessage implements PusherMessage public function respond() { - if (!starts_with($this->payload->event, 'client-')) { + if (! starts_with($this->payload->event, 'client-')) { return; } @@ -44,4 +43,4 @@ class PusherClientMessage implements PusherMessage 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 0d0d086..bed9550 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 @@ class WebSocketHandler implements MessageComponentInterface 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 @@ class WebSocketHandler implements MessageComponentInterface 'data' => json_encode([ 'socket_id' => $connection->socketId, 'activity_timeout' => 30, - ]) + ]), ])); DashboardLogger::connection($connection); @@ -98,4 +98,4 @@ class WebSocketHandler implements MessageComponentInterface return $this; } -} \ No newline at end of file +} diff --git a/src/WebSocketsServiceProvider.php b/src/WebSocketsServiceProvider.php index bd895b7..3c82126 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 BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\SendMessage; -use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\ShowDashboard; -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\Server\Router; +use BeyondCode\LaravelWebSockets\Apps\AppProvider; use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; -use Illuminate\Support\Str; +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\Statistics\Http\Controllers\WebSocketStatisticsEntriesController; 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 @@ class WebSocketsServiceProvider extends ServiceProvider ->registerRoutes() ->registerDashboardGate(); - $this->loadViewsFrom(__DIR__ . '/../resources/views/', 'websockets'); + $this->loadViewsFrom(__DIR__.'/../resources/views/', 'websockets'); $this->commands([ Console\StartWebSocketServer::class, @@ -46,7 +44,7 @@ class WebSocketsServiceProvider extends ServiceProvider 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 @@ class WebSocketsServiceProvider extends ServiceProvider 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 2cc7a7b..f51259c 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 @@ class ChannelTest extends TestCase $message = new Message(json_encode([ 'event' => 'pusher:subscribe', 'data' => [ - 'channel' => 'basic-channel' + 'channel' => 'basic-channel', ], ])); @@ -24,7 +24,7 @@ class ChannelTest extends TestCase $this->pusherServer->onMessage($connection, $message); $connection->assertSentEvent('pusher_internal:subscription_succeeded', [ - 'channel' => 'basic-channel' + 'channel' => 'basic-channel', ]); } @@ -40,7 +40,7 @@ class ChannelTest extends TestCase $message = new Message(json_encode([ 'event' => 'pusher:unsubscribe', 'data' => [ - 'channel' => 'test-channel' + 'channel' => 'test-channel', ], ])); @@ -108,7 +108,7 @@ class ChannelTest extends TestCase $channel->broadcast([ 'event' => 'broadcasted-event', - 'channel' => 'test-channel' + 'channel' => 'test-channel', ]); $connection1->assertSentEvent('broadcasted-event'); @@ -125,7 +125,7 @@ class ChannelTest extends TestCase $channel->broadcastToOthers($connection1, [ 'event' => 'broadcasted-event', - 'channel' => 'test-channel' + 'channel' => 'test-channel', ]); $connection1->assertNotSentEvent('broadcasted-event'); @@ -145,4 +145,4 @@ class ChannelTest extends TestCase $connection->assertSentEvent('pusher:pong'); } -} \ No newline at end of file +} diff --git a/tests/Channels/PresenceChannelTest.php b/tests/Channels/PresenceChannelTest.php index def322b..0d2d093 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 @@ class PresenceChannelTest extends TestCase 'event' => 'pusher:subscribe', 'data' => [ 'auth' => 'invalid', - 'channel' => 'presence-channel' + 'channel' => 'presence-channel', ], ])); @@ -38,8 +38,8 @@ class PresenceChannelTest extends TestCase $channelData = [ 'user_id' => 1, 'user_info' => [ - 'name' => 'Marcel' - ] + 'name' => 'Marcel', + ], ]; $signature = "{$connection->socketId}:presence-channel:".json_encode($channelData); @@ -49,7 +49,7 @@ class PresenceChannelTest extends TestCase '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 @@ class PresenceChannelTest extends TestCase 'channel' => 'presence-channel', ]); } -} \ No newline at end of file +} diff --git a/tests/Channels/PrivateChannelTest.php b/tests/Channels/PrivateChannelTest.php index e0ee0d9..c933d98 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 @@ class PrivateChannelTest extends TestCase 'event' => 'pusher:subscribe', 'data' => [ 'auth' => 'invalid', - 'channel' => 'private-channel' + 'channel' => 'private-channel', ], ])); @@ -43,14 +43,14 @@ class PrivateChannelTest extends TestCase '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 12dd4c3..71393d7 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 @@ class AppTest extends TestCase new App(1, 'appKey', '', 'new'); } -} \ No newline at end of file +} diff --git a/tests/ClientProviders/ConfigAppProviderTest.php b/tests/ClientProviders/ConfigAppProviderTest.php index 421a73b..f8909db 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 @@ class ConfigAppProviderTest extends TestCase $this->assertCount(1, $apps); - /** @var $app */ + /** @var $app */ $app = $apps[0]; $this->assertEquals('Test App', $app->name); @@ -85,4 +85,4 @@ class ConfigAppProviderTest extends TestCase $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 5605ce4..0c7fd28 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 @@ class CleanStatisticsTest extends TestCase $this->app['config']->set('websockets.statistics.delete_statistics_older_than_days', 31); } - /** @test */ public function it_can_clean_the_statistics() { @@ -44,4 +42,4 @@ class CleanStatisticsTest extends TestCase $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 caad118..62cf154 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 @@ class ConnectionTest extends TestCase $connection->assertSentEvent('pusher:pong'); } -} \ No newline at end of file +} diff --git a/tests/HttpApi/FetchChannelTest.php b/tests/HttpApi/FetchChannelTest.php index 34643bd..cabc459 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 @@ class FetchChannelTest extends TestCase $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 @@ class FetchChannelTest extends TestCase $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 @@ class FetchChannelTest extends TestCase $this->assertSame([ 'occupied' => true, - 'subscription_count' => 2 + 'subscription_count' => 2, ], json_decode($response->getContent(), true)); } @@ -92,12 +91,12 @@ class FetchChannelTest extends TestCase $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 @@ class FetchChannelTest extends TestCase $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 78f8cc6..088dabf 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 @@ class FetchChannelsTest extends TestCase $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 @@ class FetchChannelsTest extends TestCase $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 @@ class FetchChannelsTest extends TestCase $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 0881e37..543aeb0 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 @@ class FetchUsersTest extends TestCase $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 @@ class FetchUsersTest extends TestCase $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 @@ class FetchUsersTest extends TestCase $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 @@ class FetchUsersTest extends TestCase $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 @@ class FetchUsersTest extends TestCase $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 d16d640..855ceee 100644 --- a/tests/Messages/PusherClientMessageTest.php +++ b/tests/Messages/PusherClientMessageTest.php @@ -16,7 +16,7 @@ class PusherClientMessageTest extends TestCase 'event' => 'client-test', 'channel' => 'test-channel', 'data' => [ - 'client-event' => 'test' + 'client-event' => 'test', ], ])); @@ -46,7 +46,7 @@ class PusherClientMessageTest extends TestCase 'event' => 'client-test', 'channel' => 'test-channel', 'data' => [ - 'client-event' => 'test' + 'client-event' => 'test', ], ])); @@ -56,8 +56,8 @@ class PusherClientMessageTest extends TestCase $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 1ecfbca..a0c37d0 100644 --- a/tests/Mocks/Connection.php +++ b/tests/Mocks/Connection.php @@ -54,4 +54,4 @@ class Connection implements ConnectionInterface { PHPUnit::assertTrue($this->closed); } -} \ No newline at end of file +} diff --git a/tests/Mocks/Message.php b/tests/Mocks/Message.php index 8b68e6a..3b0706c 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 @@ class Message extends \Ratchet\RFC6455\Messaging\Message { return $this->payload; } -} \ No newline at end of file +} diff --git a/tests/Statistics/Controllers/WebSocketsStatisticsControllerTest.php b/tests/Statistics/Controllers/WebSocketsStatisticsControllerTest.php index a38f6a8..482f50b 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 @@ class WebSocketsStatisticsControllerTest extends TestCase '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 56d344c..3176d09 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 @@ class AppIdTest extends TestCase $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 1a51144..d863cba 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 BeyondCode\LaravelWebSockets\Tests\Mocks\Connection; -use BeyondCode\LaravelWebSockets\WebSocketsServiceProvider; -use Illuminate\Support\Facades\Route; 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 BeyondCode\LaravelWebSockets\WebSockets\WebSocketHandler; +use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager; abstract class TestCase extends \Orchestra\Testbench\TestCase { @@ -53,8 +51,6 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase 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 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase $message = new Message(json_encode([ 'event' => 'pusher:subscribe', 'data' => [ - 'channel' => $channel + 'channel' => $channel, ], ])); @@ -97,8 +93,8 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase $channelData = [ 'user_id' => 1, 'user_info' => [ - 'name' => 'Marcel' - ] + 'name' => 'Marcel', + ], ]; $signature = "{$connection->socketId}:{$channel}:".json_encode($channelData); @@ -108,7 +104,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase '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 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase { $this->assertTrue(true); } -} \ No newline at end of file +}