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

Trait method "methodName" was already imported. [even if it is an abstract method] #272

Closed
t11n opened this issue Nov 25, 2013 · 4 comments

Comments

@t11n
Copy link

t11n commented Nov 25, 2013

Hi there,

When generating the API documentation for my latest project, I came over the following exception:

Trait method "methodName" was already imported.

I looked into the sources and saw this exception gets thrown, if one tries to import the same method from two different traits. Usually, this is not correct, so the exception gets thrown correctly. Except for (at least) one exception: Traits can import abstract methods. This was my case. Two traits were imported, both having an abstract method with the same name, the using class implements that method. Fine with PHP, but apigen complains.

Without having covered the full issue, I locally applied the following patch to make apigen run through.

--- vendor/andrewsville/php-token-reflection/TokenReflection/ReflectionClass.php    (Revision 485)
+++ vendor/andrewsville/php-token-reflection/TokenReflection/ReflectionClass.php    (Working copy)
@@ -719,7 +719,7 @@
                        }

                        if (!isset($this->methods[$newName])) {
-                           if (isset($methods[$newName])) {
+                           if (isset($methods[$newName]) && !$traitMethod->isAbstract()) {
                                throw new Exception\RuntimeException(sprintf('Trait method "%s" was already imported.', $newName), Exception\RuntimeException::ALREADY_EXISTS, $this);
                            }

@@ -730,7 +730,7 @@

                if (!in_array(null, $imports)) {
                    if (!isset($this->methods[$methodName])) {
-                       if (isset($methods[$methodName])) {
+                       if (isset($methods[$methodName]) && !$traitMethod->isAbstract()) {
                            throw new Exception\RuntimeException(sprintf('Trait method "%s" was already imported.', $methodName), Exception\RuntimeException::ALREADY_EXISTS, $this);
                        }

Basically, the patched version checks if the imported method is an abstract method. If it is, it will not complain.

Maybe somebody can take care of that?

Cheers,
Thomas

@TomasVotruba
Copy link
Contributor

Hi Thomas, looks fine to me.

If you still got this issue, could you send PR?

@t11n
Copy link
Author

t11n commented Sep 9, 2014

Hi, obviously this was the wrong project. Sorry for that. I created a PR for the PHP-Token-Reflection project: Andrewsville/PHP-Token-Reflection#60

Let's see if it is going to be merged.

Cheers,
Thomas

@TomasVotruba
Copy link
Contributor

I see :) . Great that you send a PR!

@TomasVotruba
Copy link
Contributor

@t11n I've just added the fix from your PR to ApiGen's fork of TokenReflection, see https://github.com/apigen/TokenReflection/commit/441d42121a06e045b47c72d562d0920d41766ad0#diff-918c79373ab56a6567b280c96c5503e9R713

This should fasten up the process.

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

No branches or pull requests

2 participants