Skip to content

Commit 4743076

Browse files
authored
[php] Follow PHP8.4 update: declared nullable parameters explicitly (#20243)
* explictly declared nullable to parameters with "null" default value * generated php sample * fixed unnecessary "?" * re-generated sample
1 parent ba5ecbc commit 4743076

File tree

111 files changed

+458
-458
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+458
-458
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ class Configuration
503503
* @param array|null $variables hash of variable and the corresponding value (optional)
504504
* @return string URL based on host settings
505505
*/
506-
public static function getHostString(array $hostSettings, $hostIndex, array $variables = null)
506+
public static function getHostString(array $hostSettings, $hostIndex, ?array $variables = null)
507507
{
508508
if (null === $variables) {
509509
$variables = [];

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ class ObjectSerializer
4949
* Serialize data
5050
*
5151
* @param mixed $data the data to serialize
52-
* @param string $type the OpenAPIToolsType of the data
53-
* @param string $format the format of the OpenAPITools type of the data
52+
* @param string|null $type the OpenAPIToolsType of the data
53+
* @param string|null $format the format of the OpenAPITools type of the data
5454
*
5555
* @return scalar|object|array|null serialized form of $data
5656
*/
@@ -395,7 +395,7 @@ class ObjectSerializer
395395
*
396396
* @param mixed $data object or primitive to be deserialized
397397
* @param string $class class name is passed as a string
398-
* @param string[] $httpHeaders HTTP headers
398+
* @param string[]|null $httpHeaders HTTP headers
399399
*
400400
* @return object|array|null a single or an array of $class instances
401401
*/

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ use {{invokerPackage}}\ObjectSerializer;
7676
* @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
7777
*/
7878
public function __construct(
79-
ClientInterface $client = null,
80-
Configuration $config = null,
81-
HeaderSelector $selector = null,
82-
$hostIndex = 0
79+
?ClientInterface $client = null,
80+
?Configuration $config = null,
81+
?HeaderSelector $selector = null,
82+
int $hostIndex = 0
8383
) {
8484
$this->client = $client ?: new Client();
8585
$this->config = $config ?: Configuration::getDefaultConfiguration();
@@ -152,7 +152,7 @@ use {{invokerPackage}}\ObjectSerializer;
152152
{{/-last}}
153153
{{/servers}}
154154
{{#allParams}}
155-
* @param {{{dataType}}} ${{paramName}}{{#description}} {{.}}{{/description}}{{^description}} {{paramName}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{#isDeprecated}} (deprecated){{/isDeprecated}}
155+
* @param {{{dataType}}}{{^required}}|null{{/required}} ${{paramName}}{{#description}} {{.}}{{/description}}{{^description}} {{paramName}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{#isDeprecated}} (deprecated){{/isDeprecated}}
156156
{{/allParams}}
157157
{{#servers}}
158158
{{#-first}}
@@ -211,7 +211,7 @@ use {{invokerPackage}}\ObjectSerializer;
211211
{{/-last}}
212212
{{/servers}}
213213
{{#allParams}}
214-
* @param {{{dataType}}} ${{paramName}}{{#description}} {{.}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{#isDeprecated}} (deprecated){{/isDeprecated}}
214+
* @param {{{dataType}}}{{^required}}|null{{/required}} ${{paramName}}{{#description}} {{.}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{#isDeprecated}} (deprecated){{/isDeprecated}}
215215
{{/allParams}}
216216
{{#servers}}
217217
{{#-first}}
@@ -395,7 +395,7 @@ use {{invokerPackage}}\ObjectSerializer;
395395
{{/-last}}
396396
{{/servers}}
397397
{{#allParams}}
398-
* @param {{{dataType}}} ${{paramName}}{{#description}} {{.}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{#isDeprecated}} (deprecated){{/isDeprecated}}
398+
* @param {{{dataType}}}{{^required}}|null{{/required}} ${{paramName}}{{#description}} {{.}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{#isDeprecated}} (deprecated){{/isDeprecated}}
399399
{{/allParams}}
400400
{{#servers}}
401401
{{#-first}}
@@ -457,7 +457,7 @@ use {{invokerPackage}}\ObjectSerializer;
457457
{{/-last}}
458458
{{/servers}}
459459
{{#allParams}}
460-
* @param {{{dataType}}} ${{paramName}}{{#description}} {{.}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{#isDeprecated}} (deprecated){{/isDeprecated}}
460+
* @param {{{dataType}}}{{^required}}|null{{/required}} ${{paramName}}{{#description}} {{.}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{#isDeprecated}} (deprecated){{/isDeprecated}}
461461
{{/allParams}}
462462
{{#servers}}
463463
{{#-first}}
@@ -547,7 +547,7 @@ use {{invokerPackage}}\ObjectSerializer;
547547
{{/-last}}
548548
{{/servers}}
549549
{{#allParams}}
550-
* @param {{{dataType}}} ${{paramName}}{{#description}} {{.}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{#isDeprecated}} (deprecated){{/isDeprecated}}
550+
* @param {{{dataType}}}{{^required}}|null{{/required}} ${{paramName}}{{#description}} {{.}}{{/description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{#isDeprecated}} (deprecated){{/isDeprecated}}
551551
{{/allParams}}
552552
{{#servers}}
553553
{{#-first}}

modules/openapi-generator/src/main/resources/php/libraries/psr-18/ApiException.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ class ApiException extends RequestException
5858
public function __construct(
5959
$message,
6060
RequestInterface $request,
61-
ResponseInterface $response = null,
62-
Exception $previous = null
61+
?ResponseInterface $response = null,
62+
?Exception $previous = null
6363
) {
6464
parent::__construct($message, $request, $previous);
6565
if ($response) {

modules/openapi-generator/src/main/resources/php/libraries/psr-18/api.mustache

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ use function sprintf;
9595
protected $streamFactory;
9696
9797
public function __construct(
98-
ClientInterface $httpClient = null,
99-
Configuration $config = null,
100-
HttpAsyncClient $httpAsyncClient = null,
101-
UriFactoryInterface $uriFactory = null,
102-
RequestFactoryInterface $requestFactory = null,
103-
StreamFactoryInterface $streamFactory = null,
104-
HeaderSelector $selector = null,
98+
?ClientInterface $httpClient = null,
99+
?Configuration $config = null,
100+
?HttpAsyncClient $httpAsyncClient = null,
101+
?UriFactoryInterface $uriFactory = null,
102+
?RequestFactoryInterface $requestFactory = null,
103+
?StreamFactoryInterface $streamFactory = null,
104+
?HeaderSelector $selector = null,
105105
?array $plugins = null,
106106
$hostIndex = 0
107107
) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,10 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}}{{/parentSchema}}{{^par
231231
/**
232232
* Constructor
233233
*
234-
* @param mixed[] $data Associated array of property values
234+
* @param mixed[]|null $data Associated array of property values
235235
* initializing the model
236236
*/
237-
public function __construct(array $data = null)
237+
public function __construct(?array $data = null)
238238
{
239239
{{#parentSchema}}
240240
parent::__construct($data);

samples/client/petstore/php/OpenAPIClient-php/lib/Api/AnotherFakeApi.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ class AnotherFakeApi
8383
* @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
8484
*/
8585
public function __construct(
86-
ClientInterface $client = null,
87-
Configuration $config = null,
88-
HeaderSelector $selector = null,
89-
$hostIndex = 0
86+
?ClientInterface $client = null,
87+
?Configuration $config = null,
88+
?HeaderSelector $selector = null,
89+
int $hostIndex = 0
9090
) {
9191
$this->client = $client ?: new Client();
9292
$this->config = $config ?: Configuration::getDefaultConfiguration();

samples/client/petstore/php/OpenAPIClient-php/lib/Api/DefaultApi.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ class DefaultApi
8383
* @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
8484
*/
8585
public function __construct(
86-
ClientInterface $client = null,
87-
Configuration $config = null,
88-
HeaderSelector $selector = null,
89-
$hostIndex = 0
86+
?ClientInterface $client = null,
87+
?Configuration $config = null,
88+
?HeaderSelector $selector = null,
89+
int $hostIndex = 0
9090
) {
9191
$this->client = $client ?: new Client();
9292
$this->config = $config ?: Configuration::getDefaultConfiguration();

0 commit comments

Comments
 (0)