diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 402b747b..7eeb0f2f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -28,7 +28,7 @@ jobs: strategy: fail-fast: true matrix: - php: [8.2] + php: [8.2, 8.3] laravel: [10] name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} diff --git a/src/Channels/Channel.php b/src/Channels/Channel.php index 4be82bf4..8b0fae42 100644 --- a/src/Channels/Channel.php +++ b/src/Channels/Channel.php @@ -27,7 +27,7 @@ public function name(): string /** * Subscribe to the given channel. */ - public function subscribe(Connection $connection, ?string $auth = null, ?string $data = null): void + public function subscribe(Connection $connection, string $auth = null, string $data = null): void { App::make(ChannelManager::class) ->for($connection->app()) diff --git a/src/Channels/PresenceChannel.php b/src/Channels/PresenceChannel.php index dd2e570e..84835813 100644 --- a/src/Channels/PresenceChannel.php +++ b/src/Channels/PresenceChannel.php @@ -12,7 +12,7 @@ class PresenceChannel extends PrivateChannel /** * Subscribe to the given channel. */ - public function subscribe(Connection $connection, ?string $auth = null, ?string $data = null): void + public function subscribe(Connection $connection, string $auth = null, string $data = null): void { parent::subscribe($connection, $auth, $data); diff --git a/src/Channels/PrivateChannel.php b/src/Channels/PrivateChannel.php index 25cced06..5cfd6ade 100644 --- a/src/Channels/PrivateChannel.php +++ b/src/Channels/PrivateChannel.php @@ -11,7 +11,7 @@ class PrivateChannel extends Channel /** * Subscribe to the given channel. */ - public function subscribe(Connection $connection, ?string $auth = null, ?string $data = null): void + public function subscribe(Connection $connection, string $auth = null, string $data = null): void { $this->verify($connection, $auth, $data); @@ -21,7 +21,7 @@ public function subscribe(Connection $connection, ?string $auth = null, ?string /** * Deteremine whether the given auth token is valid. */ - protected function verify(Connection $connection, string $auth, ?string $data = null): bool + protected function verify(Connection $connection, string $auth, string $data = null): bool { $signature = "{$connection->id()}:{$this->name()}"; diff --git a/src/ClientEvent.php b/src/ClientEvent.php index d0a21083..3a123b57 100644 --- a/src/ClientEvent.php +++ b/src/ClientEvent.php @@ -9,7 +9,7 @@ class ClientEvent /** * Handle a pusher event. */ - public static function handle(Connection $connection, array $event): ClientEvent|null + public static function handle(Connection $connection, array $event): ?ClientEvent { if (! Str::startsWith($event['event'], 'client-')) { return null; diff --git a/src/Connection.php b/src/Connection.php index fe7edfd9..e24bb4d7 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -59,7 +59,7 @@ public function app(): Application /** * Get the origin of the connection. */ - public function origin(): string|null + public function origin(): ?string { return $this->origin; } diff --git a/src/Contracts/ChannelManager.php b/src/Contracts/ChannelManager.php index 407335fe..1a23c7c3 100644 --- a/src/Contracts/ChannelManager.php +++ b/src/Contracts/ChannelManager.php @@ -13,7 +13,7 @@ interface ChannelManager /** * Get the application instance. */ - public function app(): Application|null; + public function app(): ?Application; /** * The application the channel manager should be scoped to. diff --git a/src/Contracts/ConnectionManager.php b/src/Contracts/ConnectionManager.php index eb7e2242..7515b70c 100644 --- a/src/Contracts/ConnectionManager.php +++ b/src/Contracts/ConnectionManager.php @@ -12,7 +12,7 @@ interface ConnectionManager /** * Get the application instance. */ - public function app(): Application|null; + public function app(): ?Application; /** * The application the channel manager should be scoped to. @@ -27,7 +27,7 @@ public function connect(Connection $connection): Connection; /** * Attempt to find a connection from the manager. */ - public function reconnect(string $identifier): Connection|null; + public function reconnect(string $identifier): ?Connection; /** * Remove a connection from the manager. @@ -42,7 +42,7 @@ public function resolve(string $identifier, Closure $newConnection): Connection; /** * Find a connection by its identifier. */ - public function find(string $identifier): Connection|null; + public function find(string $identifier): ?Connection; /** * Get all of the connections from the cache. diff --git a/src/Managers/ChannelManager.php b/src/Managers/ChannelManager.php index f59e5d6a..da7be7d1 100644 --- a/src/Managers/ChannelManager.php +++ b/src/Managers/ChannelManager.php @@ -36,7 +36,7 @@ public function __construct( /** * Get the application instance. */ - public function app(): Application|null + public function app(): ?Application { return $this->application; } diff --git a/src/Managers/ConnectionManager.php b/src/Managers/ConnectionManager.php index 4157846f..9fac3877 100644 --- a/src/Managers/ConnectionManager.php +++ b/src/Managers/ConnectionManager.php @@ -34,7 +34,7 @@ public function __construct( /** * Get the application instance. */ - public function app(): Application|null + public function app(): ?Application { return $this->application; } @@ -54,7 +54,7 @@ public function connect(Connection $connection): Connection /** * Attempt to find a connection from the manager. */ - public function reconnect(string $identifier): Connection|null + public function reconnect(string $identifier): ?Connection { if ($connection = $this->find($identifier)) { return $connection->touch(); diff --git a/src/Managers/Connections.php b/src/Managers/Connections.php index 72a2ea68..b7e0436b 100644 --- a/src/Managers/Connections.php +++ b/src/Managers/Connections.php @@ -10,7 +10,7 @@ class Connections extends Collection /** * Find a connection in the collection. */ - public function find(string $identifier): Connection|null + public function find(string $identifier): ?Connection { if (! $connection = parent::get($identifier)) { return null; diff --git a/src/PusherEvent.php b/src/PusherEvent.php index 9d1e2ea2..113e5913 100644 --- a/src/PusherEvent.php +++ b/src/PusherEvent.php @@ -42,7 +42,7 @@ public static function acknowledge(Connection $connection): void /** * Subscribe to the given channel. */ - public static function subscribe(Connection $connection, string $channel, ?string $auth = null, ?string $data = null): void + public static function subscribe(Connection $connection, string $channel, string $auth = null, string $data = null): void { $channel = ChannelBroker::create($channel); @@ -99,7 +99,7 @@ public static function sendInternally(Connection $connection, string $event, str /** * Format the payload for the given event. */ - public static function formatPayload(string $event, array $data = [], ?string $channel = null, string $prefix = 'pusher:'): string|false + public static function formatPayload(string $event, array $data = [], string $channel = null, string $prefix = 'pusher:'): string|false { return json_encode( array_filter([ diff --git a/src/Servers/ApiGateway/Server.php b/src/Servers/ApiGateway/Server.php index 8252bb4d..4e0e0d19 100644 --- a/src/Servers/ApiGateway/Server.php +++ b/src/Servers/ApiGateway/Server.php @@ -83,7 +83,7 @@ protected function getConnection(Request $request): Connection /** * Get the application instance for the request. */ - protected function application(Request $request): Application|null + protected function application(Request $request): ?Application { parse_str($request->serverVariables['QUERY_STRING'], $queryString); diff --git a/src/Servers/Ratchet/Factory.php b/src/Servers/Ratchet/Factory.php index 0c236b13..03ad3770 100644 --- a/src/Servers/Ratchet/Factory.php +++ b/src/Servers/Ratchet/Factory.php @@ -21,7 +21,7 @@ class Factory /** * Create a new WebSocket server instance. */ - public static function make(string $host = '0.0.0.0', string $port = '8080', ?LoopInterface $loop = null): IoServer + public static function make(string $host = '0.0.0.0', string $port = '8080', LoopInterface $loop = null): IoServer { $loop = $loop ?: Loop::get(); diff --git a/src/Servers/Ratchet/Server.php b/src/Servers/Ratchet/Server.php index 44688403..14bb46c9 100644 --- a/src/Servers/Ratchet/Server.php +++ b/src/Servers/Ratchet/Server.php @@ -74,8 +74,6 @@ public function onError(ConnectionInterface $connection, Exception $e): void /** * Get a Reverb connection from a Ratchet connection. - * - * @return \Laravel\Reverb\Servers\Ratchet\Connection */ protected function connection(ConnectionInterface $connection): Connection { diff --git a/tests/ApiGatewayTestCase.php b/tests/ApiGatewayTestCase.php index ddc142c4..81fb748e 100644 --- a/tests/ApiGatewayTestCase.php +++ b/tests/ApiGatewayTestCase.php @@ -94,7 +94,6 @@ public function connect($connectionId = 'abc-123', $appKey = 'pusher-key'): void /** * Send a message to the connected client. * - * @param string $connectionId * @param string $appKey */ public function send(array $message, ?string $connectionId = 'abc-123', $appKey = 'pusher-key'): void @@ -116,11 +115,9 @@ public function send(array $message, ?string $connectionId = 'abc-123', $appKey /** * Subscribe to a channel. * - * @param array $data - * @param string $connectionId * @param string $appKey */ - public function subscribe(string $channel, ?array $data = [], ?string $auth = null, ?string $connectionId = 'abc-123', $appKey = 'pusher-key'): void + public function subscribe(string $channel, ?array $data = [], string $auth = null, ?string $connectionId = 'abc-123', $appKey = 'pusher-key'): void { $data = ! empty($data) ? json_encode($data) : null; @@ -161,10 +158,9 @@ public function disconnect($connectionId = 'abc-123'): void /** * Assert a message was sent to the given connection. * - * @param mixed $message * @return void */ - public function assertSent(string $connectionId = null, mixed $message = null, ?int $times = null) + public function assertSent(string $connectionId = null, mixed $message = null, int $times = null) { Bus::assertDispatched(SendToConnection::class, function ($job) use ($connectionId, $message) { return ($connectionId ? $job->connectionId === $connectionId : true) diff --git a/tests/Feature/Ratchet/ServerTest.php b/tests/Feature/Ratchet/ServerTest.php index a40f1f16..0b688fd3 100644 --- a/tests/Feature/Ratchet/ServerTest.php +++ b/tests/Feature/Ratchet/ServerTest.php @@ -10,10 +10,11 @@ use Laravel\Reverb\Jobs\PingInactiveConnections; use Laravel\Reverb\Jobs\PruneStaleConnections; use Laravel\Reverb\Tests\RatchetTestCase; +use React\Promise\Deferred; + use function Ratchet\Client\connect; use function React\Async\await; use function React\Promise\all; -use React\Promise\Deferred; uses(RatchetTestCase::class); diff --git a/tests/Pest.php b/tests/Pest.php index 12673d59..9692b6c5 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -31,10 +31,8 @@ function connections(int $count = 1, $serializable = false): Connections /** * Generate a valid Pusher authentication signature. - * - * @param string $data */ -function validAuth(ReverbConnection $connection, string $channel, ?string $data = null): string +function validAuth(ReverbConnection $connection, string $channel, string $data = null): string { $signature = "{$connection->id()}:{$channel}"; diff --git a/tests/RatchetTestCase.php b/tests/RatchetTestCase.php index 3e16f2b2..5ae060e9 100644 --- a/tests/RatchetTestCase.php +++ b/tests/RatchetTestCase.php @@ -11,9 +11,7 @@ use Laravel\Reverb\Event; use Laravel\Reverb\Loggers\NullLogger; use Laravel\Reverb\Servers\Ratchet\Factory; -use function Ratchet\Client\connect; use Ratchet\Client\WebSocket; -use function React\Async\await; use React\Async\SimpleFiber; use React\EventLoop\Factory as LoopFactory; use React\Http\Browser; @@ -21,6 +19,9 @@ use React\Promise\PromiseInterface; use ReflectionObject; +use function Ratchet\Client\connect; +use function React\Async\await; + class RatchetTestCase extends TestCase { use InteractsWithAsyncRedis; @@ -158,7 +159,7 @@ public function connect($host = '0.0.0.0', $port = '8080', $key = 'pusher-key', /** * Send a message to the connected client. */ - public function send(array $message, ?WebSocket $connection = null): string + public function send(array $message, WebSocket $connection = null): string { $promise = new Deferred; @@ -191,11 +192,8 @@ public function disconnect(WebSocket $connection): string /** * Subscribe to a channel. - * - * @param array $data - * @param string $auth */ - public function subscribe(string $channel, ?array $data = [], ?string $auth = null, ?WebSocket $connection = null): string + public function subscribe(string $channel, ?array $data = [], string $auth = null, WebSocket $connection = null): string { $data = ! empty($data) ? json_encode($data) : null;