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

Apply fixes from StyleCI #3

Merged
merged 1 commit into from
Dec 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config/websockets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],

/*
Expand All @@ -89,6 +89,6 @@
/*
* Passphrase for your local_cert file.
*/
'passphrase' => null
'passphrase' => null,
],
];
4 changes: 2 additions & 2 deletions src/Apps/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Apps/AppProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ public function findById($appId): ?App;
public function findByKey(string $appKey): ?App;

public function findBySecret(string $appSecret): ?App;
}
}
5 changes: 2 additions & 3 deletions src/Apps/ConfigAppProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function findBySecret(string $appSecret): ?App

protected function instanciate(?array $appAttributes): ?App
{
if (!$appAttributes) {
if (! $appAttributes) {
return null;
}

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


return $app;
}
}
}
3 changes: 1 addition & 2 deletions src/Console/CleanStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

class CleanStatistics extends Command
{

protected $signature = 'websockets:clean
{appId? : (optional) The app id that will be cleaned.}';

Expand Down Expand Up @@ -36,4 +35,4 @@ public function handle()

$this->comment('All done!');
}
}
}
32 changes: 15 additions & 17 deletions src/Console/StartWebSocketServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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} ';
Expand Down Expand Up @@ -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();
});

Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -111,7 +109,7 @@ protected function startWebSocketServer()

$routes = WebSocketsRouter::getRoutes();

/** 🛰 Start the server 🛰 */
/* 🛰 Start the server 🛰 */
(new WebSocketServerFactory())
->setLoop($this->loop)
->useRoutes($routes)
Expand Down
9 changes: 4 additions & 5 deletions src/Dashboard/DashboardLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace BeyondCode\LaravelWebSockets\Dashboard;

use stdClass;
use Ratchet\ConnectionInterface;
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
use stdClass;

class DashboardLogger
{
Expand Down Expand Up @@ -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);

Expand All @@ -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,
]);
}

}
}
2 changes: 1 addition & 1 deletion src/Dashboard/Http/Controllers/AuthenticateDashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ public function __invoke(Request $request, Broadcaster $broadcaster)
*/
return $broadcaster->validAuthenticationResponse($request, []);
}
}
}
6 changes: 3 additions & 3 deletions src/Dashboard/Http/Controllers/DashboardApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -30,7 +30,7 @@ public function getStatistics($appId)
'api_message_count' => [
'x' => $statisticData->pluck('timestamp'),
'y' => $statisticData->pluck('api_message_count'),
]
],
];
}
}
}
2 changes: 1 addition & 1 deletion src/Dashboard/Http/Controllers/SendMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Dashboard/Http/Controllers/ShowDashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ public function __invoke(Request $request, AppProvider $apps)
'apps' => $apps->all(),
]);
}
}
}
2 changes: 1 addition & 1 deletion src/Dashboard/Http/Middleware/Authorize.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ public function handle($request, $next)
{
return Gate::check('viewWebSocketsDashboard') ? $next($request) : abort(403);
}
}
}
2 changes: 1 addition & 1 deletion src/Exceptions/InvalidApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ public static function valueIsRequired($name, $appId)
{
return new static("{$name} is required but was empty for app id `{$appId}`.");
}
}
}
2 changes: 1 addition & 1 deletion src/Exceptions/InvalidWebSocketController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ public static function withController(string $controllerClass)

return new static("Invalid WebSocket Controller provided. Expected instance of `{$messageComponentInterfaceClass}`, but received `{$controllerClass}`.");
}
}
}
2 changes: 1 addition & 1 deletion src/Facades/StatisticsLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 11 additions & 14 deletions src/HttpApi/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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));
Expand All @@ -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() !== '') {
Expand All @@ -109,4 +106,4 @@ protected function ensureValidSignature(Request $request)
}

abstract public function __invoke(Request $request);
}
}
3 changes: 1 addition & 2 deletions src/HttpApi/Controllers/FetchChannelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

return $channel->toArray();
}
}
}
5 changes: 2 additions & 3 deletions src/HttpApi/Controllers/FetchChannelsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,7 +25,7 @@ public function __invoke(Request $request)
return [
'user_count' => count($channel->getUsers()),
];
})->toArray()
})->toArray(),
];
}
}
}
5 changes: 2 additions & 3 deletions src/HttpApi/Controllers/FetchUsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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(),
];
}
}
}
Loading