-
Notifications
You must be signed in to change notification settings - Fork 16
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
Train moodle.Commenting.MissingDocblock.Missing to understand #[\Override] #155
Comments
@andrewnicols it occurs to me that when we are giving the warning about missing PHPdoc in a class that extends something else, can we make the fail message include "If this is an overridden method, please add the #[\Override] attribute." or something like that. |
That's exactly what I had in mind. A hard error if neither are provided. |
Was looking to the related PR #160 ... I see that only thing that we are doing is to stop warning when the attribute is added. We aren't going to warn about "duplicate" phpdoc blocks (@ children) neither we are going to warn when both the phpdoc block and the attribute exists. I imagine that's ok, just sharing about it. And, also, sharing about the need to update the devdocs, because:
Ciao :-) |
That's correct and, in my opinion, preferable. There is no (easy) way to determine parentage in phpcs. If we want that kind of thing we need tooling like phpstan or rector.
Again I think that is correct. It is perfectly legitimate for a child class to have its own docs and want to declare that it is an override.
Which example? |
Whops sorry, I forgot to share the link, I was talking about this example, that always hurt my eyes (although, as said, I don't think that we have anything written about the summary & long description for functions): https://moodledev.io/general/development/policies/codingstyle#functions |
For waht it is worth, I think it is a smell to have a comment on an overridden method. (And override should not change the contract for a method that is defined in the base class.) But anyway, that is a dicussion for another day. Awesome that this has now landed. Thank you very much :-) |
Moodle coding style rules say:
Our code-checker rules have never understood this, and always given false-positives.
But, PHP 8.3+ now provides the #[\Override] annotation (See https://tracker.moodle.org/browse/MDL-79901 for discussion of the use of that in Moodle.) And that can safely be used in older PHP without errors.
So, we should teaching moodle.Commenting.MissingDocblock.Missing to use this annotation, and for such methods, give a warning if the comment is present (rather than if it is absent).
The text was updated successfully, but these errors were encountered: