Skip to content
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

Squiz.Commenting.FunctionComment.MissingReturn @inheritDoc not resolved? #2770

Closed
kwhat opened this issue Dec 17, 2019 · 13 comments · May be fixed by #3533
Closed

Squiz.Commenting.FunctionComment.MissingReturn @inheritDoc not resolved? #2770

kwhat opened this issue Dec 17, 2019 · 13 comments · May be fixed by #3533

Comments

@kwhat
Copy link

kwhat commented Dec 17, 2019

Hi,

I have @inheritDoc as the docblock to one of my inherited methods. The parent method is documented correctly, however, Squiz.Commenting does not appear to inherit the doc-block.

    /**
     * @inheritDoc
     */
    public function __toString(): string { /* Child Class */ }
    /**
     * @throws DatabaseException
     *
     * @return string
     */
    public function __toString(): string { /* Parent Class */ }
----------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 1 LINE
----------------------------------------------------------------------
 31 | ERROR | Missing @return tag in function comment
    |       | (Squiz.Commenting.FunctionComment.MissingReturn)
 31 | ERROR | Missing @throws tag in function comment
    |       | (Squiz.Commenting.FunctionCommentThrowTag.Missing)
----------------------------------------------------------------------
@kwhat
Copy link
Author

kwhat commented Dec 17, 2019

Tested with {@inheritdoc} and {@inheritDoc}; possible regression of #214

@kwhat
Copy link
Author

kwhat commented Dec 17, 2019

Never mind, you learn something new every day.

@kwhat kwhat closed this as completed Dec 17, 2019
@bkdotcom
Copy link
Contributor

Not sure why this was closed. There's currently no open issue regarding inheritdoc

Seems like like if the sniff had a $skipIfInheritdoc (default false) option, everyone would be happy

$skipIfInheritdoc would address the common use case

    /**
     * {@inheritdoc}
     */

@kwhat
Copy link
Author

kwhat commented Jan 30, 2020

I closed this issue after reading the PHP doc documentation, CS works according to the specification as it currently is. @inheritdoc is only for the title and description.

@bkdotcom
Copy link
Contributor

bkdotcom commented Jan 30, 2020

https://docs.phpdoc.org/latest/guides/inheritance.html

However, it does make clear that an element has been explicitly documented (and thus not forgotten). As such we are working to include a new (normal) tag in the PHPDoc Standard @inheritdoc that will serve that purpose.

8 years have passed...

That may be the "official" specification, but the community has adopted it to include the the entire parent comment if the comment consists only of @inheritdoc

a non-exhaustive list of IDEs / frameworks / projects that use it for this purpose

@filips123
Copy link
Contributor

filips123 commented Jul 21, 2020

Can this be reopened and supported? Basically any documentation builder (including phpDocumentor), framework and modern IDE supports @inheritDoc and {@inheritDoc}. It feels really unnececary to duplicate all docblocks if they are already documented in parent, requiring more maintaince and possibly causing outdated definitions or even more problems.

It would be nice if PHPCS could actually detect if all parent's parameters are correct or not and also reflect than on children, but option to just ignore detection of missing/incomplite tags (but not other docblock detections) if @inheritDoc is present in docblock would also probably be ok.

Also, maybe a bit newer standard is PSR-19 draft which specified:

In addition to the inherited descriptions and tags as defined in this chapter's root, a function or method in a class or interface MUST inherit the following tags:

  • @param
  • @return
  • @throws

@xjm
Copy link
Contributor

xjm commented Aug 12, 2020

A $skipIfInheritdoc option seems like a great solution to this, given that this feature request has been made over and over for years on various docblock-related sniffs.

@kwhat kwhat reopened this Aug 12, 2020
@kwhat
Copy link
Author

kwhat commented Aug 12, 2020

Reopened the issue for clarification from devs.

@xjm
Copy link
Contributor

xjm commented Aug 12, 2020

#3051 solves this for me locally. Example usage for testing:

    <rule ref="Squiz.Commenting.FunctionComment">                               
        <properties>
            <property name="skipIfInheritdoc" value="true"/>
        </properties>
    </rule>

@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation Jan 18, 2021
@gsherwood gsherwood added this to the 3.6.0 milestone Jan 18, 2021
gsherwood added a commit that referenced this issue Jan 19, 2021
gsherwood added a commit that referenced this issue Jan 19, 2021
@gsherwood
Copy link
Member

This has now been resolved by the sniff property added in #3051, and documented here: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Customisable-Sniff-Properties#squizcommentingfunctioncomment

PHPCS v3 Development automation moved this from Idea Bank to Ready for Release Jan 19, 2021
@XedinUnknown
Copy link

XedinUnknown commented Mar 12, 2021

Not working for me. Even with skipIfInheritDoc still reports Squiz.Commenting.FunctionComment.MissingParamTag.

XedinUnknown added a commit to XedinUnknown/woocommerce-paypal-payments that referenced this issue Mar 15, 2021
It should not be raised in this case, because the methods who are "missing" docs are declared with `@inheritDoc`. See squizlabs/PHP_CodeSniffer#2770 (comment)
@gsherwood
Copy link
Member

Not working for me. Even with skipIfInheritDoc still reports Squiz.Commenting.FunctionComment.MissingParamTag.

This new option is unreleased and not available in 3.5.8. This will become available when 3.6.0 is released.

@XedinUnknown
Copy link

Oh! I just assumed there'd be a releaase since mid-january this year. What about making a beta release with this? :)

PavelSavushkinMix added a commit to PavelSavushkinMix/PHP_CodeSniffer that referenced this issue Jan 17, 2022


It's supported to use {@inheritdoc}. Add a support of @inheritdoc (w/ brackets).
Original PR number - squizlabs#3051

Closes squizlabs#2770
PavelSavushkinMix added a commit to PavelSavushkinMix/PHP_CodeSniffer that referenced this issue Jan 17, 2022


It's supported to use {@inheritdoc}. Add support of @inheritdoc (w/o brackets).
Original PR number - squizlabs#3051

Closes squizlabs#2770
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
PHPCS v3 Development
Ready for Release
6 participants