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

Better explain the code using actual type hints #38

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

lode
Copy link

@lode lode commented Dec 20, 2023

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.

Copy link
Author

@lode lode left a 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
Copy link
Author

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
Copy link
Author

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.

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
Copy link
Author

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.

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.

1 participant