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

Inherit docblock method from interface thru abstract class #2717

Closed
donbidon opened this issue Dec 3, 2020 · 13 comments · Fixed by #3701
Closed

Inherit docblock method from interface thru abstract class #2717

donbidon opened this issue Dec 3, 2020 · 13 comments · Fixed by #3701

Comments

@donbidon
Copy link

donbidon commented Dec 3, 2020

// Interface, abstract and final class described in the same file.

interface SomeInterface
{
    /**
     * Description.
     */
    public function myMethod(int $arg): void;
}

abstract class SomeAbstraction implements SomeInterface
{
}

class SomeClass extends SomeAbstraction
{
    /**
     * {@inheritDoc}
     */
    public function myMethod(int $arg): void
    {
    }
}

Expected behavior

SomeClass::myMethod() has same description as SomeInterface::myMethod().

Actual behavior

SomeClass::myMethod() has description "{@inheritdoc}".

Environment

  • PHPDoc version used: 3.0.0
  • Install method: phar
  • PHP 7.4.10
  • Windows 10
@jaapio jaapio added this to Backlog in v3.2 via automation Dec 4, 2020
@jaapio jaapio added the bug label Dec 4, 2020
@jaapio jaapio added this to To do in v3.4 Dec 28, 2021
@ve3
Copy link

ve3 commented Mar 15, 2024

Confirmed this still happens with phpDoc 3.4.3

@smaddock
Copy link
Contributor

smaddock commented Apr 3, 2024

This structure is the majority of our code base; happy to provide testing or work on a PR if someone points me in the right direction.

@jaapio
Copy link
Member

jaapio commented Apr 5, 2024

The methods are transformed in the Descriptor namespace, the MethodDescriptor class is a the object type representing a method in the code base.

Docblocks of a method are resolved via this method: https://github.com/phpDocumentor/phpDocumentor/blob/master/src/phpDocumentor/Descriptor/MethodDescriptor.php#L205

I think you will need to change something in this trait to make this work: https://github.com/phpDocumentor/phpDocumentor/blob/master/src/phpDocumentor/Descriptor/Traits/HasDescription.php#L36

please let me know when you need some more help to get things started

@smaddock
Copy link
Contributor

The method DocBlock for \phpDocumentor\Descriptor\MethodDescriptor::getInheritedElement describes the correct behavior.

Looks like the problem is line 230 returns before checking if there is further inheritance.

@smaddock
Copy link
Contributor

I know no one likes recursion but that seems to be the reliable fix here, with a bail-out after a sane # of recursions. I'll work on a proof of concept.

@jaapio
Copy link
Member

jaapio commented Apr 15, 2024

Thanks for diving into this. I think you have to keep in mind how this method works. First it will try to find a parent class providing a docblock for the current method.
What is missing here is that we never look into interfaces for classes. So if the current class does implement an interface we should try to find the correct interface.
Keep in mind that an interface can have multiple parents. But that's already covered by the current implementation.

Let's forget about traits for now as they make this more complex.

I would love to see some extra unit tests in a pr to ensure we do not break your work in the future. If you need any assistance feel free to comment on this issue or create a draft pr in an early stage so I can guide you a bit to avoid solutions that I don't want to merge. Or a lot of rework on your side.

Unfortunately I will be away for about 2 weeks so it might be harder for me to help begining from next week. But after that I will have time to help you when needed.

Thanks again for your efforts

@smaddock
Copy link
Contributor

Draft PR #3701 created.

@smaddock
Copy link
Contributor

smaddock commented Apr 18, 2024

How do I build or try out the edits I've made on real data? When I try make phar and then try to use the PHAR I get:

Version string 'my-branch-hash' does not follow SemVer semantics

which is reported here as a known issue... I assume there's a way to get it to build for testing purposes, though, that is not documented in the CONTRIBUTING.md.

@jaapio
Copy link
Member

jaapio commented Apr 18, 2024

I think you can overwrite this by removing the @git-version@ in the application.php. that's the version used to report the version.

@jaapio
Copy link
Member

jaapio commented Apr 18, 2024

What I normally do to test locally is by running

./bin/phpdoc

If you are not using docker you can simply use any directory on your system using the --config to point to the config you want to use.

What I do very often is using the data/example directory to test new features. Maybe you could extend the pizza example to cover your use case so we have an option to add some cypress tests in the future.

@smaddock
Copy link
Contributor

There seems to be an inheritance issue in the master branch. If I run v3.4.3, methods in the current class override any parents. This is the expected behavior. If I run the current master branch, methods are returned from the parent class, even if the current class overrides them. Do you know what changes might have been made since 3.4.3 that would have broken this?

@jaapio
Copy link
Member

jaapio commented Apr 24, 2024

I think that would be this pr: https://github.com/phpDocumentor/phpDocumentor/pull/3375/files#diff-23cf3bc3d273c81962c6616210498f53d0ee54eb25e02525be8347a7f4d26eef

We tried to reduce the maintenance burden and duplication by introducing traits in this pr. I think that PR did most of the changes in this area, it's way to big so it will be hard to find the origin. It might be easier to find out what is happening. And solve that rather then trying to figure out what the original implementation looked like.

@smaddock
Copy link
Contributor

Created new issue for that issue, #3706

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
v3.2
Backlog
v3.4
Backlog
Development

Successfully merging a pull request may close this issue.

4 participants