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

Conversation

phil-davis
Copy link
Contributor

mostly be better at declaring the various arrays of Promises, associated callables, exceptions etc.

Comment on lines +191 to +197
// 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');
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.

Copy link

codecov bot commented Nov 15, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (dde9f96) 99.73% compared to head (ac6adaf) 99.21%.

Files Patch % Lines
lib/Promise.php 66.66% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #113      +/-   ##
============================================
- Coverage     99.73%   99.21%   -0.53%     
- Complexity      109      111       +2     
============================================
  Files             7        7              
  Lines           376      380       +4     
============================================
+ Hits            375      377       +2     
- Misses            1        3       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +259 to +263
if ($this->value instanceof \Throwable) {
$subPromise->reject($this->value);
} else {
throw new \LogicException('The subPromise was not fulfilled but no exception was specified');
}
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.

Copy link
Member

@staabm staabm left a comment

Choose a reason for hiding this comment

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

lgtm

@@ -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 phil-davis merged commit aa6bff1 into sabre-io:master Nov 15, 2023
4 of 6 checks passed
@phil-davis phil-davis deleted the phpstan-level-9 branch November 15, 2023 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants