Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
This is a part of the attempt to fix #2572645: [Meta] Fix 'Drupal.Commenting.FunctionComment' coding standard
This issue is created to tackle the sub-sniffs
Drupal.Commenting.FunctionComment.IncorrectTypeHint
Drupal.Commenting.FunctionComment.InvalidTypeHint
Comment | File | Size | Author |
---|---|---|---|
#75 | interdiff_71_75.txt | 601 bytes | anmolgoyal74 |
#75 | 2723621-75.patch | 25.46 KB | anmolgoyal74 |
#71 | 2723621-71.patch | 25.51 KB | longwave |
Comments
Comment #2
anoopjohn CreditAttribution: anoopjohn at Zyxware Technologies commentedPlease find attached a patch for the same.
Comment #3
Mile23I'm pretty sure all of these hook type hints should be in
use
statements at the top of the file. It might be a different standard for .api.php files, but I doubt it.The rest looks pretty OK but I didn't try too hard after finding the above.
Comment #4
anoopjohn CreditAttribution: anoopjohn at Zyxware Technologies commentedThere is another sniff for catching the use statement instead of the fully qualified class name. We can address the use issue there right? Most of the fixes in the patch only involved the addition of the first namespace separator in front of the fully qualified class name.
Can you please clarify as to what should be documented?
Comment #5
anoopjohn CreditAttribution: anoopjohn at Zyxware Technologies commentedComment #6
dawehnerThere is actually a standard on .api.php pages, indeed. I cannot find an official bit in https://www.drupal.org/node/1354#hooks but could read
like that.
Let's make that FQCN, so with the namespace
Comment #7
Mile23I guess it's much easier to read in the context of an API code example than looking for the use statement.
Comment #8
dawehnerYes, that is a good point.
Comment #9
Mile23Patch in #2 no longer applies.
Comment #10
kostyashupenkoautomerged
Comment #14
empesan CreditAttribution: empesan commentedPatch rerolled against 8.4.x
Comment #15
empesan CreditAttribution: empesan commentedComment #16
hgunicamp CreditAttribution: hgunicamp at CI&T commentedI applied the 'fix-2723621-14.patch' patch and it failed in 'core/phpcs.xml.dist' file.
cit008490cpsubuntu:drupal progestag* 8.4.x$ cat core/phpcs.xml.dist.rej
Comment #17
hgunicamp CreditAttribution: hgunicamp at CI&T commentedI fixed the problem I found in the 'fix-2723621-14.patch' patch and posted a new one. ( 'fix-2723621-16.patch')
Comment #18
dawehnerIs there a reason we don't use a fully qualified class name (FQCN)?
Comment #20
mfernea CreditAttribution: mfernea at AmeXio commentedI added the "coding standards" tag.
Comment #21
mfernea CreditAttribution: mfernea at AmeXio commentedHere is the new patch. There were some new errors and I also fixed the issues mentioned at #18.
Comment #23
mfernea CreditAttribution: mfernea at AmeXio commentedRe-roll.
Comment #25
mfernea CreditAttribution: mfernea at AmeXio commentedComment #26
mfernea CreditAttribution: mfernea at AmeXio commentedRe-roll.
Comment #27
martin107 CreditAttribution: martin107 as a volunteer commentedAll these changes look justifiable to me.
Looking at the lats testbot report ... I can see no last minute errors have crept in.
In short, I think this patch looks great .. and we should get this in..
Comment #28
Mile23'object' is correct.
https://www.drupal.org/docs/develop/coding-standards/api-documentation-a...
Does coder disagree?
Comment #29
mfernea CreditAttribution: mfernea at AmeXio commented_drupal_rewrite_settings_dump_one() is defined as:
function _drupal_rewrite_settings_dump_one(\stdClass $variable, $prefix = '', $suffix = '')
and so PHPCS complains about:
@param object $variable
@param \stdClass
is used in other places too.Comment #30
Mile23The coding standard says use object and not stdClass: https://www.drupal.org/docs/develop/coding-standards/api-documentation-a...
Also needs a re-roll.
If Coder adds stdClass then it's wrong. If there's not a sniff for object vs. stdClass then there should be. In either (or both) of those cases we should file an issue against Coder.
Comment #31
mfernea CreditAttribution: mfernea at AmeXio commentedComment #32
mfernea CreditAttribution: mfernea at AmeXio commentedHere is the updated patch and the interdiff.
The interdiff contains removal of phpcs.local.xml which was present at #26 and shouldn't have been part of the patch.
Comment #33
mfernea CreditAttribution: mfernea at AmeXio commented@Mile23 I guess we should also open a follow-up for other places where \stdClass is used as a typehint. Should we fix them here? Gray area between in and out of scope :). What do you think?
I opened #2911404: Drupal.Commenting.FunctionComment.InvalidTypeHint/FunctionComment - \stdClass for the
stdClass
vs\stdClass
issue.Comment #34
joshmillerChecked to see if patch applies, and it does, pretty cleanly (no errors). Not enough time to test to see if the phpcs is now passing.
Hopefully this comment encourages another to run the tests.
Comment #35
neclimdulFriendly post #2902381: Revert phpcs.xml.dist changes from "Ensure that we're using the right ruleset for coding standards checking" reroll.
No credit needed.
Comment #36
suraj2012 CreditAttribution: suraj2012 as a volunteer and at Valuebound commentedChecked the patch "drupal-coding-standards-2723621-35.patch" .
It applies cleanly. I also ran the phpcs test after that and there were no errors.
Comment #37
Mile23The patch is still mostly fine, but it does the above. We shouldn't remove a valid type hint.
Reverting that file and then sniffing it yields this:
Changing the hint to
stdClass
(no\
) gets a pass from phpcs. I suppose that's because it's in an.inc
file which is in the top-level namespace. InvalidTypeHint doesn't seem to care about that namespace \ in other usages, such as within a namespaced class. So InvalidTypeHint doesn't seem to be at 100% #2911404: Drupal.Commenting.FunctionComment.InvalidTypeHint/FunctionComment - \stdClassIf we add back
stdClass
(instead of\stdClass
), then this patch will be ready to go. If the sniff ever gets fixed, and it turns outstdClass
is not right, then it will show up and we can fix it then.Comment #38
Mile23Comment #39
snehi CreditAttribution: snehi as a volunteer and at Publicis Sapient for Publicis Sapient commentedGiven it a try.
Comment #40
Mile23This addresses the issues from #37 and PHPCS is happy. :-)
Comment #41
neclimdulWhy wouldn't we use the interface? Does the method signature need to be fixed instead?
Comment #43
idebr CreditAttribution: idebr at ezCompany commented#41 I agree with ideally this would type hint the MenuLinkContentInterface. However, if you look at the MenuUiTest.php file, all other methods typehint the MenuLinkContent. Considering this issue is about bring the type hint in line with the actual code, I suggest we go with the smallest change possible and update the documentation to match the code here and leave the change in the actual code to a follow up.
The MenuUiTest was moved in #2723621: Fix Drupal.Commenting.FunctionComment.IncorrectTypeHint and Drupal.Commenting.FunctionComment.InvalidTypeHint, so the patch no longer applies.
Comment #44
jofitz CreditAttribution: jofitz at ComputerMinds commentedRe-rolled.
Comment #45
Mile23Patch still applies, but I see this:
Comment #46
jofitz CreditAttribution: jofitz at ComputerMinds commentedCorrected the 3 errors.
Comment #48
idebr CreditAttribution: idebr at ezCompany commentedThis line is changed the wrong way around. The @param should mention \SimpleXMLElement (mind the capitals). The current method argument in HEAD is correct.
Comment #49
jofitz CreditAttribution: jofitz at ComputerMinds commentedCorrected my incorrect correction!
Thanks @idebr.
Comment #51
idebr CreditAttribution: idebr at iO commentedDrupalCI reports 4 additional incorrect typehints at the latest build: https://www.drupal.org/pift-ci-job/1017856
These were added recently in #2975754: Add hooks to act on a new revision being created
/var/lib/drupalci/workspace/jenkins-drupal_patches-65188/source/core/lib/Drupal/Core/Entity/entity.api.php
line 930 Expected type hint "EntityInterface"; found "Drupal\Core\Entity\EntityInterface" for $new_revision
930 Expected type hint "EntityInterface"; found "Drupal\Core\Entity\EntityInterface" for $entity
954 Expected type hint "EntityInterface"; found "Drupal\Core\Entity\EntityInterface" for $new_revision
954 Expected type hint "EntityInterface"; found "Drupal\Core\Entity\EntityInterface" for $entity
Comment #52
Mile23This calls back to #6.
So I think we need clarity on whether .api pages should have fully-qualified class names in hints or not, and make sure there's a coder rule for it.
Comment #53
jofitz CreditAttribution: jofitz at ComputerMinds commentedCorrected the 4 coding standards errors.
Comment #54
Mile23Ahh the slashes. :-)
LGTM, and the CI, so yay.
Comment #55
alexpottThis change is really odd. Imo we shouldn't be making it. The whole coding standard of object vs stdClass for any old object makes sense in every cases apart from this one where the thing is a
\stdClass
. That said maybe the gains of the patch outweigh this one awkwardness and we can address it more properly in the follow-up. Imo coder should be fixed as per @Mile23's comment on #2911404: Drupal.Commenting.FunctionComment.InvalidTypeHint/FunctionComment - \stdClass. Maybe we should postpone on that - dunno.Comment #56
Mile23Okie.
Comment #59
alexpottComment #60
alexpottHere we go... the blocker went in ages ago.
Comment #62
alexpottToo many DateFormatInterface classes :)
Comment #63
xjmTurning on new coding standards a minor-only change (although we can backport the cleanups without the rule in some cases to preserve cherry-picks). Since this is just docs, it's backportable; however, the backport patch would need to have a version that does not include the
phpcs.xml.dist
change.Comment #65
longwaveNeeds a reroll.
Comment #66
ankithashettyRe-rolled the patch in #62. Thanks!
Comment #67
Suresh Prabhu Parkala CreditAttribution: Suresh Prabhu Parkala at Specbee commentedUpdated patch. Please review!
Comment #68
daffie CreditAttribution: daffie commentedCan we not add this line and keep the long format. This is an example file for other developers.
Comment #69
abhisekmazumdarFor some reason the last two patches are getting applied. So I have excluded the changes done on
core/lib/Drupal/Core/Entity/entity.api.php
as per the suggestion on #68.Kindly review the patch.
Comment #70
abhisekmazumdarOops !!
Updated the patch.
Comment #71
longwaveFixed the reroll, addressed three other issues found by running phpcs.
Comment #72
daffie CreditAttribution: daffie commentedAll code changes look good to me.
I have run PHPCS on my local machine and with the patch applied there are no errors.
For me is it RTBC.
I was wondering if we should create a followup to fix:
Comment #73
catchWould be good to have a follow-up for #72. I also I think we should leave the assert() out of the 9.1.x backport (along with the hunk that enables the drupalcs checks).
Comment #74
alexpottThis should remove the @param doc entirely. Having {inheritdoc} and a single @param override breaks api.drupal.org - see https://api.drupal.org/api/drupal/core%21modules%21system%21src%21Plugin...
This method has three params but only one is documented.
If we want to change one param we have to provide a full docblock.
Comment #75
anmolgoyal74 CreditAttribution: anmolgoyal74 at OpenSense Labs for DrupalFit commentedRemoved the @param doc.
We can handle #72 in a follow-up.
Comment #76
longwaveComment #77
alexpottCommitted 203ad06 and pushed to 9.2.x. Thanks!
The patch doesn't apply to 9.1.x so fixing only in 9.2.x.