diff --git a/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache b/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache index 7c912fcae611..780ac7e05c03 100644 --- a/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache +++ b/modules/openapi-generator/src/main/resources/php/ObjectSerializer.mustache @@ -95,11 +95,11 @@ class ObjectSerializer } } } else { - foreach($data as $property => $value) { + foreach ($data as $property => $value) { $values[$property] = self::sanitizeForSerialization($value); } } - return (object)$values; + return (object) $values; } else { return (string)$data; } @@ -131,7 +131,9 @@ class ObjectSerializer */ public static function sanitizeTimestamp($timestamp) { - if (!is_string($timestamp)) return $timestamp; + if (!is_string($timestamp)) { + return $timestamp; + } return preg_replace('/(:\d{2}.\d{6})\d*/', '$1', $timestamp); } @@ -159,20 +161,20 @@ class ObjectSerializer */ private static function isEmptyValue($value, string $openApiType): bool { - # If empty() returns false, it is not empty regardless of its type. + // If empty() returns false, it is not empty regardless of its type. if (!empty($value)) { return false; } - # Null is always empty, as we cannot send a real "null" value in a query parameter. + // Null is always empty, as we cannot send a real "null" value in a query parameter. if ($value === null) { return true; } switch ($openApiType) { - # For numeric values, false and '' are considered empty. - # This comparison is safe for floating point values, since the previous call to empty() will - # filter out values that don't match 0. + // For numeric values, false and '' are considered empty. + // This comparison is safe for floating point values, since the previous call to empty() will + // filter out values that don't match 0. case 'int': case 'integer': return $value !== 0; @@ -181,16 +183,16 @@ class ObjectSerializer case 'float': return $value !== 0 && $value !== 0.0; - # For boolean values, '' is considered empty + // For boolean values, '' is considered empty case 'bool': case 'boolean': return !in_array($value, [false, 0], true); - # For string values, '' is considered empty. + // For string values, '' is considered empty. case 'string': return $value === ''; - # For all the other types, any value at this point can be considered empty. + // For all the other types, any value at this point can be considered empty. default: return true; } @@ -218,10 +220,10 @@ class ObjectSerializer bool $required = true ): array { - # Check if we should omit this parameter from the query. This should only happen when: - # - Parameter is NOT required; AND - # - its value is set to a value that is equivalent to "empty", depending on its OpenAPI type. For - # example, 0 as "int" or "boolean" is NOT an empty value. + // Check if we should omit this parameter from the query. This should only happen when: + // - Parameter is NOT required; AND + // - its value is set to a value that is equivalent to "empty", depending on its OpenAPI type. For + // example, 0 as "int" or "boolean" is NOT an empty value. if (self::isEmptyValue($value, $openApiType)) { if ($required) { return ["{$paramName}" => '']; @@ -230,8 +232,8 @@ class ObjectSerializer } } - # Handle DateTime objects in query - if($openApiType === "\\DateTime" && $value instanceof \DateTime) { + // Handle DateTime objects in query + if ($openApiType === "\\DateTime" && $value instanceof \DateTime) { return ["{$paramName}" => $value->format(self::$dateTimeFormat)]; } @@ -241,10 +243,12 @@ class ObjectSerializer // since \GuzzleHttp\Psr7\Query::build fails with nested arrays // need to flatten array first $flattenArray = function ($arr, $name, &$result = []) use (&$flattenArray, $style, $explode) { - if (!is_array($arr)) return $arr; + if (!is_array($arr)) { + return $arr; + } foreach ($arr as $k => $v) { - $prop = ($style === 'deepObject') ? $prop = "{$name}[{$k}]" : $k; + $prop = ($style === 'deepObject') ? "{$name}[{$k}]" : $k; if (is_array($v)) { $flattenArray($v, $prop, $result); @@ -489,7 +493,7 @@ class ObjectSerializer $data = is_string($data) ? json_decode($data) : $data; if (is_array($data)) { - $data = (object)$data; + $data = (object) $data; } // If a discriminator is defined and points to a valid subclass, use it. @@ -528,20 +532,20 @@ class ObjectSerializer } /** - * Build a query string from an array of key value pairs. - * - * This function can use the return value of `parse()` to build a query - * string. This function does not modify the provided keys when an array is - * encountered (like `http_build_query()` would). - * - * The function is copied from https://github.com/guzzle/psr7/blob/a243f80a1ca7fe8ceed4deee17f12c1930efe662/src/Query.php#L59-L112 - * with a modification which is described in https://github.com/guzzle/psr7/pull/603 - * - * @param array $params Query string parameters. - * @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986 - * to encode using RFC3986, or PHP_QUERY_RFC1738 - * to encode using RFC1738. - */ + * Build a query string from an array of key value pairs. + * + * This function can use the return value of `parse()` to build a query + * string. This function does not modify the provided keys when an array is + * encountered (like `http_build_query()` would). + * + * The function is copied from https://github.com/guzzle/psr7/blob/a243f80a1ca7fe8ceed4deee17f12c1930efe662/src/Query.php#L59-L112 + * with a modification which is described in https://github.com/guzzle/psr7/pull/603 + * + * @param array $params Query string parameters. + * @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986 + * to encode using RFC3986, or PHP_QUERY_RFC1738 + * to encode using RFC1738. + */ public static function buildQuery(array $params, $encoding = PHP_QUERY_RFC3986): string { if (!$params) { diff --git a/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php b/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php index c4e2fd94c29f..a29544290262 100644 --- a/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php +++ b/samples/client/petstore/php/OpenAPIClient-php/lib/ObjectSerializer.php @@ -103,11 +103,11 @@ public static function sanitizeForSerialization($data, $type = null, $format = n } } } else { - foreach($data as $property => $value) { + foreach ($data as $property => $value) { $values[$property] = self::sanitizeForSerialization($value); } } - return (object)$values; + return (object) $values; } else { return (string)$data; } @@ -139,7 +139,9 @@ public static function sanitizeFilename($filename) */ public static function sanitizeTimestamp($timestamp) { - if (!is_string($timestamp)) return $timestamp; + if (!is_string($timestamp)) { + return $timestamp; + } return preg_replace('/(:\d{2}.\d{6})\d*/', '$1', $timestamp); } @@ -167,20 +169,20 @@ public static function toPathValue($value) */ private static function isEmptyValue($value, string $openApiType): bool { - # If empty() returns false, it is not empty regardless of its type. + // If empty() returns false, it is not empty regardless of its type. if (!empty($value)) { return false; } - # Null is always empty, as we cannot send a real "null" value in a query parameter. + // Null is always empty, as we cannot send a real "null" value in a query parameter. if ($value === null) { return true; } switch ($openApiType) { - # For numeric values, false and '' are considered empty. - # This comparison is safe for floating point values, since the previous call to empty() will - # filter out values that don't match 0. + // For numeric values, false and '' are considered empty. + // This comparison is safe for floating point values, since the previous call to empty() will + // filter out values that don't match 0. case 'int': case 'integer': return $value !== 0; @@ -189,16 +191,16 @@ private static function isEmptyValue($value, string $openApiType): bool case 'float': return $value !== 0 && $value !== 0.0; - # For boolean values, '' is considered empty + // For boolean values, '' is considered empty case 'bool': case 'boolean': return !in_array($value, [false, 0], true); - # For string values, '' is considered empty. + // For string values, '' is considered empty. case 'string': return $value === ''; - # For all the other types, any value at this point can be considered empty. + // For all the other types, any value at this point can be considered empty. default: return true; } @@ -226,10 +228,10 @@ public static function toQueryValue( bool $required = true ): array { - # Check if we should omit this parameter from the query. This should only happen when: - # - Parameter is NOT required; AND - # - its value is set to a value that is equivalent to "empty", depending on its OpenAPI type. For - # example, 0 as "int" or "boolean" is NOT an empty value. + // Check if we should omit this parameter from the query. This should only happen when: + // - Parameter is NOT required; AND + // - its value is set to a value that is equivalent to "empty", depending on its OpenAPI type. For + // example, 0 as "int" or "boolean" is NOT an empty value. if (self::isEmptyValue($value, $openApiType)) { if ($required) { return ["{$paramName}" => '']; @@ -238,8 +240,8 @@ public static function toQueryValue( } } - # Handle DateTime objects in query - if($openApiType === "\\DateTime" && $value instanceof \DateTime) { + // Handle DateTime objects in query + if ($openApiType === "\\DateTime" && $value instanceof \DateTime) { return ["{$paramName}" => $value->format(self::$dateTimeFormat)]; } @@ -249,10 +251,12 @@ public static function toQueryValue( // since \GuzzleHttp\Psr7\Query::build fails with nested arrays // need to flatten array first $flattenArray = function ($arr, $name, &$result = []) use (&$flattenArray, $style, $explode) { - if (!is_array($arr)) return $arr; + if (!is_array($arr)) { + return $arr; + } foreach ($arr as $k => $v) { - $prop = ($style === 'deepObject') ? $prop = "{$name}[{$k}]" : $k; + $prop = ($style === 'deepObject') ? "{$name}[{$k}]" : $k; if (is_array($v)) { $flattenArray($v, $prop, $result); @@ -497,7 +501,7 @@ public static function deserialize($data, $class, $httpHeaders = null) $data = is_string($data) ? json_decode($data) : $data; if (is_array($data)) { - $data = (object)$data; + $data = (object) $data; } // If a discriminator is defined and points to a valid subclass, use it. @@ -536,20 +540,20 @@ public static function deserialize($data, $class, $httpHeaders = null) } /** - * Build a query string from an array of key value pairs. - * - * This function can use the return value of `parse()` to build a query - * string. This function does not modify the provided keys when an array is - * encountered (like `http_build_query()` would). - * - * The function is copied from https://github.com/guzzle/psr7/blob/a243f80a1ca7fe8ceed4deee17f12c1930efe662/src/Query.php#L59-L112 - * with a modification which is described in https://github.com/guzzle/psr7/pull/603 - * - * @param array $params Query string parameters. - * @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986 - * to encode using RFC3986, or PHP_QUERY_RFC1738 - * to encode using RFC1738. - */ + * Build a query string from an array of key value pairs. + * + * This function can use the return value of `parse()` to build a query + * string. This function does not modify the provided keys when an array is + * encountered (like `http_build_query()` would). + * + * The function is copied from https://github.com/guzzle/psr7/blob/a243f80a1ca7fe8ceed4deee17f12c1930efe662/src/Query.php#L59-L112 + * with a modification which is described in https://github.com/guzzle/psr7/pull/603 + * + * @param array $params Query string parameters. + * @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986 + * to encode using RFC3986, or PHP_QUERY_RFC1738 + * to encode using RFC1738. + */ public static function buildQuery(array $params, $encoding = PHP_QUERY_RFC3986): string { if (!$params) { diff --git a/samples/client/petstore/php/psr-18/lib/ObjectSerializer.php b/samples/client/petstore/php/psr-18/lib/ObjectSerializer.php index c4e2fd94c29f..a29544290262 100644 --- a/samples/client/petstore/php/psr-18/lib/ObjectSerializer.php +++ b/samples/client/petstore/php/psr-18/lib/ObjectSerializer.php @@ -103,11 +103,11 @@ public static function sanitizeForSerialization($data, $type = null, $format = n } } } else { - foreach($data as $property => $value) { + foreach ($data as $property => $value) { $values[$property] = self::sanitizeForSerialization($value); } } - return (object)$values; + return (object) $values; } else { return (string)$data; } @@ -139,7 +139,9 @@ public static function sanitizeFilename($filename) */ public static function sanitizeTimestamp($timestamp) { - if (!is_string($timestamp)) return $timestamp; + if (!is_string($timestamp)) { + return $timestamp; + } return preg_replace('/(:\d{2}.\d{6})\d*/', '$1', $timestamp); } @@ -167,20 +169,20 @@ public static function toPathValue($value) */ private static function isEmptyValue($value, string $openApiType): bool { - # If empty() returns false, it is not empty regardless of its type. + // If empty() returns false, it is not empty regardless of its type. if (!empty($value)) { return false; } - # Null is always empty, as we cannot send a real "null" value in a query parameter. + // Null is always empty, as we cannot send a real "null" value in a query parameter. if ($value === null) { return true; } switch ($openApiType) { - # For numeric values, false and '' are considered empty. - # This comparison is safe for floating point values, since the previous call to empty() will - # filter out values that don't match 0. + // For numeric values, false and '' are considered empty. + // This comparison is safe for floating point values, since the previous call to empty() will + // filter out values that don't match 0. case 'int': case 'integer': return $value !== 0; @@ -189,16 +191,16 @@ private static function isEmptyValue($value, string $openApiType): bool case 'float': return $value !== 0 && $value !== 0.0; - # For boolean values, '' is considered empty + // For boolean values, '' is considered empty case 'bool': case 'boolean': return !in_array($value, [false, 0], true); - # For string values, '' is considered empty. + // For string values, '' is considered empty. case 'string': return $value === ''; - # For all the other types, any value at this point can be considered empty. + // For all the other types, any value at this point can be considered empty. default: return true; } @@ -226,10 +228,10 @@ public static function toQueryValue( bool $required = true ): array { - # Check if we should omit this parameter from the query. This should only happen when: - # - Parameter is NOT required; AND - # - its value is set to a value that is equivalent to "empty", depending on its OpenAPI type. For - # example, 0 as "int" or "boolean" is NOT an empty value. + // Check if we should omit this parameter from the query. This should only happen when: + // - Parameter is NOT required; AND + // - its value is set to a value that is equivalent to "empty", depending on its OpenAPI type. For + // example, 0 as "int" or "boolean" is NOT an empty value. if (self::isEmptyValue($value, $openApiType)) { if ($required) { return ["{$paramName}" => '']; @@ -238,8 +240,8 @@ public static function toQueryValue( } } - # Handle DateTime objects in query - if($openApiType === "\\DateTime" && $value instanceof \DateTime) { + // Handle DateTime objects in query + if ($openApiType === "\\DateTime" && $value instanceof \DateTime) { return ["{$paramName}" => $value->format(self::$dateTimeFormat)]; } @@ -249,10 +251,12 @@ public static function toQueryValue( // since \GuzzleHttp\Psr7\Query::build fails with nested arrays // need to flatten array first $flattenArray = function ($arr, $name, &$result = []) use (&$flattenArray, $style, $explode) { - if (!is_array($arr)) return $arr; + if (!is_array($arr)) { + return $arr; + } foreach ($arr as $k => $v) { - $prop = ($style === 'deepObject') ? $prop = "{$name}[{$k}]" : $k; + $prop = ($style === 'deepObject') ? "{$name}[{$k}]" : $k; if (is_array($v)) { $flattenArray($v, $prop, $result); @@ -497,7 +501,7 @@ public static function deserialize($data, $class, $httpHeaders = null) $data = is_string($data) ? json_decode($data) : $data; if (is_array($data)) { - $data = (object)$data; + $data = (object) $data; } // If a discriminator is defined and points to a valid subclass, use it. @@ -536,20 +540,20 @@ public static function deserialize($data, $class, $httpHeaders = null) } /** - * Build a query string from an array of key value pairs. - * - * This function can use the return value of `parse()` to build a query - * string. This function does not modify the provided keys when an array is - * encountered (like `http_build_query()` would). - * - * The function is copied from https://github.com/guzzle/psr7/blob/a243f80a1ca7fe8ceed4deee17f12c1930efe662/src/Query.php#L59-L112 - * with a modification which is described in https://github.com/guzzle/psr7/pull/603 - * - * @param array $params Query string parameters. - * @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986 - * to encode using RFC3986, or PHP_QUERY_RFC1738 - * to encode using RFC1738. - */ + * Build a query string from an array of key value pairs. + * + * This function can use the return value of `parse()` to build a query + * string. This function does not modify the provided keys when an array is + * encountered (like `http_build_query()` would). + * + * The function is copied from https://github.com/guzzle/psr7/blob/a243f80a1ca7fe8ceed4deee17f12c1930efe662/src/Query.php#L59-L112 + * with a modification which is described in https://github.com/guzzle/psr7/pull/603 + * + * @param array $params Query string parameters. + * @param int|false $encoding Set to false to not encode, PHP_QUERY_RFC3986 + * to encode using RFC3986, or PHP_QUERY_RFC1738 + * to encode using RFC1738. + */ public static function buildQuery(array $params, $encoding = PHP_QUERY_RFC3986): string { if (!$params) {