Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase phpstan level to 9 #113

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might even define the callable signatures which can help to identify issues at the caller side (can be a separate PR)

phil-davis marked this conversation as resolved.
Show resolved Hide resolved
*/
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 @@
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
Comment on lines +191 to +197
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

phpstan is confident that "value" will be a Throwable at this point. So I added an extra check, and throw a LogicException if value was not a Throwable. LogicException is already used elsewhere in this code, so I chose to throw that.

}
}

/**
* 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 @@
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
}
Comment on lines +259 to +263
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

phpstan is confident that "value" will be a Throwable at this point. So I added an extra check, and throw a LogicException if value was not a Throwable. LogicException is already used elsewhere in this code, so I chose to throw that.

}
}
});
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