FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Report `@inheritDoc` when there is no PHPDoc to inherit from by kubawerlos · Pull Request #5583 · phpstan/phpstan-src · GitHub

Report @inheritDoc when there is no PHPDoc to inherit from - #5583

Draft
kubawerlos wants to merge 5 commits into
phpstan:2.1.xfrom
6b7562617765726c6f73:invalid-inherit-doc-tag
Draft

Report @inheritDoc when there is no PHPDoc to inherit from#5583
kubawerlos wants to merge 5 commits into
phpstan:2.1.xfrom
6b7562617765726c6f73:invalid-inherit-doc-tag

Conversation

Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown
Contributor

I think we should distinguish two different case

ondrejmirtes left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The correct way to find parent methods is ParentMethodHelper.

Copy link
Copy Markdown
Contributor Author

@VincentLanglet do you mean as separate rules?

Copy link
Copy Markdown
Member

Not a class, but an error identifier for sure.

kubawerlos force-pushed the invalid-inherit-doc-tag branch from bc204fc to fd71add Compare May 2, 2026 13:52
kubawerlos requested a review from ondrejmirtes May 2, 2026 14:09

Copy link
Copy Markdown
Contributor

Hi @kubawerlos could you rebase and solve the conflict ?

continue;
}

if (preg_match(self::INLINE_INHERIT_DOC_REGEX, $child->text, $matches) !== 1) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Can't we do better ?

I know it'll be an edge case but you won't catch description like

/**
 * Please do not add `{@inheritDoc}` to this method
 */

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Like this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'm not very good in regex but looking at the test called InheritDocInsideBackticks i'm not sure we understood each other.

My point was that, we might not want to consider that a method with

/**
 * Foo @inheritDoc
 */ 

has an inheritDoc, cause it might be just a comment.
It wasn't related to backticks

(On the opposite,

/**
 * @inheritDoc Bar
 */ 

might be considered as an inherit doc with an extra comment... ; I dunno)

I never use inheritDoc so I can't stay what we can find in codebase.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Updated test.

@inheritDoc Bar will be tokenised as a tag with extra description.

kubawerlos force-pushed the invalid-inherit-doc-tag branch from fd71add to 00f4776 Compare May 6, 2026 20:45
VincentLanglet requested a review from staabm May 6, 2026 21:06
final class InvalidInheritDocTagRule implements Rule
{

private const INLINE_INHERIT_DOC_REGEX = '~`[^`]*`(*SKIP)(*FAIL)|(?<![a-zA-Z0-9])\{@inheritDoc\b[^}]*\}~i';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

can this regex be simplified because it uses i modifier (case-less), so the pattern itself does not need to handle both upper and lower case things?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

What do you mean? To lowercase $child->text and drop i, or to match only on exact case match?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I mean a-zA-Z does not make sense in a i modfied regex

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

but as commented in the other stream.. I am not convinced this regex is a good idea.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Let's see where phpstan/phpdoc-parser#298 will lead.

break;
}

if ($inheritDocTagName === null) {

staabm May 7, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I am not sure about this additional regex matching on-top of regular phpDoc parsing.
all relevant cases should be detected by the phpdoc parser, if it is doing a good job.

if not we should improve the phpdoc parser IMO

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Definitely, this is not perfect. The limitation is {@inheritDoc} ends up as part of a PhpDocTextNode, not as a tag.

staabm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

take my feedback with a grain of salt. I think this is a gray area which needs @ondrejmirtes opinion.

kubawerlos force-pushed the invalid-inherit-doc-tag branch from cea774c to 11c08cb Compare May 7, 2026 17:06
kubawerlos marked this pull request as draft May 11, 2026 16:09
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL