Skip to content

Commit 4924a51

Browse files
committed
Fix PSR-12 formatting in PHP template
1 parent 0c31459 commit 4924a51

1 file changed

Lines changed: 38 additions & 34 deletions

File tree

modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ class ObjectSerializer
9595
}
9696
}
9797
} else {
98-
foreach($data as $property => $value) {
98+
foreach ($data as $property => $value) {
9999
$values[$property] = self::sanitizeForSerialization($value);
100100
}
101101
}
102-
return (object)$values;
102+
return (object) $values;
103103
} else {
104104
return (string)$data;
105105
}
@@ -131,7 +131,9 @@ class ObjectSerializer
131131
*/
132132
public static function sanitizeTimestamp($timestamp)
133133
{
134-
if (!is_string($timestamp)) return $timestamp;
134+
if (!is_string($timestamp)) {
135+
return $timestamp;
136+
}
135137

136138
return preg_replace('/(:\d{2}.\d{6})\d*/', '$1', $timestamp);
137139
}
@@ -159,20 +161,20 @@ class ObjectSerializer
159161
*/
160162
private static function isEmptyValue($value, string $openApiType): bool
161163
{
162-
# If empty() returns false, it is not empty regardless of its type.
164+
// If empty() returns false, it is not empty regardless of its type.
163165
if (!empty($value)) {
164166
return false;
165167
}
166168

167-
# Null is always empty, as we cannot send a real "null" value in a query parameter.
169+
// Null is always empty, as we cannot send a real "null" value in a query parameter.
168170
if ($value === null) {
169171
return true;
170172
}
171173

172174
switch ($openApiType) {
173-
# For numeric values, false and '' are considered empty.
174-
# This comparison is safe for floating point values, since the previous call to empty() will
175-
# filter out values that don't match 0.
175+
// For numeric values, false and '' are considered empty.
176+
// This comparison is safe for floating point values, since the previous call to empty() will
177+
// filter out values that don't match 0.
176178
case 'int':
177179
case 'integer':
178180
return $value !== 0;
@@ -181,16 +183,16 @@ class ObjectSerializer
181183
case 'float':
182184
return $value !== 0 && $value !== 0.0;
183185
184-
# For boolean values, '' is considered empty
186+
// For boolean values, '' is considered empty
185187
case 'bool':
186188
case 'boolean':
187189
return !in_array($value, [false, 0], true);
188190
189-
# For string values, '' is considered empty.
191+
// For string values, '' is considered empty.
190192
case 'string':
191193
return $value === '';
192194
193-
# For all the other types, any value at this point can be considered empty.
195+
// For all the other types, any value at this point can be considered empty.
194196
default:
195197
return true;
196198
}
@@ -218,10 +220,10 @@ class ObjectSerializer
218220
bool $required = true
219221
): array {
220222
221-
# Check if we should omit this parameter from the query. This should only happen when:
222-
# - Parameter is NOT required; AND
223-
# - its value is set to a value that is equivalent to "empty", depending on its OpenAPI type. For
224-
# example, 0 as "int" or "boolean" is NOT an empty value.
223+
// Check if we should omit this parameter from the query. This should only happen when:
224+
// - Parameter is NOT required; AND
225+
// - its value is set to a value that is equivalent to "empty", depending on its OpenAPI type. For
226+
// example, 0 as "int" or "boolean" is NOT an empty value.
225227
if (self::isEmptyValue($value, $openApiType)) {
226228
if ($required) {
227229
return ["{$paramName}" => ''];
@@ -230,8 +232,8 @@ class ObjectSerializer
230232
}
231233
}
232234
233-
# Handle DateTime objects in query
234-
if($openApiType === "\\DateTime" && $value instanceof \DateTime) {
235+
// Handle DateTime objects in query
236+
if ($openApiType === "\\DateTime" && $value instanceof \DateTime) {
235237
return ["{$paramName}" => $value->format(self::$dateTimeFormat)];
236238
}
237239
@@ -241,10 +243,12 @@ class ObjectSerializer
241243
// since \GuzzleHttp\Psr7\Query::build fails with nested arrays
242244
// need to flatten array first
243245
$flattenArray = function ($arr, $name, &$result = []) use (&$flattenArray, $style, $explode) {
244-
if (!is_array($arr)) return $arr;
246+
if (!is_array($arr)) {
247+
return $arr;
248+
}
245249
246250
foreach ($arr as $k => $v) {
247-
$prop = ($style === 'deepObject') ? $prop = "{$name}[{$k}]" : $k;
251+
$prop = ($style === 'deepObject') ? "{$name}[{$k}]" : $k;
248252
249253
if (is_array($v)) {
250254
$flattenArray($v, $prop, $result);
@@ -489,7 +493,7 @@ class ObjectSerializer
489493
$data = is_string($data) ? json_decode($data) : $data;
490494
491495
if (is_array($data)) {
492-
$data = (object)$data;
496+
$data = (object) $data;
493497
}
494498

495499
// If a discriminator is defined and points to a valid subclass, use it.
@@ -528,20 +532,20 @@ class ObjectSerializer
528532
}
529533

530534
/**
531-
* Build a query string from an array of key value pairs.
532-
*
533-
* This function can use the return value of `parse()` to build a query
534-
* string. This function does not modify the provided keys when an array is
535-
* encountered (like `http_build_query()` would).
536-
*
537-
* The function is copied from https://github.com/guzzle/psr7/blob/a243f80a1ca7fe8ceed4deee17f12c1930efe662/src/Query.php#L59-L112
538-
* with a modification which is described in https://github.com/guzzle/psr7/pull/603
539-
*
540-
* @param array $params Query string parameters.
541-
* @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986
542-
* to encode using RFC3986, or PHP_QUERY_RFC1738
543-
* to encode using RFC1738.
544-
*/
535+
* Build a query string from an array of key value pairs.
536+
*
537+
* This function can use the return value of `parse()` to build a query
538+
* string. This function does not modify the provided keys when an array is
539+
* encountered (like `http_build_query()` would).
540+
*
541+
* The function is copied from https://github.com/guzzle/psr7/blob/a243f80a1ca7fe8ceed4deee17f12c1930efe662/src/Query.php#L59-L112
542+
* with a modification which is described in https://github.com/guzzle/psr7/pull/603
543+
*
544+
* @param array $params Query string parameters.
545+
* @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986
546+
* to encode using RFC3986, or PHP_QUERY_RFC1738
547+
* to encode using RFC1738.
548+
*/
545549
public static function buildQuery(array $params, $encoding = PHP_QUERY_RFC3986): string
546550
{
547551
if (!$params) {

0 commit comments

Comments
 (0)