-
Notifications
You must be signed in to change notification settings - Fork 21
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'); | ||
Comment on lines
+191
to
+197
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 = []; | ||
|
||
|
@@ -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'); | ||
} | ||
Comment on lines
+259
to
+263
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
} | ||
}); | ||
|
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: | ||
- | ||
|
There was a problem hiding this comment.
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)