Skip to content

Commit 113c205

Browse files
committed
Fix PSR-12 formatting in PHP template
1 parent 1d3ef5c commit 113c205

1 file changed

Lines changed: 31 additions & 29 deletions

File tree

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

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ class ObjectSerializer
108108
}
109109
}
110110
} else {
111-
foreach($data as $property => $value) {
111+
foreach ($data as $property => $value) {
112112
$values[$property] = self::sanitizeForSerialization($value);
113113
}
114114
}
115-
return (object)$values;
115+
return (object) $values;
116116
} else {
117117
return (string)$data;
118118
}
@@ -170,30 +170,30 @@ class ObjectSerializer
170170
*/
171171
private static function isEmptyValue(mixed $value, string $openApiType): bool
172172
{
173-
# If empty() returns false, it is not empty regardless of its type.
173+
// If empty() returns false, it is not empty regardless of its type.
174174
if (!empty($value)) {
175175
return false;
176176
}
177177

178-
# Null is always empty, as we cannot send a real "null" value in a query parameter.
178+
// Null is always empty, as we cannot send a real "null" value in a query parameter.
179179
if ($value === null) {
180180
return true;
181181
}
182182

183183
return match ($openApiType) {
184-
# For numeric values, false and '' are considered empty.
185-
# This comparison is safe for floating point values, since the previous call to empty() will
186-
# filter out values that don't match 0.
184+
// For numeric values, false and '' are considered empty.
185+
// This comparison is safe for floating point values, since the previous call to empty() will
186+
// filter out values that don't match 0.
187187
'int','integer' => $value !== 0,
188188
'number'|'float' => $value !== 0 && $value !== 0.0,
189189
190-
# For boolean values, '' is considered empty
190+
// For boolean values, '' is considered empty
191191
'bool','boolean' => !in_array($value, [false, 0], true),
192192
193-
# For string values, '' is considered empty.
193+
// For string values, '' is considered empty.
194194
'string' => $value === '',
195195
196-
# For all the other types, any value at this point can be considered empty.
196+
// For all the other types, any value at this point can be considered empty.
197197
default => true
198198
};
199199
}
@@ -220,10 +220,10 @@ class ObjectSerializer
220220
bool $required = true
221221
): array {
222222
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.
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.
227227
if (self::isEmptyValue($value, $openApiType)) {
228228
if ($required) {
229229
return ["{$paramName}" => ''];
@@ -232,8 +232,8 @@ class ObjectSerializer
232232
}
233233
}
234234
235-
# Handle DateTime objects in query
236-
if($openApiType === "\DateTime" && $value instanceof DateTime) {
235+
// Handle DateTime objects in query
236+
if ($openApiType === "\\DateTime" && $value instanceof DateTime) {
237237
return ["{$paramName}" => $value->format(self::$dateTimeFormat)];
238238
}
239239
@@ -243,7 +243,9 @@ class ObjectSerializer
243243
// since \GuzzleHttp\Psr7\Query::build fails with nested arrays
244244
// need to flatten array first
245245
$flattenArray = function ($arr, $name, &$result = []) use (&$flattenArray, $style, $explode) {
246-
if (!is_array($arr)) return $arr;
246+
if (!is_array($arr)) {
247+
return $arr;
248+
}
247249
248250
foreach ($arr as $k => $v) {
249251
$prop = ($style === 'deepObject') ? "{$name}[{$k}]" : $k;
@@ -491,7 +493,7 @@ class ObjectSerializer
491493
$data = is_string($data) ? json_decode($data) : $data;
492494
493495
if (is_array($data)) {
494-
$data = (object)$data;
496+
$data = (object) $data;
495497
}
496498

497499
// If a discriminator is defined and points to a valid subclass, use it.
@@ -530,17 +532,17 @@ class ObjectSerializer
530532
}
531533

532534
/**
533-
* Build a query string from an array of key value pairs.
534-
*
535-
* This function can use the return value of `parse()` to build a query
536-
* string. This function does not modify the provided keys when an array is
537-
* encountered (like `http_build_query()` would).
538-
*
539-
* @param array $params Query string parameters.
540-
* @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986
541-
* to encode using RFC3986, or PHP_QUERY_RFC1738
542-
* to encode using RFC1738.
543-
*/
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+
* @param array $params Query string parameters.
542+
* @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986
543+
* to encode using RFC3986, or PHP_QUERY_RFC1738
544+
* to encode using RFC1738.
545+
*/
544546
public static function buildQuery(array $params, $encoding = PHP_QUERY_RFC3986): string
545547
{
546548
if (!$params) {

0 commit comments

Comments
 (0)