Add PHPCS scaffold tool bin/phpcs-scaffold#221
Conversation
Introduce a new PHPCS scaffolding utility to generate a new PHPCS sniff class, along with its unit test, fixtures and documentation files. Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
Restructure the scaffold subsystem and introduce interfaces and implementations. Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
This reverts commit 9f601c4. Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
Refactor tests and fix cs issues Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
Issue with consecutive willReturn values Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
Use DIRECTORY_SEPARATOR for cross-platform compatibility Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
|
I would love some assistance with PHPStan and PHPCS. |
What are you running into which isn't clear ? What sort of help are you looking for ? |
Thanks for asking. The PHPCS issues are clear to me, they’re mainly documentation-related (e.g., "Missing doc comment for class" and "Missing short description in doc comment"). Fixing those would mostly involve adding the required class docblocks, I'll just need to make some time after $dayJob. For PHPStan, I’m not familiar with all the syntax for that tool and I do not plan to learn it at this time. Because of that, I’m not comfortable making changes related to its findings in a codebase that targets PHP >= 5.4. I’d prefer not to suppress the warnings just to make CI pass, and I’m also hesitant to start changing code without knowing the preferred approach for resolving those findings here. If someone more familiar with PHPStan could take a look at those issues, that would be helpful. |
jrfnl
left a comment
There was a problem hiding this comment.
The PHPCS issues are clear to me, they’re mainly documentation-related (e.g., "Missing doc comment for class" and "Missing short description in doc comment"). Fixing those would mostly involve adding the required class docblocks, I'll just need to make some time after $dayJob.
Understood.
For PHPStan, I’m not familiar with all the syntax for that tool and I do not plan to learn it at this time. Because of that, I’m not comfortable making changes related to its findings in a codebase that targets PHP >= 5.4.
I’d prefer not to suppress the warnings just to make CI pass, and I’m also hesitant to start changing code without knowing the preferred approach for resolving those findings here.
If someone more familiar with PHPStan could take a look at those issues, that would be helpful.
Expanding/fixing up the docs should already fix some of the PHPStan issues too.
PHPStan bases a lot of analysis on the information found in docblocks, so if that info is not strictly correct, it will give false positives.
I've left a couple of hints inline for the issues reported by PHPStan.
Note: for type related issues in the tests where the test is verifying that the method under test does not act on an incorrect type, we should ignore the PHPStan issues. The whole point of that type of test is to verify what PHPStan also flags, but having it safeguarded by a test is definitely the better/more stable way to secure the type handling for the future.
Hope this helps a little.
| * @throws ScaffolderException if the path or contents are not valid | ||
| * @throws ScaffolderException if the file cannot be created or written to | ||
| * | ||
| * @return void |
There was a problem hiding this comment.
| * @return void | |
| * @return int|false |
👆🏻 This will remove the PHPStan error you can see for line 177 below 👇🏻
| interface FilesystemInterface | ||
| { | ||
|
|
||
| public function createDirectory($path); |
There was a problem hiding this comment.
Adding a docblock documenting what $path is supposed to be (I suspect @param string $path) and that the method should @return void will fix the two PHPStan warnings for createDirectory().
Same principle for all the other methods.
And for an interface to be meaningful, I'd also prefer that the docblock includes a description of what the method is supposed to do (and probably why).
| /** | ||
| * The directory where the templates are stored. | ||
| * | ||
| * @var non-empty-string |
There was a problem hiding this comment.
This might be a type supported by PHPStan, but is not a true type, so we don't use them in this codebase.
It is also not correct as the property does not have a default value, so will not be a non-empty-string until initialized.
If you want to avoid accounting for that in the @var type declaration, you may want to add a default value of ''.
| * @var non-empty-string | |
| * @var string |
| * @param string $path queried path | ||
| * @param int $flags stat flags | ||
| * | ||
| * @return array |
There was a problem hiding this comment.
| * @return array | |
| * @return array<int|string, int> |
|
@ghostwriter Thanks for opening this PR and for your willingness to contribute! I haven't had a detailed look yet (and won't until you are ready for it and CI passes), but I did have an initial glance and read the PR description. So please keep in mind, this is not a review, just some preliminary questions based on a quick glance.
Also note: it is not strictly necessary for the individual CLI tools to have a PHP 5.4 minimum. It is fine for those to have a PHP 7.2 minimum if that makes things easier (also see discussion notes about this in PR #152). PR #152 and this PR would have some overlap regarding CI changes if you go down that path, so it might be interesting for you to have a look at what's in that PR. Some other random (but more detailed) notes from that first glance:
|
|
@rfnl Hey Juliette,
I understand.
No, not yet. PHPCS itself uses a different file structure. I have an idea for how to support that as well, so I’ll design a fix and update this PR accordingly.
I was trying to be clever. Looking at the file structures used by
You're right. I’m considering adding a
Understood. I’ll improve this.
Thanks for the link. I’ll read it and update the PR accordingly. I wasn’t aware of that. I’ll review the wiki page and the PHP_CodeSniffer codebase to come up with a better solution.
Okay. I’ll add it to the README once I have a better understanding of how to improve the CLI command and the file structure.
PHP 5.4 is fine for me, but I’ll review PR #152 to see if there are useful changes that could apply to this PR.
I’ll take a look.
I used
You're right. I was using a
I can add the necessary workflow changes to upload coverage results to Coveralls, for you to review. However, I don’t have access to the Coveralls account for this repository, so I won’t be able to activate it.
Will do.
I set For example, if If no dependency is declared, PHPUnit will execute tests in random order, which helps detect hidden dependencies between tests. When i was testing the Filesystem i wanted to make sure each test was independent. I will commit your code suggestions, Thank you. |
|
@ghostwriter Thanks for your response. I'll await the next iteration.
I'm not sure that's needed as the namespace should either be the standard name or if it diverges from that, the As I said before, I haven't looked at the code in detail yet, so forgive me if I'm telling you something you already figured out and/or what's already in the current code, but presuming the tool is intended to be run from the root of the project for which someone wants to scaffold a sniff, I imagine you could:
I'm okay with updating the file based on
I've turned it on for this repo, so once the config and workflow steps are in place, things should start working automatically. |
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com> Co-Authored-By: Juliette <663378+jrfnl@users.noreply.github.com>
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
This reverts commit 199c839.
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
Introduce a new PHPCS scaffolding utility to generate a new PHPCS sniff class, along with its unit test, fixtures and documentation files.
vendor/bin/phpcs-scaffold Standard.Category.Sniffeg.
vendor/bin/phpcs-scaffold PHPCSDebug.Debug.TokenListWill generate:
vendor/bin/phpcs-scaffold --helpandbin/phpcs-scaffold -hwill print.Todo:
phpunit.xml.distandphpunitlte9.xml.distfiles.