Skip to content

Commit 5e48b1e

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

3 files changed

Lines changed: 93 additions & 87 deletions

File tree

samples/client/echo_api/php-nextgen-streaming/src/ObjectSerializer.php

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ public static function sanitizeForSerialization(mixed $data, ?string $type = nul
117117
}
118118
}
119119
} else {
120-
foreach($data as $property => $value) {
120+
foreach ($data as $property => $value) {
121121
$values[$property] = self::sanitizeForSerialization($value);
122122
}
123123
}
124-
return (object)$values;
124+
return (object) $values;
125125
} else {
126126
return (string)$data;
127127
}
@@ -179,30 +179,30 @@ public static function toPathValue(string $value): string
179179
*/
180180
private static function isEmptyValue(mixed $value, string $openApiType): bool
181181
{
182-
# If empty() returns false, it is not empty regardless of its type.
182+
// If empty() returns false, it is not empty regardless of its type.
183183
if (!empty($value)) {
184184
return false;
185185
}
186186

187-
# Null is always empty, as we cannot send a real "null" value in a query parameter.
187+
// Null is always empty, as we cannot send a real "null" value in a query parameter.
188188
if ($value === null) {
189189
return true;
190190
}
191191

192192
return match ($openApiType) {
193-
# For numeric values, false and '' are considered empty.
194-
# This comparison is safe for floating point values, since the previous call to empty() will
195-
# filter out values that don't match 0.
193+
// For numeric values, false and '' are considered empty.
194+
// This comparison is safe for floating point values, since the previous call to empty() will
195+
// filter out values that don't match 0.
196196
'int','integer' => $value !== 0,
197197
'number'|'float' => $value !== 0 && $value !== 0.0,
198198

199-
# For boolean values, '' is considered empty
199+
// For boolean values, '' is considered empty
200200
'bool','boolean' => !in_array($value, [false, 0], true),
201201

202-
# For string values, '' is considered empty.
202+
// For string values, '' is considered empty.
203203
'string' => $value === '',
204204

205-
# For all the other types, any value at this point can be considered empty.
205+
// For all the other types, any value at this point can be considered empty.
206206
default => true
207207
};
208208
}
@@ -229,10 +229,10 @@ public static function toQueryValue(
229229
bool $required = true
230230
): array {
231231

232-
# Check if we should omit this parameter from the query. This should only happen when:
233-
# - Parameter is NOT required; AND
234-
# - its value is set to a value that is equivalent to "empty", depending on its OpenAPI type. For
235-
# example, 0 as "int" or "boolean" is NOT an empty value.
232+
// Check if we should omit this parameter from the query. This should only happen when:
233+
// - Parameter is NOT required; AND
234+
// - its value is set to a value that is equivalent to "empty", depending on its OpenAPI type. For
235+
// example, 0 as "int" or "boolean" is NOT an empty value.
236236
if (self::isEmptyValue($value, $openApiType)) {
237237
if ($required) {
238238
return ["{$paramName}" => ''];
@@ -241,8 +241,8 @@ public static function toQueryValue(
241241
}
242242
}
243243

244-
# Handle DateTime objects in query
245-
if($openApiType === "\DateTime" && $value instanceof DateTime) {
244+
// Handle DateTime objects in query
245+
if ($openApiType === "\\DateTime" && $value instanceof DateTime) {
246246
return ["{$paramName}" => $value->format(self::$dateTimeFormat)];
247247
}
248248

@@ -252,7 +252,9 @@ public static function toQueryValue(
252252
// since \GuzzleHttp\Psr7\Query::build fails with nested arrays
253253
// need to flatten array first
254254
$flattenArray = function ($arr, $name, &$result = []) use (&$flattenArray, $style, $explode) {
255-
if (!is_array($arr)) return $arr;
255+
if (!is_array($arr)) {
256+
return $arr;
257+
}
256258

257259
foreach ($arr as $k => $v) {
258260
$prop = ($style === 'deepObject') ? "{$name}[{$k}]" : $k;
@@ -500,7 +502,7 @@ public static function deserialize(mixed $data, string $class, ?array $httpHeade
500502
$data = is_string($data) ? json_decode($data) : $data;
501503

502504
if (is_array($data)) {
503-
$data = (object)$data;
505+
$data = (object) $data;
504506
}
505507

506508
// If a discriminator is defined and points to a valid subclass, use it.
@@ -539,17 +541,17 @@ public static function deserialize(mixed $data, string $class, ?array $httpHeade
539541
}
540542

541543
/**
542-
* Build a query string from an array of key value pairs.
543-
*
544-
* This function can use the return value of `parse()` to build a query
545-
* string. This function does not modify the provided keys when an array is
546-
* encountered (like `http_build_query()` would).
547-
*
548-
* @param array $params Query string parameters.
549-
* @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986
550-
* to encode using RFC3986, or PHP_QUERY_RFC1738
551-
* to encode using RFC1738.
552-
*/
544+
* Build a query string from an array of key value pairs.
545+
*
546+
* This function can use the return value of `parse()` to build a query
547+
* string. This function does not modify the provided keys when an array is
548+
* encountered (like `http_build_query()` would).
549+
*
550+
* @param array $params Query string parameters.
551+
* @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986
552+
* to encode using RFC3986, or PHP_QUERY_RFC1738
553+
* to encode using RFC1738.
554+
*/
553555
public static function buildQuery(array $params, $encoding = PHP_QUERY_RFC3986): string
554556
{
555557
if (!$params) {

samples/client/echo_api/php-nextgen/src/ObjectSerializer.php

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ public static function sanitizeForSerialization(mixed $data, ?string $type = nul
117117
}
118118
}
119119
} else {
120-
foreach($data as $property => $value) {
120+
foreach ($data as $property => $value) {
121121
$values[$property] = self::sanitizeForSerialization($value);
122122
}
123123
}
124-
return (object)$values;
124+
return (object) $values;
125125
} else {
126126
return (string)$data;
127127
}
@@ -179,30 +179,30 @@ public static function toPathValue(string $value): string
179179
*/
180180
private static function isEmptyValue(mixed $value, string $openApiType): bool
181181
{
182-
# If empty() returns false, it is not empty regardless of its type.
182+
// If empty() returns false, it is not empty regardless of its type.
183183
if (!empty($value)) {
184184
return false;
185185
}
186186

187-
# Null is always empty, as we cannot send a real "null" value in a query parameter.
187+
// Null is always empty, as we cannot send a real "null" value in a query parameter.
188188
if ($value === null) {
189189
return true;
190190
}
191191

192192
return match ($openApiType) {
193-
# For numeric values, false and '' are considered empty.
194-
# This comparison is safe for floating point values, since the previous call to empty() will
195-
# filter out values that don't match 0.
193+
// For numeric values, false and '' are considered empty.
194+
// This comparison is safe for floating point values, since the previous call to empty() will
195+
// filter out values that don't match 0.
196196
'int','integer' => $value !== 0,
197197
'number'|'float' => $value !== 0 && $value !== 0.0,
198198

199-
# For boolean values, '' is considered empty
199+
// For boolean values, '' is considered empty
200200
'bool','boolean' => !in_array($value, [false, 0], true),
201201

202-
# For string values, '' is considered empty.
202+
// For string values, '' is considered empty.
203203
'string' => $value === '',
204204

205-
# For all the other types, any value at this point can be considered empty.
205+
// For all the other types, any value at this point can be considered empty.
206206
default => true
207207
};
208208
}
@@ -229,10 +229,10 @@ public static function toQueryValue(
229229
bool $required = true
230230
): array {
231231

232-
# Check if we should omit this parameter from the query. This should only happen when:
233-
# - Parameter is NOT required; AND
234-
# - its value is set to a value that is equivalent to "empty", depending on its OpenAPI type. For
235-
# example, 0 as "int" or "boolean" is NOT an empty value.
232+
// Check if we should omit this parameter from the query. This should only happen when:
233+
// - Parameter is NOT required; AND
234+
// - its value is set to a value that is equivalent to "empty", depending on its OpenAPI type. For
235+
// example, 0 as "int" or "boolean" is NOT an empty value.
236236
if (self::isEmptyValue($value, $openApiType)) {
237237
if ($required) {
238238
return ["{$paramName}" => ''];
@@ -241,8 +241,8 @@ public static function toQueryValue(
241241
}
242242
}
243243

244-
# Handle DateTime objects in query
245-
if($openApiType === "\DateTime" && $value instanceof DateTime) {
244+
// Handle DateTime objects in query
245+
if ($openApiType === "\\DateTime" && $value instanceof DateTime) {
246246
return ["{$paramName}" => $value->format(self::$dateTimeFormat)];
247247
}
248248

@@ -252,7 +252,9 @@ public static function toQueryValue(
252252
// since \GuzzleHttp\Psr7\Query::build fails with nested arrays
253253
// need to flatten array first
254254
$flattenArray = function ($arr, $name, &$result = []) use (&$flattenArray, $style, $explode) {
255-
if (!is_array($arr)) return $arr;
255+
if (!is_array($arr)) {
256+
return $arr;
257+
}
256258

257259
foreach ($arr as $k => $v) {
258260
$prop = ($style === 'deepObject') ? "{$name}[{$k}]" : $k;
@@ -500,7 +502,7 @@ public static function deserialize(mixed $data, string $class, ?array $httpHeade
500502
$data = is_string($data) ? json_decode($data) : $data;
501503

502504
if (is_array($data)) {
503-
$data = (object)$data;
505+
$data = (object) $data;
504506
}
505507

506508
// If a discriminator is defined and points to a valid subclass, use it.
@@ -539,17 +541,17 @@ public static function deserialize(mixed $data, string $class, ?array $httpHeade
539541
}
540542

541543
/**
542-
* Build a query string from an array of key value pairs.
543-
*
544-
* This function can use the return value of `parse()` to build a query
545-
* string. This function does not modify the provided keys when an array is
546-
* encountered (like `http_build_query()` would).
547-
*
548-
* @param array $params Query string parameters.
549-
* @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986
550-
* to encode using RFC3986, or PHP_QUERY_RFC1738
551-
* to encode using RFC1738.
552-
*/
544+
* Build a query string from an array of key value pairs.
545+
*
546+
* This function can use the return value of `parse()` to build a query
547+
* string. This function does not modify the provided keys when an array is
548+
* encountered (like `http_build_query()` would).
549+
*
550+
* @param array $params Query string parameters.
551+
* @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986
552+
* to encode using RFC3986, or PHP_QUERY_RFC1738
553+
* to encode using RFC1738.
554+
*/
553555
public static function buildQuery(array $params, $encoding = PHP_QUERY_RFC3986): string
554556
{
555557
if (!$params) {

samples/client/petstore/php-nextgen/OpenAPIClient-php/src/ObjectSerializer.php

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ public static function sanitizeForSerialization(mixed $data, ?string $type = nul
116116
}
117117
}
118118
} else {
119-
foreach($data as $property => $value) {
119+
foreach ($data as $property => $value) {
120120
$values[$property] = self::sanitizeForSerialization($value);
121121
}
122122
}
123-
return (object)$values;
123+
return (object) $values;
124124
} else {
125125
return (string)$data;
126126
}
@@ -178,30 +178,30 @@ public static function toPathValue(string $value): string
178178
*/
179179
private static function isEmptyValue(mixed $value, string $openApiType): bool
180180
{
181-
# If empty() returns false, it is not empty regardless of its type.
181+
// If empty() returns false, it is not empty regardless of its type.
182182
if (!empty($value)) {
183183
return false;
184184
}
185185

186-
# Null is always empty, as we cannot send a real "null" value in a query parameter.
186+
// Null is always empty, as we cannot send a real "null" value in a query parameter.
187187
if ($value === null) {
188188
return true;
189189
}
190190

191191
return match ($openApiType) {
192-
# For numeric values, false and '' are considered empty.
193-
# This comparison is safe for floating point values, since the previous call to empty() will
194-
# filter out values that don't match 0.
192+
// For numeric values, false and '' are considered empty.
193+
// This comparison is safe for floating point values, since the previous call to empty() will
194+
// filter out values that don't match 0.
195195
'int','integer' => $value !== 0,
196196
'number'|'float' => $value !== 0 && $value !== 0.0,
197197

198-
# For boolean values, '' is considered empty
198+
// For boolean values, '' is considered empty
199199
'bool','boolean' => !in_array($value, [false, 0], true),
200200

201-
# For string values, '' is considered empty.
201+
// For string values, '' is considered empty.
202202
'string' => $value === '',
203203

204-
# For all the other types, any value at this point can be considered empty.
204+
// For all the other types, any value at this point can be considered empty.
205205
default => true
206206
};
207207
}
@@ -228,10 +228,10 @@ public static function toQueryValue(
228228
bool $required = true
229229
): array {
230230

231-
# Check if we should omit this parameter from the query. This should only happen when:
232-
# - Parameter is NOT required; AND
233-
# - its value is set to a value that is equivalent to "empty", depending on its OpenAPI type. For
234-
# example, 0 as "int" or "boolean" is NOT an empty value.
231+
// Check if we should omit this parameter from the query. This should only happen when:
232+
// - Parameter is NOT required; AND
233+
// - its value is set to a value that is equivalent to "empty", depending on its OpenAPI type. For
234+
// example, 0 as "int" or "boolean" is NOT an empty value.
235235
if (self::isEmptyValue($value, $openApiType)) {
236236
if ($required) {
237237
return ["{$paramName}" => ''];
@@ -240,8 +240,8 @@ public static function toQueryValue(
240240
}
241241
}
242242

243-
# Handle DateTime objects in query
244-
if($openApiType === "\DateTime" && $value instanceof DateTime) {
243+
// Handle DateTime objects in query
244+
if ($openApiType === "\\DateTime" && $value instanceof DateTime) {
245245
return ["{$paramName}" => $value->format(self::$dateTimeFormat)];
246246
}
247247

@@ -251,7 +251,9 @@ public static function toQueryValue(
251251
// since \GuzzleHttp\Psr7\Query::build fails with nested arrays
252252
// need to flatten array first
253253
$flattenArray = function ($arr, $name, &$result = []) use (&$flattenArray, $style, $explode) {
254-
if (!is_array($arr)) return $arr;
254+
if (!is_array($arr)) {
255+
return $arr;
256+
}
255257

256258
foreach ($arr as $k => $v) {
257259
$prop = ($style === 'deepObject') ? "{$name}[{$k}]" : $k;
@@ -499,7 +501,7 @@ public static function deserialize(mixed $data, string $class, ?array $httpHeade
499501
$data = is_string($data) ? json_decode($data) : $data;
500502

501503
if (is_array($data)) {
502-
$data = (object)$data;
504+
$data = (object) $data;
503505
}
504506

505507
// If a discriminator is defined and points to a valid subclass, use it.
@@ -538,17 +540,17 @@ public static function deserialize(mixed $data, string $class, ?array $httpHeade
538540
}
539541

540542
/**
541-
* Build a query string from an array of key value pairs.
542-
*
543-
* This function can use the return value of `parse()` to build a query
544-
* string. This function does not modify the provided keys when an array is
545-
* encountered (like `http_build_query()` would).
546-
*
547-
* @param array $params Query string parameters.
548-
* @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986
549-
* to encode using RFC3986, or PHP_QUERY_RFC1738
550-
* to encode using RFC1738.
551-
*/
543+
* Build a query string from an array of key value pairs.
544+
*
545+
* This function can use the return value of `parse()` to build a query
546+
* string. This function does not modify the provided keys when an array is
547+
* encountered (like `http_build_query()` would).
548+
*
549+
* @param array $params Query string parameters.
550+
* @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986
551+
* to encode using RFC3986, or PHP_QUERY_RFC1738
552+
* to encode using RFC1738.
553+
*/
552554
public static function buildQuery(array $params, $encoding = PHP_QUERY_RFC3986): string
553555
{
554556
if (!$params) {

0 commit comments

Comments
 (0)