Skip to content

Commit 4e39739

Browse files
committed
Fix phpstan errors in events package
- Update CallQueuedListener data PHPDoc to allow string|array - Use bind() instead of singleton() in EventServiceProvider - Add queue() method to Broadcasting Factory contract - Add phpstan ignore for false positive in defer()
1 parent ddb89f5 commit 4e39739

4 files changed

Lines changed: 15 additions & 5 deletions

File tree

src/contracts/src/Broadcasting/Factory.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@ interface Factory
1010
* Get a broadcaster implementation by name.
1111
*/
1212
public function connection(?string $name = null): Broadcaster;
13+
14+
/**
15+
* Queue the given event for broadcast.
16+
*/
17+
public function queue(mixed $event): void;
1318
}

src/events/src/CallQueuedListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class CallQueuedListener implements ShouldQueue
3333
/**
3434
* The data to be passed to the listener.
3535
*
36-
* @var array
36+
* @var array|string
3737
*/
3838
public $data;
3939

src/events/src/Dispatcher.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,17 @@ class Dispatcher implements DispatcherContract
6060

6161
/**
6262
* The queue resolver instance.
63+
*
64+
* @var (callable(): mixed)|null
6365
*/
64-
protected ?callable $queueResolver = null;
66+
protected $queueResolver = null;
6567

6668
/**
6769
* The database transaction manager resolver instance.
70+
*
71+
* @var (callable(): mixed)|null
6872
*/
69-
protected ?callable $transactionManagerResolver = null;
73+
protected $transactionManagerResolver = null;
7074

7175
/**
7276
* The currently deferred events.
@@ -90,7 +94,7 @@ class Dispatcher implements DispatcherContract
9094
*/
9195
public function __construct(?ContainerContract $container = null)
9296
{
93-
$this->container = $container ?: new Container;
97+
$this->container = $container ?? Container::getInstance();
9498
}
9599

96100
/**
@@ -727,6 +731,7 @@ public function defer(callable $callback, ?array $events = null): mixed
727731

728732
$this->deferringEvents = false;
729733

734+
/** @phpstan-ignore foreach.emptyArray (callback may add deferred events) */
730735
foreach ($this->deferredEvents as $args) {
731736
$this->dispatch(...$args);
732737
}

src/events/src/EventServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class EventServiceProvider extends ServiceProvider
1515
*/
1616
public function register(): void
1717
{
18-
$this->app->singleton('events', function ($app) {
18+
$this->app->bind('events', function ($app) {
1919
return (new Dispatcher($app))->setQueueResolver(function () use ($app) {
2020
return $app->get(QueueFactoryContract::class);
2121
})->setTransactionManagerResolver(function () use ($app) {

0 commit comments

Comments
 (0)