Skip to content

Commit e57fb3a

Browse files
JulianVennentimon-sbr
authored andcommitted
[php-*] Explicitly declare nullable parameters (OpenAPITools#20524)
* [php-nextgen] Explicitly declare nullable parameters explicitly * Fix some deprecation warnings in other php generators * [php-nextgen] Fix PHP 8.4 deprecation warnings with nullable/optional array parameters
1 parent 34660c4 commit e57fb3a

File tree

104 files changed

+209
-208
lines changed

Some content is hidden

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

104 files changed

+209
-208
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PhpNextgenClientCodegen.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -211,15 +211,16 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
211211
}
212212

213213
for (CodegenParameter param : operation.allParams) {
214+
String paramType;
214215
if (param.isArray || param.isMap) {
215-
param.vendorExtensions.putIfAbsent("x-php-param-type", "array");
216+
paramType = "array";
216217
} else {
217-
String paramType = param.dataType;
218-
if ((!param.required || param.isNullable) && !paramType.equals("mixed")) { // optional or nullable but not mixed
219-
paramType = "?" + paramType;
220-
}
221-
param.vendorExtensions.putIfAbsent("x-php-param-type", paramType);
218+
paramType = param.dataType;
219+
}
220+
if ((!param.required || param.isNullable) && !paramType.equals("mixed")) { // optional or nullable but not mixed
221+
paramType = "?" + paramType;
222222
}
223+
param.vendorExtensions.putIfAbsent("x-php-param-type", paramType);
223224
}
224225
}
225226

modules/openapi-generator/src/main/resources/php-dt-modern/ApiClientFactory.php.mustache

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ApiClientFactory implements PM\ServiceFactoryInterface
1616
$this->configKey = $configKey;
1717
}
1818

