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

Generated getResult() method is incompatible with ResultProviderInterface parent method due to missing return type declaration #113

Closed
GaryJones opened this issue Dec 29, 2017 · 3 comments
Labels
Milestone

Comments

@GaryJones
Copy link
Contributor

The ResultProviderAssembler generates classes with a getResult() method.

Here's a part of my WSDL:

<s:element name="CalcRatesResponse">
    <s:complexType>
        <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="CalcRatesResult" type="tns:CalcRatesResult" />
        </s:sequence>
    </s:complexType>
</s:element>

Here's the relevant rule in my config file:

    ->addRule(new Rules\TypenameMatchesRule(
        new Rules\AssembleRule(new ResultProviderAssembler()),
        '/Response$/'
     ))

Here's one of my generated classes:

<?php

namespace GAA\CorpManagerApi\SoapTypes;

use Phpro\SoapClient\Type\ResultProviderInterface;
use Phpro\SoapClient\Type\ResultInterface;

class CalcRatesResponse implements ResultProviderInterface
{

    /**
     * @var CalcRatesResult
     */
    private $CalcRatesResult;

    /**
     * @return CalcRatesResult|ResultInterface
     */
    public function getResult()
    {
        return $this->CalcRatesResult;
    }
}

However, the getResult() method in the ResultProviderInterface has a return type declaration (added via #80), which means the generated method is an incompatible signature, causing a fatal error.

    /**
     * @return ResultInterface
     */
    public function getResult(): ResultInterface;

The method generation code doesn't appear to have anything suggesting that a return type declaration should be included.

Zend-code does have the support of adding a returntype when generating the method from an array.

@veewee veewee added the bug label Dec 29, 2017
@veewee veewee added this to the 0.6.1 milestone Dec 29, 2017
@veewee
Copy link
Contributor

veewee commented Dec 29, 2017

Hi @GaryJones,

Thanks for reporting.
That is indeed a bug that needs to be fixed.

@GaryJones
Copy link
Contributor Author

'returntype' => ResultInterface::class,

...may be to be a working fix, though not ideal since the FQN is added, which is redundant since the use statement at the top of the file is already present. Result is:

    /**
     * @return CalcRatesResult|ResultInterface
     */
    public function getResult() : \Phpro\SoapClient\Type\ResultInterface
    {
        return $this->CalcRatesResult;
    }

If we try to use:

'returntype' => Normalizer::getClassNameFromFQN(ResultInterface::class),

Then zend-code changes it to:

    /**
     * @return CalcRatesResult|ResultInterface
     */
    public function getResult() : \ResultInterface
    {
        return $this->CalcRatesResult;
    }

which is wrong since ResultInterface is not in the global scope.

I'm not familiar enough / not dived in further to see if the ideal is possible:

   /**
     * @return CalcRatesResult|ResultInterface
     */
    public function getResult() : ResultInterface
    {
        return $this->CalcRatesResult;
    }

@veewee
Copy link
Contributor

veewee commented Dec 29, 2017

Hi @GaryJones,

That is a known issue in zend-code that isn't going to be fixed. I suggest to use the FQCN and run a tool like php-cs-fixer on it after the code is generated.

More info at:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants