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

@inheritdoc should be {@inheritdoc} #11635

Closed
michaelarnauts opened this issue May 26, 2016 · 38 comments
Closed

@inheritdoc should be {@inheritdoc} #11635

michaelarnauts opened this issue May 26, 2016 · 38 comments
Assignees
Labels
type:bug Bug type:docs Documentation
Milestone

Comments

@michaelarnauts
Copy link
Contributor

According to the documentation of phpdoc, the @inheritdoc tag to indicate that the function documentation should be copied from the parent function should be written as {@inheritdoc}.

Currently, @inheritdoc is used everywhere in the code of Yii2.

The next version of Netbeans should be able to process these according to this page.

@Faryshta
Copy link
Contributor

i think the use case there is distinct.

/**
 * @inheritdoc
 */
public function method();

will copy the long description, and other tags like params, return, etc.

/**
 * {@inheritdoc}
 * @return string
 */
public function method();

Will copy ONLY the long description, not the rest of the tags which have to be asigned again.

@cebe
Copy link
Member

cebe commented May 26, 2016

The problem with this is, that there is no real spec of PHPDoc (yet) and at the time when the yii2-apidoc tool has been implemented the page you linked also contained an @inheritdoc tag that was described to work similar to what is implemented now. It is actually still there in the PSR proposal: https://github.com/phpDocumentor/fig-standards/blob/b994d853b8ba33bd4bfb00e53cc268d57a5d1e7b/proposed/phpdoc.md#61-making-inheritance-explicit-using-the-inheritdoc-tag so it is hard to say which notation is correct. Because our usage of @inheritdoc is meant to inherit everything and not just description, it is the correct tag to use imo.

@cebe cebe self-assigned this May 26, 2016
@cebe cebe added the type:docs Documentation label May 26, 2016
@samdark
Copy link
Member

samdark commented May 26, 2016

IDEs are OK with what's used currently.

@rob006
Copy link
Contributor

rob006 commented Sep 23, 2016

IDEs are OK with what's used currently.

Well, this is not true. I'm testing NetBeans 8.2-RC now and only {@inheritdoc} works properly. With @inheritdoc it drops method description and actually works like without any inheritdoc tag.

70e4c28d

830c9b01

b51df457

@samdark samdark added the type:bug Bug label Sep 24, 2016
@samdark samdark added this to the 2.0.11 milestone Sep 24, 2016
@MaksimKiselev
Copy link
Contributor

Для всех методов где есть тег @inheritdoc просто добавить {}?

@cebe
Copy link
Member

cebe commented Oct 21, 2016

@mkiselev no, APIdoc tool must be adjusted, see #11635 (comment)

@MaksimKiselev
Copy link
Contributor

@cebe yep, I was read this PSR.

@cebe
Copy link
Member

cebe commented Jul 6, 2017

As long as there is no spec to follow I do not think there is anything we can do about this issue.
There is a significant differentce between @inheritdoc and {@inheritdoc}. @inheritdoc will inherit all tags, {@inheritdoc} will only inherit description. We can not easily change Yii code to use {@inheritdoc}.

@cebe cebe closed this as completed Jul 6, 2017
@cebe cebe removed this from the 2.0.13 milestone Jul 6, 2017
@rob006
Copy link
Contributor

rob006 commented Jul 6, 2017

@cebe "all tags" are inherited by default, so {@inheritdoc} and @inheritdoc would work exactly the same in 99% cases. And remaining 1% contains mostly situations when @inheritdoc is used as inline tag: https://github.com/yiisoft/yii2/blob/master/framework/db/Query.php#L558-L574 . So basically Yii 2 already (incorrectly) uses @inheritdoc as inline tag.

But the main problem with @inheritdoc is that nobody (except Yii 2) using it - everyone sticks to {@inheritdoc}. So @inheritdoc will always have worse support than {@inheritdoc}. We already have great phpdoc with broken links because nobody supports custom [[]] syntax, do we really need another Yii-specific syntax in phpdoc?

@sergeymakinen
Copy link
Member

sergeymakinen commented Jul 6, 2017

I tend to agree with @rob006.

/**
 * @inheritDoc
 */

blocks should be removed at all as they simply don't make any sense.

Only inline {@inheritDoc} should be left when they're needed.

@cebe
Copy link
Member

