Better explain the code using actual type hints#38
Open
lode wants to merge 6 commits intodaylerees:masterfrom
Open
Better explain the code using actual type hints#38lode wants to merge 6 commits intodaylerees:masterfrom
lode wants to merge 6 commits intodaylerees:masterfrom
Conversation
lode
commented
Dec 20, 2023
Author
lode
left a comment
There was a problem hiding this comment.
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 |
Author
There was a problem hiding this comment.
This mixed was not really wrong, but overly broad.
| * @param \Scientist\Experiment $experiment | ||
| * @param \Scientist\Report $report | ||
| * | ||
| * @return mixed |
Comment on lines
-218
to
+201
| * @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 |
Author
There was a problem hiding this comment.
I changed these Exception to Throwable, since Machine->executeMutedCallback() actually catches that, thus it could end up here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.