diff --git a/src/Broadcasters/Broadcaster.php b/src/Broadcasters/Broadcaster.php index 42c9e537..dacc0f4d 100644 --- a/src/Broadcasters/Broadcaster.php +++ b/src/Broadcasters/Broadcaster.php @@ -20,13 +20,13 @@ public function broadcast( array $channels, bool $later, string $action, - string $target = null, - string $targets = null, - string $partial = null, + ?string $target = null, + ?string $targets = null, + ?string $partial = null, ?array $partialData = [], - string $inlineContent = null, + ?string $inlineContent = null, bool $escapeInlineContent = true, array $attributes = [], - string $exceptSocket = null, + ?string $exceptSocket = null, ): void; } diff --git a/src/Broadcasters/LaravelBroadcaster.php b/src/Broadcasters/LaravelBroadcaster.php index d70c4db3..02102c3f 100644 --- a/src/Broadcasters/LaravelBroadcaster.php +++ b/src/Broadcasters/LaravelBroadcaster.php @@ -21,14 +21,14 @@ public function broadcast( array $channels, bool $later, string $action, - string $target = null, - string $targets = null, - string $partial = null, + ?string $target = null, + ?string $targets = null, + ?string $partial = null, ?array $partialData = [], - string $inlineContent = null, + ?string $inlineContent = null, bool $escapeInlineContent = true, array $attributes = [], - string $exceptSocket = null, + ?string $exceptSocket = null, ): void { $job = new BroadcastAction( $channels, diff --git a/src/Broadcasting/Factory.php b/src/Broadcasting/Factory.php index 58f8e869..f04e6a50 100644 --- a/src/Broadcasting/Factory.php +++ b/src/Broadcasting/Factory.php @@ -52,42 +52,42 @@ public function fake() return $this; } - public function broadcastAppend($content = null, Model|string $target = null, string $targets = null, Channel|Model|Collection|array|string $channel = null, array $attributes = []) + public function broadcastAppend($content = null, Model|string|null $target = null, ?string $targets = null, Channel|Model|Collection|array|string|null $channel = null, array $attributes = []) { return $this->broadcastAction('append', $content, $target, $targets, $channel, $attributes); } - public function broadcastPrepend($content = null, Model|string $target = null, string $targets = null, Channel|Model|Collection|array|string $channel = null, array $attributes = []) + public function broadcastPrepend($content = null, Model|string|null $target = null, ?string $targets = null, Channel|Model|Collection|array|string|null $channel = null, array $attributes = []) { return $this->broadcastAction('prepend', $content, $target, $targets, $channel, $attributes); } - public function broadcastBefore($content = null, Model|string $target = null, string $targets = null, Channel|Model|Collection|array|string $channel = null, array $attributes = []) + public function broadcastBefore($content = null, Model|string|null $target = null, ?string $targets = null, Channel|Model|Collection|array|string|null $channel = null, array $attributes = []) { return $this->broadcastAction('before', $content, $target, $targets, $channel, $attributes); } - public function broadcastAfter($content = null, Model|string $target = null, string $targets = null, Channel|Model|Collection|array|string $channel = null, array $attributes = []) + public function broadcastAfter($content = null, Model|string|null $target = null, ?string $targets = null, Channel|Model|Collection|array|string|null $channel = null, array $attributes = []) { return $this->broadcastAction('after', $content, $target, $targets, $channel, $attributes); } - public function broadcastUpdate($content = null, Model|string $target = null, string $targets = null, Channel|Model|Collection|array|string $channel = null, array $attributes = []) + public function broadcastUpdate($content = null, Model|string|null $target = null, ?string $targets = null, Channel|Model|Collection|array|string|null $channel = null, array $attributes = []) { return $this->broadcastAction('update', $content, $target, $targets, $channel, $attributes); } - public function broadcastReplace($content = null, Model|string $target = null, string $targets = null, Channel|Model|Collection|array|string $channel = null, array $attributes = []) + public function broadcastReplace($content = null, Model|string|null $target = null, ?string $targets = null, Channel|Model|Collection|array|string|null $channel = null, array $attributes = []) { return $this->broadcastAction('replace', $content, $target, $targets, $channel, $attributes); } - public function broadcastRemove(Model|string $target = null, string $targets = null, Channel|Model|Collection|array|string $channel = null, array $attributes = []) + public function broadcastRemove(Model|string|null $target = null, ?string $targets = null, Channel|Model|Collection|array|string|null $channel = null, array $attributes = []) { return $this->broadcastAction('remove', null, $target, $targets, $channel, $attributes); } - public function broadcastRefresh(Channel|Model|Collection|array|string $channel = null) + public function broadcastRefresh(Channel|Model|Collection|array|string|null $channel = null) { return $this->broadcastAction( action: 'refresh', @@ -98,7 +98,7 @@ public function broadcastRefresh(Channel|Model|Collection|array|string $channel )); } - public function broadcastAction(string $action, $content = null, Model|string $target = null, string $targets = null, Channel|Model|Collection|array|string $channel = null, array $attributes = []) + public function broadcastAction(string $action, $content = null, Model|string|null $target = null, ?string $targets = null, Channel|Model|Collection|array|string|null $channel = null, array $attributes = []) { $broadcast = new PendingBroadcast( channels: $channel ? $this->resolveChannels($channel) : [], diff --git a/src/Broadcasting/PendingBroadcast.php b/src/Broadcasting/PendingBroadcast.php index 53196026..c326bfef 100644 --- a/src/Broadcasting/PendingBroadcast.php +++ b/src/Broadcasting/PendingBroadcast.php @@ -70,7 +70,7 @@ class PendingBroadcast */ protected array $deferredCancelCallbacks = []; - public function __construct(array $channels, string $action, Rendering $rendering, string $target = null, string $targets = null, array $attributes = []) + public function __construct(array $channels, string $action, Rendering $rendering, ?string $target = null, ?string $targets = null, array $attributes = []) { $this->action = $action; $this->target = $target; diff --git a/src/Broadcasting/Rendering.php b/src/Broadcasting/Rendering.php index 8c489278..691e8ecb 100644 --- a/src/Broadcasting/Rendering.php +++ b/src/Broadcasting/Rendering.php @@ -17,7 +17,7 @@ class Rendering public bool $escapeInlineContent = true; - public function __construct(string $partial = null, ?array $data = [], string $inlineContent = null, ?bool $escapeInlineContent = true) + public function __construct(?string $partial = null, ?array $data = [], ?string $inlineContent = null, ?bool $escapeInlineContent = true) { $this->partial = $partial; $this->data = $data; diff --git a/src/Events/TurboStreamBroadcast.php b/src/Events/TurboStreamBroadcast.php index 8da29bd6..75011a7f 100644 --- a/src/Events/TurboStreamBroadcast.php +++ b/src/Events/TurboStreamBroadcast.php @@ -31,7 +31,7 @@ class TurboStreamBroadcast implements ShouldBroadcastNow public bool $escapeInlineContent = true; - public function __construct(array $channels, string $action, string $target = null, string $targets = null, string $partial = null, ?array $partialData = [], string $inlineContent = null, bool $escapeInlineContent = true, array $attributes = []) + public function __construct(array $channels, string $action, ?string $target = null, ?string $targets = null, ?string $partial = null, ?array $partialData = [], ?string $inlineContent = null, bool $escapeInlineContent = true, array $attributes = []) { $this->channels = $channels; $this->action = $action; diff --git a/src/Http/Middleware/TurboMiddleware.php b/src/Http/Middleware/TurboMiddleware.php index 5c766794..66cbd92e 100644 --- a/src/Http/Middleware/TurboMiddleware.php +++ b/src/Http/Middleware/TurboMiddleware.php @@ -151,7 +151,7 @@ private function turboVisit($request) /** * @param \Illuminate\Http\Request $request */ - private function guessFormRedirectUrl($request, string $defaultRedirectUrl = null) + private function guessFormRedirectUrl($request, ?string $defaultRedirectUrl = null) { if ($this->inExceptArray($request)) { return $defaultRedirectUrl; diff --git a/src/Http/PendingTurboStreamResponse.php b/src/Http/PendingTurboStreamResponse.php index 6ab4404f..167ac3ed 100644 --- a/src/Http/PendingTurboStreamResponse.php +++ b/src/Http/PendingTurboStreamResponse.php @@ -35,7 +35,7 @@ class PendingTurboStreamResponse implements Htmlable, Renderable, Responsable private array $useCustomAttributes = []; - public static function forModel(Model $model, string $action = null): self + public static function forModel(Model $model, ?string $action = null): self { $builder = new self(); @@ -242,7 +242,7 @@ public function refresh(): self ->attributes(array_filter(['request-id' => Turbo::currentRequestId()])); } - private function buildAction(string $action, Model|string $target = null, $content = null, Rendering $rendering = null, array $attributes = []) + private function buildAction(string $action, Model|string|null $target = null, $content = null, ?Rendering $rendering = null, array $attributes = []) { $this->useAction = $action; $this->useTarget = $target instanceof Model ? $this->resolveTargetFor($target) : $target; @@ -265,7 +265,7 @@ private function buildActionAll(string $action, Model|string $targets, $content return $this; } - public function broadcastTo($channel, callable $callback = null) + public function broadcastTo($channel, ?callable $callback = null) { $callback = $callback ?? function () { }; @@ -275,7 +275,7 @@ public function broadcastTo($channel, callable $callback = null) }); } - public function broadcastToPrivateChannel($channel, callable $callback = null) + public function broadcastToPrivateChannel($channel, ?callable $callback = null) { $callback = $callback ?? function () { }; @@ -286,7 +286,7 @@ public function broadcastToPrivateChannel($channel, callable $callback = null) }); } - public function broadcastToPresenceChannel($channel, callable $callback = null) + public function broadcastToPresenceChannel($channel, ?callable $callback = null) { $callback = $callback ?? function () { }; diff --git a/src/Jobs/BroadcastAction.php b/src/Jobs/BroadcastAction.php index 31153cc0..135f8f59 100644 --- a/src/Jobs/BroadcastAction.php +++ b/src/Jobs/BroadcastAction.php @@ -32,7 +32,7 @@ class BroadcastAction implements ShouldQueue public ?string $socket = null; - public function __construct(array $channels, string $action, string $target = null, string $targets = null, string $partial = null, ?array $partialData = [], string $inlineContent = null, bool $escapeInlineContent = true, array $attributes = [], $socket = null) + public function __construct(array $channels, string $action, ?string $target = null, ?string $targets = null, ?string $partial = null, ?array $partialData = [], ?string $inlineContent = null, bool $escapeInlineContent = true, array $attributes = [], $socket = null) { $this->channels = $channels; $this->action = $action; diff --git a/src/Models/Broadcasts.php b/src/Models/Broadcasts.php index 3a047720..a375e72c 100644 --- a/src/Models/Broadcasts.php +++ b/src/Models/Broadcasts.php @@ -170,7 +170,7 @@ public function asTurboStreamBroadcastingChannel() return $this->toChannels(Collection::wrap($this->broadcastDefaultStreamables($this->wasRecentlyCreated))); } - protected function broadcastActionTo($streamables, string $action, Rendering $rendering, string $target = null): PendingBroadcast + protected function broadcastActionTo($streamables, string $action, Rendering $rendering, ?string $target = null): PendingBroadcast { return TurboStream::broadcastAction( action: $action, diff --git a/src/Testing/AssertableTurboStream.php b/src/Testing/AssertableTurboStream.php index 7ee63b5e..7268d034 100644 --- a/src/Testing/AssertableTurboStream.php +++ b/src/Testing/AssertableTurboStream.php @@ -23,7 +23,7 @@ public function has(int $expectedTurboStreamsCount): self return $this; } - public function hasTurboStream(Closure $callback = null): self + public function hasTurboStream(?Closure $callback = null): self { $callback ??= fn ($matcher) => $matcher; $attrs = collect(); diff --git a/src/Testing/TurboStreamMatcher.php b/src/Testing/TurboStreamMatcher.php index b425dba6..f7db2657 100644 --- a/src/Testing/TurboStreamMatcher.php +++ b/src/Testing/TurboStreamMatcher.php @@ -47,7 +47,7 @@ public function see(string $content): self return $matcher; } - public function matches(Closure $callback = null): bool + public function matches(?Closure $callback = null): bool { // We first pass the current instance to the callback given in the // `->assertTurboStream(fn)` call. This is where the `->where()` diff --git a/src/TurboServiceProvider.php b/src/TurboServiceProvider.php index 10e377d9..1606124e 100644 --- a/src/TurboServiceProvider.php +++ b/src/TurboServiceProvider.php @@ -12,7 +12,6 @@ use HotwiredLaravel\TurboLaravel\Http\PendingTurboStreamResponse; use HotwiredLaravel\TurboLaravel\Testing\AssertableTurboStream; use HotwiredLaravel\TurboLaravel\Testing\ConvertTestResponseToTurboStreamCollection; -use HotwiredLaravel\TurboLaravel\Views\Components as ViewComponents; use Illuminate\Contracts\Http\Kernel; use Illuminate\Contracts\Routing\ResponseFactory; use Illuminate\Http\Request; @@ -112,7 +111,7 @@ private function configureMacros(): void private function configureRequestAndResponseMacros(): void { - ResponseFacade::macro('turboStream', function ($model = null, string $action = null): MultiplePendingTurboStreamResponse|PendingTurboStreamResponse { + ResponseFacade::macro('turboStream', function ($model = null, ?string $action = null): MultiplePendingTurboStreamResponse|PendingTurboStreamResponse { return turbo_stream($model, $action); }); @@ -132,7 +131,7 @@ private function configureRequestAndResponseMacros(): void return TurboFacade::isTurboNativeVisit(); }); - Request::macro('wasFromTurboFrame', function (string $frame = null): bool { + Request::macro('wasFromTurboFrame', function (?string $frame = null): bool { if (! $frame) { return $this->hasHeader('Turbo-Frame'); } @@ -147,7 +146,7 @@ private function configureTestResponseMacros() return; } - TestResponse::macro('assertTurboStream', function (callable $callback = null) { + TestResponse::macro('assertTurboStream', function (?callable $callback = null) { Assert::assertStringContainsString( Turbo::TURBO_STREAM_FORMAT, $this->headers->get('Content-Type'), diff --git a/src/Views/RecordIdentifier.php b/src/Views/RecordIdentifier.php index dd209f9e..6444d149 100644 --- a/src/Views/RecordIdentifier.php +++ b/src/Views/RecordIdentifier.php @@ -24,7 +24,7 @@ public function __construct(object $record) $this->record = $record; } - public function domId(string $prefix = null): string + public function domId(?string $prefix = null): string { if ($recordId = $this->record->getKey()) { return sprintf('%s%s%s', $this->domClass($prefix), self::DELIMITER, $recordId); @@ -33,7 +33,7 @@ public function domId(string $prefix = null): string return $this->domClass($prefix ?: static::NEW_PREFIX); } - public function domClass(string $prefix = null): string + public function domClass(?string $prefix = null): string { $singular = Name::forModel($this->record)->singular; $delimiter = static::DELIMITER; diff --git a/src/globals.php b/src/globals.php index c024014d..399cae52 100644 --- a/src/globals.php +++ b/src/globals.php @@ -39,7 +39,7 @@ function dom_class(object $model, string $prefix = ''): string * @param Model|Collection|array|string|null $model = null * @param string|null $action = null */ - function turbo_stream($model = null, string $action = null): MultiplePendingTurboStreamResponse|PendingTurboStreamResponse + function turbo_stream($model = null, ?string $action = null): MultiplePendingTurboStreamResponse|PendingTurboStreamResponse { return base_turbo_stream($model, $action); } diff --git a/src/helpers.php b/src/helpers.php index c320ac53..e876dc14 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -39,7 +39,7 @@ function dom_class(object $model, string $prefix = ''): string * @param Model|Collection|array|string|null $model = null * @param string|null $action = null */ - function turbo_stream($model = null, string $action = null): MultiplePendingTurboStreamResponse|PendingTurboStreamResponse + function turbo_stream($model = null, ?string $action = null): MultiplePendingTurboStreamResponse|PendingTurboStreamResponse { if (is_array($model) || $model instanceof Collection) { return MultiplePendingTurboStreamResponse::forStreams($model);