-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
[PHP] Small tweaks for php generator, PHPStan level 1 #7528
[PHP] Small tweaks for php generator, PHPStan level 1 #7528
Conversation
$propertyValue = $data->{$instance::attributeMap()[$property]}; | ||
if (isset($propertyValue)) { | ||
if (isset($data->{$instance::attributeMap()[$property]})) { | ||
$propertyValue = $data->{$instance::attributeMap()[$property]}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous statement basically made no sense, it's just a null check in disguise.
@@ -63,18 +63,18 @@ use {{invokerPackage}}\ObjectSerializer; | |||
* @param ClientInterface $client | |||
* @param Configuration $config | |||
* @param HeaderSelector $selector | |||
* @param int $host_index (Optional) host index to select the list of hosts if defined in the OpenAPI spec | |||
* @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code style fix.
@@ -567,14 +560,16 @@ use {{invokerPackage}}\ObjectSerializer; | |||
} | |||
|
|||
// for model (json/xml) | |||
if (isset($_tempBody)) { | |||
// $_tempBody is the method argument, if present | |||
{{#bodyParams}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one produced nonsensical code unless you have body params:
- sets
$_tempBody
to null - checks if
$_tempBody
is not null
It can never be not null because the code mutating it is not generated, why are the checks for it generated then?
I'm going to check this pr locally today. |
} | ||
} elseif (count($formParams) > 0) { | ||
} else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This abandoned else
really bothers me... Did you forgot to delete it? Or maybe you wanted it as elseif
as it was before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is the if
is only needed when you have the body, otherwise I delete it and the elseif
becomes if
. I don't know how to do it better with Mustache. 🙈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like I fixed it in my commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quite understand the part with the body serialization, looks too complicated to understand it without tests, but I hope you know what you're doing. 👍
Basically, the code does this:
But, in case the second condition is not set, you generate code like this: $_tempBody = null;
// additional code here is not generated
if ($_tempBody !== null) {} Which is nonsensical, the if will never match since the code mutating What I've done is changed the condition from 2. to generate the |
Continuation on #7376, fixes two small code issues and a single code style issue.
PR checklist
./bin/generate-samples.sh
to update all Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example./bin/generate-samples.sh bin/configs/java*
. For Windows users, please run the script in Git BASH.master
@jebentier (2017/07), @dkarlovi (2017/07), @mandrean (2017/08), @jfastnacht (2017/09), @ackintosh (2017/09) heart, @ybelenko (2018/07), @renepardon (2018/12)