cebe commented Jul 7, 2017

What exactly is not working with current Yii PHPdoc?

@rob006
Copy link
Contributor

rob006 commented Jul 7, 2017

Links to classes/methods/properties. Yii 2 uses [[]] syntax which is supported only by yii2-apidoc (note that [[select]] is not parsed here):

cfc096a5

Yii 1.1 uses standard {@link} which works perfectly fine in PhpStorm:

7a170fbe

@cebe cebe reopened this Jul 7, 2017
@klimov-paul
Copy link
Member

klimov-paul commented Jul 7, 2017

How does usage of {@link} is related to @inheritdoc topic?
If you are concern about it - you should open a separated issue.

@rob006
Copy link
Contributor

rob006 commented Jul 7, 2017

@klimov-paul {@link} is only another example of yii-specific syntax in phpdoc (after using @inheritdoc instead of {@inheritdoc}). But you're right, it should have another issue.

@samdark samdark added this to the 2.0.15 milestone Jul 8, 2017
@bizley
Copy link
Member

bizley commented Jul 15, 2017

I'll just drop the link to phpDocumentor 2 mentioning the @inheritdoc.

@sergeymakinen
Copy link
Member

TBH, this issue mostly describes problems with a documentation parsing in IDEs. In a long term, I think it's easier for PhpStorm to support @inheritDoc.

@cebe
Copy link
Member

cebe commented Jul 15, 2017

we're going to make a standard and then follow it ;) https://twitter.com/cebe_cc/status/884929923294650368

@rob006
Copy link
Contributor

rob006 commented Jul 16, 2017

Personally I don't see any sense in existing of @inheritdoc. It was created only because someone see problem in docblock with {@inheritdoc} only. So now we have special non-inline tag which can be used only in one scenario and result is exactly the same as with inline tag. It adds only unnecessary complexity, nothing more.

@jblac
Copy link

jblac commented Jul 21, 2017

What we've noticed, is phpDocumentor generates errors with @inheritdoc but with {@inheritdoc} it does not. Take it for what it's worth -- I've started having my team use the latter option because I don't like my error report being above 0... but, i'm anal that way.

@klimov-paul
Copy link
Member

See yiisoft/yii2-apidoc#160

@samdark
Copy link
Member

samdark commented Jan 19, 2018

Summary of current IDE support

Block-level @inheritdoc

Eclipse PDT

  • @inheritdoc doesn't work.

Netbeans 8.2

  • @inheritdoc doesn't work.

PhpStorm

  • @inheritDoc works the same as @inheritdoc.
  • If there's only @inheritdoc, both description and meta-tags are inherited.
  • If there are description and @inheritdoc, it overrides description but inherits meta-tags.
  • @since isn't inherited.
  • If there are @inheritdoc and meta-tags, it inherits description and adds new meta-tags to the ones from parent class.
    Weird thing is that same-named @param tags are duplicated:

Base

/**     
 * @param int $a
 * @param int $b
 */

and

/**
 * @inheritdoc
 * @param string $b
 * @param int $a
 */

gives:

string $b
int $a
int $a
int $b

Inline {@inheritdoc}

Eclipse PDT

  • {@inheritdoc} doesn't work.

NetBeans 8.2

  • {@inheritDoc} works for classes, @since is inherited.
  • {@inheritDoc} does not work for methods.

PhpStorm

  • {@inheritDoc} works like block-level @inheritdoc while {@inheritdoc} (lowercase) works as expected replacing only
    the token with inehrited description.

  • If there's only {@inheritdoc}, both description and meta-tags are inherited.

  • @since isn't inherited.

  • If there is description and {@inheritdoc} in it, then {@inheritdoc} is replaced with inherited description. Meta-tags
    are inherited.

  • If there are {@inheritdoc} and meta-tags, it behaves by replacing {@inheritdoc} with description and weird-merging
    meta-tags.

@samdark
Copy link
Member

samdark commented Jan 19, 2018

That basically means that there's no sense to switch to {@inheritdoc} for all doc comments but supporting it is nice to have since there's PSR for it and it may be used in projects.

@samdark samdark closed this as completed Jan 19, 2018
@klimov-paul
Copy link
Member

So we consider @rob006's screenshots to be forged in Photoshop or something?

