- Notifications
You must be signed in to change notification settings - Fork 23
Modernize sniffs & helpers and embrace PHPCSUtils #74
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
tfrommen left a comment
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.
Thanks for refactoring, improving and simplifying this, @gmazzap!
I have two questions that each may pose some massive churn, but still:
- The
Inpsyde\Helpersnamespace is new, right? If yes, can we maybe choose a more specific name, for example,Inpsyde\CSHelpers, orInpsyde\CodingStandardsHelpersor something like that? Just "Helpers" really is too generic, in my opinion. - Why did you decide to use that many Nowdoc blocks in tests, each representing a file-under-test? Can we move the code into actual files, maybe? That would mean that the test code is much slimmer, and one would have (better) IDE-support when writing/editing such files...
Again, thanks! I really like upgrading this to using the now-stable PHPCSUtils package.
Co-authored-by: Thorsten Frommen <info@tfrommen.de> Signed-off-by: Giuseppe Mazzapica <giuseppe.mazzapica@gmail.com>
Agreed. For test we already have Edit: implemented in e3a3488.
I guess you are referring to the helpers' tests. The thing is some tests case have a different Nowdoc blocks per test method, see e.g. https://github.com/inpsyde/php-coding-standards/blob/feature/72-73/tests/cases/Helpers/FunctionDocBlocTest.php That would mean we would need different files per test case, and it would be hard to organize or even name them. Moreover, I think that when the Nowdoc is inside a certain limit, let's say 50 lines or so, it is still "manageable" especially when the IDE can easily "collapse" those blocks. And to me readability is actually better, not worse. Take this example, for a real test case. And imagine it would be written like this: public function testAllTags(): void { $file = $this->factoryFile(getenv('FIXTURES_PATH') . '/helpers/function-docbloc-001.php')); $oneFuncPos = $file->findNext(T_FUNCTION, 1); $twoFuncPos = $file->findNext(T_CLOSURE, $oneFuncPos + 1); $tagsOne = FunctionDocBlock::allTags($file, $oneFuncPos); $tagsTwo = FunctionDocBlock::allTags($file, $twoFuncPos); static::assertSame( [ '@param' => ['?string $foo', 'bool $bool'], '@return' => ['string'], ], $tagsOne ); static::assertSame( [ '@param' => ['string $foo'], '@return' => ['string'], '@custom' => ['Hello World'], '@wp-hook' => [''], ], $tagsTwo ); }The assertions make totally no sense if you don't look at the actual PHP code that is being analyzed, which in this case would require the developer to open another file. |
| Thanks for renaming the Helpers' namespace. 🙏 Regarding the inline Nowdoc PHP code - I guess this comes down to personal preference.
Unit tests require knowledge about the actual implementation details. Just like any other white-box test. In this case, you can structure the test like so, because a part of the subject-under-test is some PHP code that gets analyzed, and that could live in an actual file, or in a string. So if you prefer this, that is fine by me. |
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Bug fix, feature
What is the current behavior? (You can also link to an open issue here)
See #72 and #73
What is the new behavior (if this is a feature change)?
Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
Yes. The old helper class is deleted.
Other information:
Sorry for the big PR. The helpers where all interconnected and used in sniffs, it was hard to refactor one without touching the others.
And then I needed to test the work, so I adjusted the test.
I could have put the license normalization in another PR, but I guess that is the lease of the problems reviewing this PR...