Skip to content

Commit

Permalink
[PHP] Small tweaks for php generator, PHPStan level 1 (#7528)
Browse files Browse the repository at this point in the history
* Small tweaks for php generator, PHPStan level 1

Co-authored-by: Yuriy Belenko <[email protected]>
  • Loading branch information
dkarlovi and ybelenko committed Oct 7, 2020
1 parent 08a1bdc commit b1da096
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 411 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ class ObjectSerializer
continue;
}

$propertyValue = $data->{$instance::attributeMap()[$property]};
if (isset($propertyValue)) {
if (isset($data->{$instance::attributeMap()[$property]})) {
$propertyValue = $data->{$instance::attributeMap()[$property]};
$instance->$propertySetter(self::deserialize($propertyValue, $type, null));
}
}
Expand Down
25 changes: 11 additions & 14 deletions modules/openapi-generator/src/main/resources/php/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
public function __construct(
ClientInterface $client = null,
Configuration $config = null,
HeaderSelector $selector = null,
$host_index = 0
$hostIndex = 0
) {
$this->client = $client ?: new Client();
$this->config = $config ?: new Configuration();
$this->headerSelector = $selector ?: new HeaderSelector();
$this->hostIndex = $host_index;
$this->hostIndex = $hostIndex;
}

/**
Expand Down Expand Up @@ -547,13 +547,6 @@ use {{invokerPackage}}\ObjectSerializer;
{{/isFile}}
}
{{/formParams}}
// body params
$_tempBody = null;
{{#bodyParams}}
if (isset(${{paramName}})) {
$_tempBody = ${{paramName}};
}
{{/bodyParams}}

if ($multipart) {
$headers = $this->headerSelector->selectHeadersForMultipart(
Expand All @@ -567,14 +560,18 @@ use {{invokerPackage}}\ObjectSerializer;
}

// for model (json/xml)
if (isset($_tempBody)) {
// $_tempBody is the method argument, if present
{{#bodyParams}}
if (isset(${{paramName}})) {
if ($headers['Content-Type'] === 'application/json') {
$httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
$httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization(${{paramName}}));
} else {
$httpBody = $_tempBody;
$httpBody = ${{paramName}};
}
} elseif (count($formParams) > 0) {
{{/bodyParams}}
{{^bodyParams}}
if (count($formParams) > 0) {
{{/bodyParams}}
if ($multipart) {
$multipartContents = [];
foreach ($formParams as $formParamName => $formParamValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,18 @@ class AnotherFakeApi
* @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
*/
public function __construct(
ClientInterface $client = null,
Configuration $config = null,
HeaderSelector $selector = null,
$host_index = 0
$hostIndex = 0
) {
$this->client = $client ?: new Client();
$this->config = $config ?: new Configuration();
$this->headerSelector = $selector ?: new HeaderSelector();
$this->hostIndex = $host_index;
$this->hostIndex = $hostIndex;
}

/**
Expand Down Expand Up @@ -316,11 +316,6 @@ protected function call123TestSpecialTagsRequest($client)



// body params
$_tempBody = null;
if (isset($client)) {
$_tempBody = $client;
}

if ($multipart) {
$headers = $this->headerSelector->selectHeadersForMultipart(
Expand All @@ -334,12 +329,11 @@ protected function call123TestSpecialTagsRequest($client)
}

// for model (json/xml)
if (isset($_tempBody)) {
// $_tempBody is the method argument, if present
if (isset($client)) {
if ($headers['Content-Type'] === 'application/json') {
$httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
$httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($client));
} else {
$httpBody = $_tempBody;
$httpBody = $client;
}
} elseif (count($formParams) > 0) {
if ($multipart) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,18 @@ class DefaultApi
* @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
*/
public function __construct(
ClientInterface $client = null,
Configuration $config = null,
HeaderSelector $selector = null,
$host_index = 0
$hostIndex = 0
) {
$this->client = $client ?: new Client();
$this->config = $config ?: new Configuration();
$this->headerSelector = $selector ?: new HeaderSelector();
$this->hostIndex = $host_index;
$this->hostIndex = $hostIndex;
}

/**
Expand Down Expand Up @@ -301,8 +301,6 @@ protected function fooGetRequest()



// body params
$_tempBody = null;

if ($multipart) {
$headers = $this->headerSelector->selectHeadersForMultipart(
Expand All @@ -316,14 +314,7 @@ protected function fooGetRequest()
}

// for model (json/xml)
if (isset($_tempBody)) {
// $_tempBody is the method argument, if present
if ($headers['Content-Type'] === 'application/json') {
$httpBody = \GuzzleHttp\json_encode(ObjectSerializer::sanitizeForSerialization($_tempBody));
} else {
$httpBody = $_tempBody;
}
} elseif (count($formParams) > 0) {
if (count($formParams) > 0) {
if ($multipart) {
$multipartContents = [];
foreach ($formParams as $formParamName => $formParamValue) {
Expand Down
Loading

0 comments on commit b1da096

Please sign in to comment.