Skip to content

Commit a68ad56

Browse files
authored
[php-*] Explicitly declare nullable parameters (#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 ad8de61 commit a68ad56

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

Lines changed: 7 additions & 6 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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();

0 commit comments

Comments
 (0)