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

Improve {@inheritdoc} behavior #4686 #4846

Merged
merged 2 commits into from
Oct 24, 2022

Conversation

junichi11
Copy link
Member

#4686

  • Support {@inheritdoc} for fields and constants
  • Replace {@inheritdoc} with whole parent sentences

Example

<?php

/**
 * Parent class.
 * 
 */
class ParentClass
{
	/**
	 * Parernt field.
	 */
	public $field;

        /**
         * Parent const.
         */
        public const CONSTANT = "CONSTANT";

	/**
	 * Parent method.
	 */
	public function method() {}
}

class Child extends ParentClass
{
	public $field = 'field';

        public const CONSTANT = "CONSTANT";

        public function method() {}
}

/**
 * {@inheritDoc}
 */
class ChildWithTag extends ParentClass
{
	/**
	 * {@inheritDoc}
	 */
	public $field = 'field';

        /**
         * {@inheritDoc}
         */
        public const CONSTANT = "CONSTANT";

	/**
	 * {@inheritDoc}
	 */
	public function method() {}
}

/**
 * Header.
 * {@inheritDoc} Child class.
 * 
 */
class ChildWithTagAndAdditionalComment extends ParentClass
{
	/**
	 * {@inheritDoc} child field.
	 */
	public $field = 'field';

        /**
         * {@inheritDoc} child const.
         */
        public const CONSTANT = "CONSTANT";

	/**
	 * Header.
         * {@inheritDoc} child method.
         * test.
	 */
	public function method() {}
}

$parent = new ParentClass();
$parent->field;
$parent::CONSTANT;
$parent->method();

$child = new Child();
$child->field;
$child::CONSTANT;
$child->method();

$childWithTag = new ChildWithTag();
$childWithTag->field;
$childWithTag::CONSTANT;
$childWithTag->method();

$childWithTag2 = new ChildWithTagAndAdditionalComment();
$childWithTag2->field;
$childWithTag2::CONSTANT;
$childWithTag2->method();

nb-php-gh-4686

@junichi11 junichi11 added the PHP [ci] enable extra PHP tests (php/php.editor) label Oct 23, 2022
@junichi11 junichi11 added this to the NB17 milestone Oct 23, 2022
@junichi11 junichi11 linked an issue Oct 23, 2022 that may be closed by this pull request
Phpdocumentor separates sentences into the header and description.
Then, it replaces `{@inheritdoc}` with description.

However, if there is only one sentence in the parent PHPDoc,
`{@inheritdoc}` is not replaced anything in the child PHPDoc.
So, just replace `{@inheritdoc}` with whole parent sentences by default.
@junichi11
Copy link
Member Author

@tmysik Could you please have a look at this when you have time? If there is no problem, let's merge it. Thanks.

I've implemented this based on PhpDocumentor in the past. If there is exact documentation for {@inheritdoc}, we should follow it. However, I can't find the exact specification about {@inheritDoc} now...
Currently, when PHPDoc has only a single sentence(e.g. Get something.), inline {@inheritdoc} is not replaced by anything (e.g. /** {@inheritdoc} something...*/). If only {@inheritdoc} is written, {@inheritdoc} is replaced with it(Get something). So, I've changed it to the same behavior.

Copy link
Member

@tmysik tmysik left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks for all the tests.

@tmysik tmysik merged commit 9445a56 into apache:master Oct 24, 2022
@junichi11
Copy link
Member Author

@tmysik Thank you for your review!

@junichi11 junichi11 deleted the gh-4686-inheritdoc branch October 24, 2022 11:45
@tmysik
Copy link
Member

tmysik commented Oct 24, 2022

@junichi11 Nothing to thank for, really. You did the job, as always.

@junichi11 junichi11 added the hacktoberfest-accepted Hacktoberfest label Oct 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest-accepted Hacktoberfest PHP [ci] enable extra PHP tests (php/php.editor)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[PHP] Inheriting docs is broken
2 participants