-
Notifications
You must be signed in to change notification settings - Fork 46
Add native typhints to all hamcrest classes (+ install phpstan) #88
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
Conversation
@@ -15,8 +15,13 @@ | |||
|
|||
class IsArrayContainingKeyValuePair extends TypeSafeMatcher | |||
{ | |||
|
|||
/** | |||
* @var mixed $_keyMatcher |
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.
If possible please use actually used type/types here and other DocBlocks.
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.
mixed
only got a native typehint in php 8.0.
PHP 7.4:
/**
* @var mixed $_keyMatcher
*/
private $_keyMatcher;
and have to use docblocks for this.
PHP 8.x:
private mixed $_keyMatcher;
Idk if you were following the PHP update discussion, I think version 3.0 with typehints could have a minimum version of PHP 8.0 if it would be my library.
https://www.youtube.com/watch?v=iVaSGD2fCXU
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.
Oh sorry, I think I understood your comment only now.
Fixing..
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've meant use @var string|integer|etc $_keyMatcher
instead of @var mixed $_keyMatcher
in DocBlocks only. Hopefully that would make PHPStan happier.
Thanks for the review! So got a few questions now
I will:
I could:
|
Actually, never mind about the mixing FQNS and not. I understood it now! Because the generator doesn't support imports/use statements, so this one needs to be FQDNs, because it will be taken for code generation ✅ |
I personally prefer to import everything, but this change should be done in a separate PR.
No.
Throw an exception probably or use an
Sure. Please do this.
OK.
If you'd like (in separate PR) we can teach generator to understand imports. |
No need to review, unless I request a review, because this will make things even more complicated I think |
Hey, I did prioritize some other Open Source work before getting back to this. To not have to leave this open for months, I would suggest to accept a non-empty phpstan baseline and start the journey of typed code with a little bit of legacy code. This is the way to at least not create new issues while the repository lives on. Let me know what you would prefer. |
My apologies. I'll wait for time, when you request a review then.
Then please do this:
|
Mhh. Maybe we missunderstood.
I was suggesting to not do this (now). |
Then create a task(s) explaining the idea behind each of the issues hidden in the PHPStan baseline and how it is supposed to be fixed in the future. This way we won't lose the fact that something needs to be fixed after this PR is merged. |
…urrent working directory instead of in tests
943886f
to
cbdee96
Compare
Created and linked all three issues from the latest phpstan run without the baseline - they stayed the same. Resolved the conflicts with upstream (was just the re-generation of the generated files) |
composer.json
Outdated
"phpunit/phpunit": "^4.8.36 || ^5.7 || ^6.5 || ^7.0 || ^8.0 || ^9.0", | ||
"phpstan/phpstan": "^2.1", | ||
"phpstan/phpstan-phpunit": "^2.0", | ||
"symfony/var-dumper": "^5.4" |
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.
Why the symfony/var-dumper
is needed?
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.
sorry, my mistake. I removed it
I recommend adding a GitHub Action job to run the PHPStan automatically. Example: https://github.com/minkphp/driver-testsuite/blob/master/.github/workflows/ci.yml . |
@aik099 yep, I recommend that, too ;) You have to do this in a separate PR. Honestly this is a bit hard to do as a contributor without the checks running automatically |
Since PhpStan is added in this PR, then GitHub Action changes related to it should be here as well. |
Added the config |
ah, now the checks ran directly, didn't notice it the first time. Well then i was wrong: this was easy |
pull_request: | ||
|
||
jobs: | ||
static_analysis: |
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.
Please do this:
- move this job into an existing YML file instead of adding a new one
- for an existing YML file:
- rename into
ci.yml
- replace
name: tests
withname: ci
- replace
name: PHP ${{ matrix.php }}
intoname: Tests ${{ matrix.php }}
- rename into
This way we'll have all CI runs in one place. Right now I have to jump through the hooks to see static analysis and tests of the same PR on the https://github.com/hamcrest/hamcrest-php/actions page.
Example result: https://github.com/minkphp/Mink/actions/runs/13197030721.
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.
done
Merged. Thank you @pscheit . |
Hey there 👋 ,
I felt so free to PR native typehints for this library. I noticed that most of the Matchers:: and other methods are not type hinted at all, which makes it really difficult to use the library in other typed libraries (e.g. https://github.com/webforge-labs/object-asserter).
However I went through everything in ./hamcrest with the help of phpstan and added typehints where they were missing.
Added the few "real issues" I found into the baseline.
What do you think, would this worth it to create a Version 3 of this library? Because everything I made is highly non backwards compatible, once got was extended by third parties.
For user the library api shouldn't change.
I added phpstan because that way those refactorings are much easier and easier to spot if mistakes are made.
While going through all that found some few other quirks I will address separately - which would even be backwards compatible.
Hope you like it, if not - don't sweat it, since we didnt talk about it before.
Best regards,
Philipp
Btw: you wrote about codestyle in the CONTRIBUTING notes, but couldnt find a guide?