Skip to content

Commit

Permalink
Increase phpstan level to 9
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-davis committed Nov 15, 2023
1 parent dde9f96 commit ac6adaf
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/EmitterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public function removeAllListeners(string $eventName = null): void
/**
* The list of listeners.
*
* @var array<string, array{0:boolean, 1:array<int, mixed>, 2:array<int, mixed>}>
* @var array<string, array{0:boolean, 1:array<int, mixed>, 2:array<int, callable>}>
*/
protected array $listeners = [];
}
2 changes: 1 addition & 1 deletion lib/Loop/Loop.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ protected function runStreams(?float $timeout): void
/**
* A list of timers, added by setTimeout.
*
* @var array<int, mixed>
* @var array<int, array{0:float, 1:callable}>
*/
protected array $timers = [];

Expand Down
17 changes: 13 additions & 4 deletions lib/Promise.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,21 @@ public function wait()
return $this->value;
} else {
// If we got here, it means that the asynchronous operation
// errored. Therefore we need to throw an exception.
throw $this->value;
// errored. Therefore, we need to throw an exception.
if ($this->value instanceof \Throwable) {
throw $this->value;
}
// The state should have been REJECTED, with "value" a Throwable
// But "value" was not a Throwable. So throw a more general exception.
throw new \LogicException('The Promise was not fulfilled but no exception was specified');

Check warning on line 197 in lib/Promise.php

View check run for this annotation

Codecov / codecov/patch

lib/Promise.php#L197

Added line #L197 was not covered by tests
}
}

/**
* A list of subscribers. Subscribers are the callbacks that want us to let
* them know if the callback was fulfilled or rejected.
*
* @var array<int, mixed>
* @var array<int, array{0:Promise<TReturn>, 1:callable|null, 2:callable|null}>
*/
protected array $subscribers = [];

Expand Down Expand Up @@ -251,7 +256,11 @@ private function invokeCallback(Promise $subPromise, callable $callBack = null):
if (self::FULFILLED === $this->state) {
$subPromise->fulfill($this->value);
} else {
$subPromise->reject($this->value);
if ($this->value instanceof \Throwable) {
$subPromise->reject($this->value);
} else {
throw new \LogicException('The subPromise was not fulfilled but no exception was specified');

Check warning on line 262 in lib/Promise.php

View check run for this annotation

Codecov / codecov/patch

lib/Promise.php#L262

Added line #L262 was not covered by tests
}
}
}
});
Expand Down
6 changes: 3 additions & 3 deletions lib/WildcardEmitterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,14 @@ public function removeAllListeners(string $eventName = null): void
/**
* The list of listeners.
*
* @var array<string, mixed>
* @var array<string, array<int, array{0:int, 1:callable}>>
*/
protected array $listeners = [];

/**
* The list of "wildcard listeners".
*
* @var array<string, mixed>
* @var array<string, array<int, array{0:int, 1:callable}>>
*/
protected array $wildcardListeners = [];

Expand All @@ -233,7 +233,7 @@ public function removeAllListeners(string $eventName = null): void
*
* If the list of listeners changes though, the index clears.
*
* @var array<string, mixed>
* @var array<string, array<int, callable>>
*/
protected array $listenerIndex = [];
}
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 8
level: 9
phpVersion: 70430 # PHP 7.4.30
ignoreErrors:
-
Expand Down

0 comments on commit ac6adaf

Please sign in to comment.