zendframework / zend-code

BSD 3-Clause "New" or "Revised" License
1.68k stars 78 forks source link

MethodReflection::getPrototype() crashes when method has no return #154

Open erickcomp opened 6 years ago

erickcomp commented 6 years ago

When I use this method to grab the protype of a method of my class, it crashes with this error:

"Call to a member function getTypes() on boolean"

It happens because I have a method without return. My opinion is: the return type should be "void" on prototype. Issue #84 adresses the support for void. I've modified the code to make it return void. I could create a pull request if you guys want me to do so.

It was like this:

             $return = $docBlock->getTag('return');
             $returnTypes = $return->getTypes();
             $returnType = count($returnTypes) > 1 ? implode('|', $returnTypes) : $returnTypes[0];

And I've changed to this:

            $return = $docBlock->getTag('return');

            if($return === false)
            {
                $returnType = 'void';
            }
            else
            {
                $returnTypes = $return->getTypes();
                $returnType = count($returnTypes) > 1 ? implode('|', $returnTypes) : $returnTypes[0];
            }

If you don't think it should be void, at least set $returnType variable to empty string or null. I've read the CONTRIBUTING.md, but I'm still pretty new to contributing on github, so fell free to get this code and push it into repository.

Regards

Ocramius commented 6 years ago

Hi @ericklima-comp!

Can you maybe write an example class and snippet of zend-code that reproduces the actual crash?

If you want to, we can guide you through the pull-request process, so you familiarize with the platform and can apply the changes with your own attribution as well, but we first need a unit test. See https://github.com/zendframework/zend-code/blob/323188dc74e2780a401b8014804ef7edcc0fd865/test/Reflection/MethodReflectionTest.php for examples.

erickcomp commented 6 years ago

Hello. I'm kind a dinossaur when it comes to testing. Anyway, I've attached a whole test case. If you need anything else, just let me know. zend-code-bug-test-ericklima.comp_2018.04.17.zip

Ocramius commented 6 years ago

@ericklima-comp you uploaded the entire zip with the repo - can you maybe just add your test to https://gist.github.com/ for now? I can then show you how to open a pull request here.

erickcomp commented 6 years ago

@Ocramius . Here it is! https://gist.github.com/ericklima-comp/bb32e0b9ec1a7ad9c430a201a96d5c3f

weierophinney commented 4 years ago

This repository has been closed and moved to laminas/laminas-code; a new issue has been opened at https://github.com/laminas/laminas-code/issues/6.