19-
public function __invoke(ContainerInterface $container, $requestedName, array $options = null): ApiClient
19+
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): ApiClient
2020
{
2121
$config = new OAGAC\ApiClientOptions(\array_merge($this->getServiceConfig($container), $options ?? []));
2222
return new ApiClient(

modules/openapi-generator/src/main/resources/php-dt/ApiClientFactory.php.mustache

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ApiClientFactory implements PM\ServiceFactoryInterface
1616
$this->configKey = $configKey;
1717
}
1818

19-
public function __invoke(ContainerInterface $container, $requestedName, array $options = null): ApiClient
19+
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): ApiClient
2020
{
2121
$config = new OAGAC\ApiClientOptions(\array_merge($this->getServiceConfig($container), $options ?? []));
2222
return new ApiClient(

modules/openapi-generator/src/main/resources/php-mezzio-ph-modern/Factory.php.mustache

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use Laminas\Stratigility\MiddlewarePipe;
2121

2222
class Factory implements FactoryInterface
2323
{
24-
public function __invoke(ContainerInterface $container, $requestedName, array $options = null): Application
24+
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): Application
2525
{
2626
$errorMiddleware = self::getErrorMiddleware($container);
2727
$pipeline = new MiddlewarePipe();

modules/openapi-generator/src/main/resources/php-mezzio-ph/Factory.php.mustache

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use Laminas\Stratigility\MiddlewarePipe;
2121

2222
class Factory implements FactoryInterface
2323
{
24-
public function __invoke(ContainerInterface $container, $requestedName, array $options = null): Application
24+
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): Application
2525
{
2626
$errorMiddleware = self::getErrorMiddleware($container);
2727
$pipeline = new MiddlewarePipe();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ class Configuration
498498
* @param array|null $variables hash of variable and the corresponding value (optional)
499499
* @return string URL based on host settings
500500
*/
501-
public static function getHostString(array $hostSettings, int $hostIndex, array $variables = null): string
501+
public static function getHostString(array $hostSettings, int $hostIndex, ?array $variables = null): string
502502
{
503503
if (null === $variables) {
504504
$variables = [];

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class ObjectSerializer
5656
*
5757
* @return scalar|object|array|null serialized form of $data
5858
*/
59-
public static function sanitizeForSerialization(mixed $data, string $type = null, string $format = null): mixed
59+
public static function sanitizeForSerialization(mixed $data, ?string $type = null, ?string $format = null): mixed
6060
{
6161
if (is_scalar($data) || null === $data) {
6262
return $data;
@@ -388,7 +388,7 @@ class ObjectSerializer
388388
*
389389
* @return mixed a single or an array of $class instances
390390
*/
391-
public static function deserialize(mixed $data, string $class, array $httpHeaders = null): mixed
391+
public static function deserialize(mixed $data, string $class, ?array $httpHeaders = null): mixed
392392
{
393393
if (null === $data) {
394394
return null;

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ 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,
79+
?ClientInterface $client = null,
80+
?Configuration $config = null,
81+
?HeaderSelector $selector = null,
8282
int $hostIndex = 0
8383
) {
8484
$this->client = $client ?: new Client();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}}{{/parentSchema}}{{^par
245245
*
246246
* @param array $data Associated array of property values initializing the model
247247
*/
248-
public function __construct(array $data = null)
248+
public function __construct(?array $data = null)
249249
{
250250
{{#discriminator}}
251251
// Initialize discriminator property with the model name.

samples/client/echo_api/php-nextgen-streaming/src/Api/AuthApi.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ class AuthApi
8787
* @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
8888
*/
8989
public function __construct(
90-
ClientInterface $client = null,
91-
Configuration $config = null,
92-
HeaderSelector $selector = null,
90+
?ClientInterface $client = null,
91+
?Configuration $config = null,
92+
?HeaderSelector $selector = null,
9393
int $hostIndex = 0
9494
) {
9595
$this->client = $client ?: new Client();

samples/client/echo_api/php-nextgen-streaming/src/Api/BodyApi.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ class BodyApi
111111
* @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
112112
*/
113113
public function __construct(
114-
ClientInterface $client = null,
115-
Configuration $config = null,
116-
HeaderSelector $selector = null,
114+
?ClientInterface $client = null,
115+
?Configuration $config = null,
116+
?HeaderSelector $selector = null,
117117
int $hostIndex = 0
118118
) {
119119
$this->client = $client ?: new Client();
@@ -1745,7 +1745,7 @@ public function testEchoBodyAllOfPetRequest(
17451745
* @return string
17461746
*/
17471747
public function testEchoBodyFreeFormObjectResponseString(
1748-
array $body = null,
1748+
?array $body = null,
17491749
string $contentType = self::contentTypes['testEchoBodyFreeFormObjectResponseString'][0]
17501750
): string
17511751
{
@@ -1766,7 +1766,7 @@ public function testEchoBodyFreeFormObjectResponseString(
17661766
* @return array of string, HTTP status code, HTTP response headers (array of strings)
17671767
*/
17681768
public function testEchoBodyFreeFormObjectResponseStringWithHttpInfo(
1769-
array $body = null,
1769+
?array $body = null,
17701770
string $contentType = self::contentTypes['testEchoBodyFreeFormObjectResponseString'][0]
17711771
): array
17721772
{
@@ -1893,7 +1893,7 @@ public function testEchoBodyFreeFormObjectResponseStringWithHttpInfo(
18931893
* @return PromiseInterface
18941894
*/
18951895
public function testEchoBodyFreeFormObjectResponseStringAsync(
1896-
array $body = null,
1896+
?array $body = null,
18971897
string $contentType = self::contentTypes['testEchoBodyFreeFormObjectResponseString'][0]
18981898
): PromiseInterface
18991899
{
@@ -1917,7 +1917,7 @@ function ($response) {
19171917
* @return PromiseInterface
19181918
*/
19191919
public function testEchoBodyFreeFormObjectResponseStringAsyncWithHttpInfo(
1920-
array $body = null,
1920+
?array $body = null,
19211921
string $contentType = self::contentTypes['testEchoBodyFreeFormObjectResponseString'][0]
19221922
): PromiseInterface
19231923
{
@@ -1970,7 +1970,7 @@ function ($exception) {
19701970
* @return \GuzzleHttp\Psr7\Request
19711971
*/
19721972
public function testEchoBodyFreeFormObjectResponseStringRequest(
1973-
array $body = null,
1973+
?array $body = null,
19741974
string $contentType = self::contentTypes['testEchoBodyFreeFormObjectResponseString'][0]
19751975
): Request
19761976
{

samples/client/echo_api/php-nextgen-streaming/src/Api/FormApi.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ class FormApi
9090
* @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
9191
*/
9292
public function __construct(
93-
ClientInterface $client = null,
94-
Configuration $config = null,
95-
HeaderSelector $selector = null,
93+
?ClientInterface $client = null,
94+
?Configuration $config = null,
95+
?HeaderSelector $selector = null,
9696
int $hostIndex = 0
9797
) {
9898
$this->client = $client ?: new Client();

samples/client/echo_api/php-nextgen-streaming/src/Api/HeaderApi.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ class HeaderApi
8484
* @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
8585
*/
8686
public function __construct(
87-
ClientInterface $client = null,
88-
Configuration $config = null,
89-
HeaderSelector $selector = null,
87+
?ClientInterface $client = null,
88+
?Configuration $config = null,
89+
?HeaderSelector $selector = null,
9090
int $hostIndex = 0
9191
) {
9292
$this->client = $client ?: new Client();

samples/client/echo_api/php-nextgen-streaming/src/Api/PathApi.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ class PathApi
8484
* @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
8585
*/
8686
public function __construct(
87-
ClientInterface $client = null,
88-
Configuration $config = null,
89-
HeaderSelector $selector = null,
87+
?ClientInterface $client = null,
88+
?Configuration $config = null,
89+
?HeaderSelector $selector = null,
9090
int $hostIndex = 0
9191
) {
9292
$this->client = $client ?: new Client();

samples/client/echo_api/php-nextgen-streaming/src/Api/QueryApi.php

+13-13
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ class QueryApi
111111
* @param int $hostIndex (Optional) host index to select the list of hosts if defined in the OpenAPI spec
112112
*/
113113
public function __construct(
114-
ClientInterface $client = null,
115-
Configuration $config = null,
116-
HeaderSelector $selector = null,
114+
?ClientInterface $client = null,
115+
?Configuration $config = null,
116+
?HeaderSelector $selector = null,
117117
int $hostIndex = 0
118118
) {
119119
$this->client = $client ?: new Client();
@@ -1853,7 +1853,7 @@ public function testQueryStyleDeepObjectExplodeTrueObjectAllOfRequest(
18531853
* @return string
18541854
*/
18551855
public function testQueryStyleFormExplodeFalseArrayInteger(
1856-
array $query_object = null,
1856+
?array $query_object = null,
18571857
string $contentType = self::contentTypes['testQueryStyleFormExplodeFalseArrayInteger'][0]
18581858
): string
18591859
{
@@ -1874,7 +1874,7 @@ public function testQueryStyleFormExplodeFalseArrayInteger(
18741874
* @return array of string, HTTP status code, HTTP response headers (array of strings)
18751875
*/
18761876
public function testQueryStyleFormExplodeFalseArrayIntegerWithHttpInfo(
1877-
array $query_object = null,
1877+
?array $query_object = null,
18781878
string $contentType = self::contentTypes['testQueryStyleFormExplodeFalseArrayInteger'][0]
18791879
): array
18801880
{
@@ -2001,7 +2001,7 @@ public function testQueryStyleFormExplodeFalseArrayIntegerWithHttpInfo(
20012001
* @return PromiseInterface
20022002
*/
20032003
public function testQueryStyleFormExplodeFalseArrayIntegerAsync(
2004-
array $query_object = null,
2004+
?array $query_object = null,
20052005
string $contentType = self::contentTypes['testQueryStyleFormExplodeFalseArrayInteger'][0]
20062006
): PromiseInterface
20072007
{
@@ -2025,7 +2025,7 @@ function ($response) {
20252025
* @return PromiseInterface
20262026
*/
20272027
public function testQueryStyleFormExplodeFalseArrayIntegerAsyncWithHttpInfo(
2028-
array $query_object = null,
2028+
?array $query_object = null,
20292029
string $contentType = self::contentTypes['testQueryStyleFormExplodeFalseArrayInteger'][0]
20302030
): PromiseInterface
20312031
{
@@ -2078,7 +2078,7 @@ function ($exception) {
20782078
* @return \GuzzleHttp\Psr7\Request
20792079
*/
20802080
public function testQueryStyleFormExplodeFalseArrayIntegerRequest(
2081-
array $query_object = null,
2081+
?array $query_object = null,
20822082
string $contentType = self::contentTypes['testQueryStyleFormExplodeFalseArrayInteger'][0]
20832083
): Request
20842084
{
@@ -2171,7 +2171,7 @@ public function testQueryStyleFormExplodeFalseArrayIntegerRequest(
21712171
* @return string
21722172
*/
21732173
public function testQueryStyleFormExplodeFalseArrayString(
2174-
array $query_object = null,
2174+
?array $query_object = null,
21752175
string $contentType = self::contentTypes['testQueryStyleFormExplodeFalseArrayString'][0]
21762176
): string
21772177
{
@@ -2192,7 +2192,7 @@ public function testQueryStyleFormExplodeFalseArrayString(
21922192
* @return array of string, HTTP status code, HTTP response headers (array of strings)
21932193
*/
21942194
public function testQueryStyleFormExplodeFalseArrayStringWithHttpInfo(
2195-
array $query_object = null,
2195+
?array $query_object = null,
21962196
string $contentType = self::contentTypes['testQueryStyleFormExplodeFalseArrayString'][0]
21972197
): array
21982198
{
@@ -2319,7 +2319,7 @@ public function testQueryStyleFormExplodeFalseArrayStringWithHttpInfo(
23192319
* @return PromiseInterface
23202320
*/
23212321
public function testQueryStyleFormExplodeFalseArrayStringAsync(
2322-
array $query_object = null,
2322+
?array $query_object = null,
23232323
string $contentType = self::contentTypes['testQueryStyleFormExplodeFalseArrayString'][0]
23242324
): PromiseInterface
23252325
{
@@ -2343,7 +2343,7 @@ function ($response) {
23432343
* @return PromiseInterface
23442344
*/
23452345
public function testQueryStyleFormExplodeFalseArrayStringAsyncWithHttpInfo(
2346-
array $query_object = null,
2346+
?array $query_object = null,
23472347
string $contentType = self::contentTypes['testQueryStyleFormExplodeFalseArrayString'][0]
23482348
): PromiseInterface
23492349
{
@@ -2396,7 +2396,7 @@ function ($exception) {
23962396
* @return \GuzzleHttp\Psr7\Request
23972397
*/
23982398
public function testQueryStyleFormExplodeFalseArrayStringRequest(
2399-
array $query_object = null,
2399+
?array $query_object = null,
24002400
string $contentType = self::contentTypes['testQueryStyleFormExplodeFalseArrayString'][0]
24012401
): Request
24022402
{

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ public function getHostSettings(): array
482482
* @param array|null $variables hash of variable and the corresponding value (optional)
483483
* @return string URL based on host settings
484484
*/
485-
public static function getHostString(array $hostSettings, int $hostIndex, array $variables = null): string
485+
public static function getHostString(array $hostSettings, int $hostIndex, ?array $variables = null): string
486486
{
487487
if (null === $variables) {
488488
$variables = [];

samples/client/echo_api/php-nextgen-streaming/src/Model/Bird.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public function getModelName(): string
247247
*
248248
* @param array $data Associated array of property values initializing the model
249249
*/
250-
public function __construct(array $data = null)
250+
public function __construct(?array $data = null)
251251
{
252252
$this->setIfExists('size', $data ?? [], null);
253253
$this->setIfExists('color', $data ?? [], null);

samples/client/echo_api/php-nextgen-streaming/src/Model/Category.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public function getModelName(): string
247247
*
248248
* @param array $data Associated array of property values initializing the model
249249
*/
250-
public function __construct(array $data = null)
250+
public function __construct(?array $data = null)
251251
{
252252
$this->setIfExists('id', $data ?? [], null);
253253
$this->setIfExists('name', $data ?? [], null);

samples/client/echo_api/php-nextgen-streaming/src/Model/DataQuery.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public function getModelName(): string
241241
*
242242
* @param array $data Associated array of property values initializing the model
243243
*/
244-
public function __construct(array $data = null)
244+
public function __construct(?array $data = null)
245245
{
246246
parent::__construct($data);
247247

samples/client/echo_api/php-nextgen-streaming/src/Model/DefaultValue.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public function getArrayStringEnumDefaultAllowableValues()
301301
*
302302
* @param array $data Associated array of property values initializing the model
303303
*/
304-
public function __construct(array $data = null)
304+
public function __construct(?array $data = null)
305305
{
306306
$this->setIfExists('array_string_enum_ref_default', $data ?? [], [["success","failure"]]);
307307
$this->setIfExists('array_string_enum_default', $data ?? [], [["success","failure"]]);

samples/client/echo_api/php-nextgen-streaming/src/Model/NumberPropertiesOnly.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public function getModelName(): string
253253
*
254254
* @param array $data Associated array of property values initializing the model
255255
*/
256-
public function __construct(array $data = null)
256+
public function __construct(?array $data = null)
257257
{
258258
$this->setIfExists('number', $data ?? [], null);
259259
$this->setIfExists('float', $data ?? [], null);

samples/client/echo_api/php-nextgen-streaming/src/Model/Pet.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public function getStatusAllowableValues()
288288
*
289289
* @param array $data Associated array of property values initializing the model
290290
*/
291-
public function __construct(array $data = null)
291+
public function __construct(?array $data = null)
292292
{
293293
$this->setIfExists('id', $data ?? [], null);
294294
$this->setIfExists('name', $data ?? [], null);

samples/client/echo_api/php-nextgen-streaming/src/Model/Query.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public function getOutcomesAllowableValues()
264264
*
265265
* @param array $data Associated array of property values initializing the model
266266
*/
267-
public function __construct(array $data = null)
267+
public function __construct(?array $data = null)
268268
{
269269
$this->setIfExists('id', $data ?? [], null);
270270
$this->setIfExists('outcomes', $data ?? [], [["SUCCESS","FAILURE"]]);

0 commit comments

Comments
 (0)