-
Notifications
You must be signed in to change notification settings - Fork 44
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
Better explain the code using actual type hints #38
base: master
Are you sure you want to change the base?
Conversation
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.
These few type hints from docblocks were actually incorrect, but not with large impact. Further all type hints are just moves or small improvements (e.g. array
> Result[]
).
* | ||
* @param string $name | ||
* | ||
* @return mixed |
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.
This mixed
was not really wrong, but overly broad.
* @param \Scientist\Experiment $experiment | ||
* @param \Scientist\Report $report | ||
* | ||
* @return mixed |
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.
This mixed
was actually void
.
* @return Exception|null | ||
*/ | ||
public function getException() | ||
public function getException(): ?\Throwable | ||
{ | ||
return $this->exception; | ||
} | ||
|
||
/** | ||
* Set the exception thrown by the callback. | ||
* | ||
* @param Exception|null $exception | ||
* | ||
* @return $this | ||
*/ | ||
public function setException($exception) | ||
public function setException(?\Throwable $exception): self |
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.
I changed these Exception
to Throwable
, since Machine->executeMutedCallback()
actually catches that, thus it could end up here.
I was trying to figure out what
Report->getTrial()
would return, which was quite difficult since it was hidden deep down. So I felt it would be nice to add type hints to the project.I only added type hints which are compatible with php 7.3, as defined in the composer.json. Further improvements could be made by requiring php 7.4 (to add type hints for class properties) or php 8.0 (to add type hint
mixed
). Both don't feel really important atm. But if we anyway are okay with bumping the required php version, I could start another PR for adding those as well.All tests are green on a php 7.3 docker.