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

Invalid SoapClient::__doRequest() signature #6901

Closed
veewee opened this issue Nov 12, 2021 · 6 comments · Fixed by #6927
Closed

Invalid SoapClient::__doRequest() signature #6901

veewee opened this issue Nov 12, 2021 · 6 comments · Fixed by #6927

Comments

@veewee
Copy link
Contributor

veewee commented Nov 12, 2021

The stubs indicate that the $one_way variable is an integer.
Since PHP 8.0 this is a bool.

psalm/stubs/soap.phpstub

Lines 261 to 268 in 2d0758a

* @param int $one_way [optional] <p>
* If one_way is set to 1, this method returns nothing.
* Use this where a response is not expected.
* </p>
* @return string The XML SOAP response.
* @since 5.0.1
*/
public function __doRequest ($request, $location, $action, $version, $one_way = 0) {}

See https://www.php.net/manual/en/soapclient.dorequest.php

8.0.0 | The type of oneWay is bool now; formerly it was int.

@orklah
Copy link
Collaborator

orklah commented Nov 12, 2021

Ouch, tough one.

This stub is not version dependant so we can't just replace int to bool without messing with lower version. We could allow both int and string but we would not be able to see errors both in older and newer versions.

I'm not sure why we have a stub for this instead of just relying on the CallMap. I guess removing this method from the stub and fixing types directly in the CallMap could work.

Could you try to push a PR doing that and we'll see if it pass?

@veewee
Copy link
Contributor Author

veewee commented Nov 12, 2021

Hello @orklah,

I tried removing the stub method and all tests seems to pass.
See https://github.com/veewee/psalm/actions?query=soap-stubs

However, If I run that version of psalm on my PHP80 repo, I get errors like:

ERROR: MethodSignatureMismatch - src/AbusedClient.php:51:14 - Argument 5 of Soap\ExtSoapEngine\AbusedClient::__doRequest has wrong type 'bool', expecting 'int' as defined by SoapClient::__doRequest (see https://psalm.dev/042)
        bool $one_way = false


ERROR: InvalidArgument - src/AbusedClient.php:66:94 - Argument 5 of SoapClient::__doRequest expects int, bool provided (see https://psalm.dev/004)
        $this->__last_response = parent::__doRequest($request, $location, $action, $version, $oneWay);

So I guess that doesnt fix it? Or do I have to do anything special in the code for that new stub to get picked up?

@orklah
Copy link
Collaborator

orklah commented Nov 12, 2021

Yeah you should also make a few changes in callmaps:
https://github.com/vimeo/psalm/tree/master/dictionaries

CallMap contains current types and then CallMap_XX_delta are delta files in order to know which version changed what. So you should change SoapClient::__doRequest on CallMap.php and CallMap_80_delta

See https://psalm.dev/docs/contributing/editing_callmaps/ for more info on how to edit those

@veewee
Copy link
Contributor Author

veewee commented Nov 13, 2021

That does the trick indeed!
Created a PR.

@veewee veewee closed this as completed Nov 13, 2021
@veewee
Copy link
Contributor Author

veewee commented Nov 15, 2021

@orklah, I just noticed that the return type is invalid as well. It is ?string instead of string.
I can't find a place in the CallMap to change this. Any clue? :)

@orklah
Copy link
Collaborator

orklah commented Nov 15, 2021

The return type is the first element of the array in the callmap, just before the parameters (that are named). Should be easy to change :)

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

Successfully merging a pull request may close this issue.

2 participants