From 47184874e9b8d61e7f4f83714d839a407d1f8ab3 Mon Sep 17 00:00:00 2001 From: Kent Rasmussen Date: Thu, 9 Jan 2025 09:53:32 +0900 Subject: [PATCH 1/3] refactor: use null coalesce --- .../marketing/php/templates/Configuration.mustache | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/swagger-config/marketing/php/templates/Configuration.mustache b/swagger-config/marketing/php/templates/Configuration.mustache index 245f62d..76751c3 100644 --- a/swagger-config/marketing/php/templates/Configuration.mustache +++ b/swagger-config/marketing/php/templates/Configuration.mustache @@ -41,9 +41,9 @@ class Configuration public function setConfig($config = array()) { - $apiKey = isset($config['apiKey']) ? $config['apiKey'] : ''; - $accessToken = isset($config['accessToken']) ? $config['accessToken'] : ''; - $server = isset($config['server']) ? $config['server'] : 'invalid-server'; + $apiKey = $config['apiKey'] ?? ''; + $accessToken = $config['accessToken'] ?? ''; + $server = $config['server'] ?? 'invalid-server'; $host = str_replace('server', $server, $this->getHost()); // Basic Authentication @@ -74,7 +74,7 @@ class Configuration public function getApiKey($apiKeyIdentifier) { - return isset($this->apiKeys[$apiKeyIdentifier]) ? $this->apiKeys[$apiKeyIdentifier] : null; + return $this->apiKeys[$apiKeyIdentifier] ?? null; } public function setApiKeyPrefix($apiKeyIdentifier, $prefix) @@ -85,7 +85,7 @@ class Configuration public function getApiKeyPrefix($apiKeyIdentifier) { - return isset($this->apiKeyPrefixes[$apiKeyIdentifier]) ? $this->apiKeyPrefixes[$apiKeyIdentifier] : null; + return $this->apiKeyPrefixes[$apiKeyIdentifier] ?? null; } public function setAccessToken($accessToken) From 3c1dd9a3db747bf521840223d4b26fd63fa6d131 Mon Sep 17 00:00:00 2001 From: Kent Rasmussen Date: Thu, 9 Jan 2025 09:58:45 +0900 Subject: [PATCH 2/3] refactor: simplify getApiKeyWithPrefix --- .../marketing/php/templates/Configuration.mustache | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/swagger-config/marketing/php/templates/Configuration.mustache b/swagger-config/marketing/php/templates/Configuration.mustache index 76751c3..1b80aa8 100644 --- a/swagger-config/marketing/php/templates/Configuration.mustache +++ b/swagger-config/marketing/php/templates/Configuration.mustache @@ -220,19 +220,14 @@ class Configuration public function getApiKeyWithPrefix($apiKeyIdentifier) { - $prefix = $this->getApiKeyPrefix($apiKeyIdentifier); $apiKey = $this->getApiKey($apiKeyIdentifier); if ($apiKey === null) { return null; } - if ($prefix === null) { - $keyWithPrefix = $apiKey; - } else { - $keyWithPrefix = $prefix . ' ' . $apiKey; - } + $prefix = $this->getApiKeyPrefix($apiKeyIdentifier); - return $keyWithPrefix; + return $prefix === null ? $apiKey : $prefix . ' ' . $apiKey; } } From d3b3fa9db60246ad3b7932afd3e4910e3fcd3bc1 Mon Sep 17 00:00:00 2001 From: Kent Rasmussen Date: Thu, 9 Jan 2025 13:29:31 +0900 Subject: [PATCH 3/3] refactor: Configuration can also be null reduces the number of PHP 8.4 deprecation warnings --- swagger-config/marketing/php/templates/api.mustache | 2 +- swagger-config/transactional/php/templates/api.mustache | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/swagger-config/marketing/php/templates/api.mustache b/swagger-config/marketing/php/templates/api.mustache index eeae621..9bc4054 100644 --- a/swagger-config/marketing/php/templates/api.mustache +++ b/swagger-config/marketing/php/templates/api.mustache @@ -37,7 +37,7 @@ use {{invokerPackage}}\ObjectSerializer; protected $config; protected $headerSelector; - public function __construct(Configuration $config = null) + public function __construct(?Configuration $config = null) { $this->client = new Client([ 'defaults' => [ diff --git a/swagger-config/transactional/php/templates/api.mustache b/swagger-config/transactional/php/templates/api.mustache index 4e2508d..57a4f37 100644 --- a/swagger-config/transactional/php/templates/api.mustache +++ b/swagger-config/transactional/php/templates/api.mustache @@ -36,7 +36,7 @@ use {{invokerPackage}}\ObjectSerializer; { protected $config; - public function __construct(Configuration $config = null) + public function __construct(?Configuration $config = null) { $this->config = $config ?: new Configuration(); }