Skip to content

Commit

Permalink
PHP 8.3 (#14)
Browse files Browse the repository at this point in the history
* PHP 8.3

* Fix code styling

---------

Co-authored-by: driesvints <[email protected]>
  • Loading branch information
driesvints and driesvints authored Sep 21, 2023
1 parent a41e0c4 commit acbe40d
Show file tree
Hide file tree
Showing 19 changed files with 29 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion src/Channels/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion src/Channels/PresenceChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/Channels/PrivateChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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()}";

Expand Down
2 changes: 1 addition & 1 deletion src/ClientEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Contracts/ChannelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions src/Contracts/ConnectionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/Managers/ChannelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(
/**
* Get the application instance.
*/
public function app(): Application|null
public function app(): ?Application
{
return $this->application;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Managers/ConnectionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(
/**
* Get the application instance.
*/
public function app(): Application|null
public function app(): ?Application
{
return $this->application;
}
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/Managers/Connections.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/PusherEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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([
Expand Down
2 changes: 1 addition & 1 deletion src/Servers/ApiGateway/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/Servers/Ratchet/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 0 additions & 2 deletions src/Servers/Ratchet/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
8 changes: 2 additions & 6 deletions tests/ApiGatewayTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/Ratchet/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 1 addition & 3 deletions tests/Pest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}";

Expand Down
12 changes: 5 additions & 7 deletions tests/RatchetTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@
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;
use React\Promise\Deferred;
use React\Promise\PromiseInterface;
use ReflectionObject;

use function Ratchet\Client\connect;
use function React\Async\await;

class RatchetTestCase extends TestCase
{
use InteractsWithAsyncRedis;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit acbe40d

Please sign in to comment.