From a3544915ef357e67e76b8de946dd1dc4868051d9 Mon Sep 17 00:00:00 2001 From: Slava Razum Date: Sat, 9 Dec 2023 23:22:48 +0100 Subject: [PATCH] Style fixes --- composer.json | 2 +- phpstan.neon.dist | 2 ++ phpstan.neon.rector.dist | 10 ++++++++++ rector.php | 10 ++++++++-- src/Sse/ServerSentEventStream.php | 2 +- src/Storage/BroadcastEventHistoryRedisStream.php | 6 +++--- ...WaveServiceProvider.php => WaveServiceProvider.php} | 2 +- tests/TestCase.php | 4 ++-- 8 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 phpstan.neon.rector.dist rename src/{LaravelWaveServiceProvider.php => WaveServiceProvider.php} (96%) diff --git a/composer.json b/composer.json index af7ed51..9d16d7d 100644 --- a/composer.json +++ b/composer.json @@ -86,7 +86,7 @@ "extra": { "laravel": { "providers": [ - "Qruto\\LaravelWave\\LaravelWaveServiceProvider" + "Qruto\\LaravelWave\\WaveServiceProvider" ] } }, diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 33bb217..79e2e07 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -7,4 +7,6 @@ parameters: - src - config tmpDir: build/phpstan + checkOctaneCompatibility: true + checkModelProperties: true checkMissingIterableValueType: false diff --git a/phpstan.neon.rector.dist b/phpstan.neon.rector.dist new file mode 100644 index 0000000..33bb217 --- /dev/null +++ b/phpstan.neon.rector.dist @@ -0,0 +1,10 @@ +includes: + - phpstan-baseline.neon + +parameters: + level: 4 + paths: + - src + - config + tmpDir: build/phpstan + checkMissingIterableValueType: false diff --git a/rector.php b/rector.php index e9df0c0..d76db00 100644 --- a/rector.php +++ b/rector.php @@ -4,6 +4,7 @@ use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector; use Rector\Config\RectorConfig; +use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector; use Rector\Set\ValueObject\LevelSetList; use Rector\Set\ValueObject\SetList; @@ -22,11 +23,16 @@ SetList::DEAD_CODE, SetList::EARLY_RETURN, // SetList::CODING_STYLE, -// SetList::NAMING, // SetList::ACTION_INJECTION_TO_CONSTRUCTOR_INJECTION, // SetList::PRIVATIZATION, // SetList::TYPE_DECLARATION, ]); - $rectorConfig->phpstanConfig(__DIR__.'/phpstan.neon.dist'); + $rectorConfig->skip([ + RemoveUnusedPromotedPropertyRector::class => [ + __DIR__ . '/src/Sse/ServerSentEvent.php', + ], + ]); + + $rectorConfig->phpstanConfig(__DIR__.'/phpstan.neon.rector.dist'); }; diff --git a/src/Sse/ServerSentEventStream.php b/src/Sse/ServerSentEventStream.php index d6cd64b..e9f5893 100644 --- a/src/Sse/ServerSentEventStream.php +++ b/src/Sse/ServerSentEventStream.php @@ -120,7 +120,7 @@ protected function shouldNotSend(BroadcastingEvent $event, ?string $socket, ?Aut return false; } - if ($user !== null && $this->presenceChannelEvent->isSelfLeaveEvent($event, $user)) { + if ($user instanceof \Illuminate\Contracts\Auth\Authenticatable && $this->presenceChannelEvent->isSelfLeaveEvent($event, $user)) { return true; } diff --git a/src/Storage/BroadcastEventHistoryRedisStream.php b/src/Storage/BroadcastEventHistoryRedisStream.php index e4d8d20..5630b7c 100644 --- a/src/Storage/BroadcastEventHistoryRedisStream.php +++ b/src/Storage/BroadcastEventHistoryRedisStream.php @@ -29,7 +29,7 @@ public function getEventsFrom(string $id): Collection return collect($this->db->xRange('broadcasted_events', $timestamp.'-'.$sequence, '+')) ->map(function ($event, $id) { - $event['data'] = json_decode($event['data'], true); + $event['data'] = json_decode($event['data'], true, 512, JSON_THROW_ON_ERROR); return new BroadcastingEvent(...['id' => $id] + $event); })->values(); @@ -39,7 +39,7 @@ public function lastEventTimestamp(): int { $keys = array_keys($this->db->xRevRange('broadcasted_events', '-', '+', 1)); - return empty($keys) ? 0 : explode('-', reset($keys))[0]; + return $keys === [] ? 0 : explode('-', reset($keys))[0]; } public function pushEvent(BroadcastingEvent $event) @@ -47,7 +47,7 @@ public function pushEvent(BroadcastingEvent $event) $this->removeOldEvents(); $eventData = \get_object_vars($event); - $eventData['data'] = json_encode($eventData['data']); + $eventData['data'] = json_encode($eventData['data'], JSON_THROW_ON_ERROR); $id = $this->db->xAdd('broadcasted_events', '*', $eventData); $event->id = $id; diff --git a/src/LaravelWaveServiceProvider.php b/src/WaveServiceProvider.php similarity index 96% rename from src/LaravelWaveServiceProvider.php rename to src/WaveServiceProvider.php index 6533030..ee7089a 100644 --- a/src/LaravelWaveServiceProvider.php +++ b/src/WaveServiceProvider.php @@ -15,7 +15,7 @@ use Spatie\LaravelPackageTools\Package; use Spatie\LaravelPackageTools\PackageServiceProvider; -class LaravelWaveServiceProvider extends PackageServiceProvider +class WaveServiceProvider extends PackageServiceProvider { public function configurePackage(Package $package): void { diff --git a/tests/TestCase.php b/tests/TestCase.php index 0d948fe..66da4cb 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -6,7 +6,7 @@ use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; use Orchestra\Testbench\TestCase as Orchestra; -use Qruto\LaravelWave\LaravelWaveServiceProvider; +use Qruto\LaravelWave\WaveServiceProvider; class TestCase extends Orchestra { @@ -22,7 +22,7 @@ protected function setUp(): void protected function getPackageProviders($app) { return [ - LaravelWaveServiceProvider::class, + WaveServiceProvider::class, ]; }