Looks like there are 2 researches here with quite an opposite results, so it is hard to determine, who speaks the truth.

@klimov-paul
Copy link
Member

it is nice to have since there's PSR for it and it may be used in projects.

PHPDocumentor project uses {@inheritdoc} tag with brackets. See:
https://github.com/phpDocumentor/Reflection/blob/develop/src/phpDocumentor/Reflection/Php/Argument.php#L63-L65
https://github.com/phpDocumentor/ReflectionDocBlock/blob/3.3.2/src/DocBlock/Tags/PropertyRead.php#L50-L53

This project is the closest thing to be a standard about PHPDoc at the present state.
We use thier libraries to create our own APIDoc at yii2-apidoc.

@samdark
Copy link
Member

samdark commented Jan 19, 2018

Hmm... let me reinstall NetBeans and try again. I've tried by mouse + CTRL over class name (works) and same over method name (displays @inheritdoc).

@samdark
Copy link
Member

samdark commented Jan 19, 2018

NetBeans 8.2 release:

tags

@samdark
Copy link
Member

samdark commented Jan 19, 2018

@samdark samdark reopened this Jan 19, 2018
@rob006
Copy link
Contributor

rob006 commented Jan 19, 2018

@samdark {@inheritdoc} should go on its own line. Using it as this is {@inheritdoc} string does not make any sense.

@klimov-paul
Copy link
Member

klimov-paul commented Jan 19, 2018

@samdark, you are mixing different things here.
The example you provide here is doomed to fail and does not relates to this issue.

PHPDoc has a specific demand on formatting: description plain text goes first, then tags @param, @return and so on.

In your example you attempt to forge method PHPDoc to be following:

/**
 * This is
 * Parent description
 * @param int $var
 * @return int
 * string
 */

which is obviously incorrect.

@klimov-paul
Copy link
Member

The question here is whether IDE picks up parent description from @inheritdoc (plain) as well as from {@inheritdoc} (with brackets) correctly or not.

E.g. which has better support:

this?

/**
 * @inheritdoc
 */
public function foo() {..}

/**
 * @inheritdoc
 * @return Override
 */
public function foo() {..}

/**
 * @inheritdoc
 * @param Override $var
 */
public function foo($var) {..}

or this?

/**
 * {@inheritdoc}
 */
public function foo() {..}

/**
 * {@inheritdoc}
 * @return Override
 */
public function foo() {..}

/**
 * {@inheritdoc}
 * @param Override $var
 */
public function foo($var) {..}

@samdark
Copy link
Member

samdark commented Jan 19, 2018

OK. Netbeans supports plain {@inheritdoc} well. Also checked phpdocumentor code. It doesn't support @inheritdoc w/o { and } at all so yeah, it makes sense to have it.

@rob006, @klimov-paul my example makes sense according to phpdocumenor docs:

But indeed, that doesn't matter.

@samdark
Copy link
Member

samdark commented Jan 19, 2018

So I'm all for {@inheritdoc} w/o any extra strings or property overrides. It has the best support among phpdocumentor, phpstorm and netbeans.

@klimov-paul
Copy link
Member

OK, since yii2-apidoc now supports brackets for 'inheritdoc', I will update the source code in the next few days.

@cebe
Copy link
Member

cebe commented Jan 19, 2018

Does {@inheritdoc} pick up the short or long description or both?

/**
 * This is the short description.
 *
 * This is the long description...
 */

@samdark
Copy link
Member

samdark commented Jan 19, 2018

Both.

@cebe
Copy link
Member

cebe commented Jan 20, 2018

here is an example, where at the position of @inheritdoc only the long description of the parent method should be inserted:

* @inheritdoc

@rob006
Copy link
Contributor

rob006 commented Jan 20, 2018

@cebe There is no real standard for this, so every IDE/tool behaves differently. AFAIK, according to phpDocumentor docs, summary and description inherits separately, so in this Query example only summary should be inserted in the place of {@inheritdoc}.

BTW: I've made some research some time ago. Not sure if it is still valid, but prepare for brainfuck: https://netbeans.org/bugzilla/show_bug.cgi?id=269107#c8 :D

@klimov-paul
Copy link
Member

Resolved by commit 65f6b59

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Bug type:docs Documentation
Projects
None yet
Development

No branches or pull requests

10 participants