From 6d321166f9d4942fb01b777b6251ea89bb6751d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ja=CC=81n=20Hamra=CC=81k?= Date: Mon, 14 Jul 2025 19:36:36 +0200 Subject: [PATCH 1/2] Support netresearch/jsonmapper ^5.0 --- composer.json | 6 ++---- src/JiraClient.php | 7 +++++++ src/ServiceDesk/Request/Request.php | 7 +++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 58cc2c0e..89cf5176 100644 --- a/composer.json +++ b/composer.json @@ -7,10 +7,8 @@ "php": "^8.0", "ext-curl": "*", "ext-json": "*", - "netresearch/jsonmapper": "^4.2", - "monolog/monolog": "^2.0|^3.0" - }, - "suggest": { + "netresearch/jsonmapper": "^4.2|^5.0", + "monolog/monolog": "^2.0|^3.0", "vlucas/phpdotenv": "^5.0|^6.0" }, "require-dev": { diff --git a/src/JiraClient.php b/src/JiraClient.php index 6c9c5585..a1710873 100644 --- a/src/JiraClient.php +++ b/src/JiraClient.php @@ -73,6 +73,13 @@ public function __construct(?ConfigurationInterface $configuration = null, ?Logg $this->json_mapper = new \JsonMapper(); + // Adjust settings for JsonMapper v5.0 BC + if (property_exists($this->json_mapper, 'bStrictNullTypesInArrays')) { + $this->json_mapper->bStrictNullTypesInArrays = false; // if you want to allow nulls in arrays + } + $this->json_mapper->bStrictNullTypes = false; // if you want to allow nulls + $this->json_mapper->bStrictObjectTypeChecking = false; // if you want to disable strict type checking + // Fix "\JiraRestApi\JsonMapperHelper::class" syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' $this->json_mapper->undefinedPropertyHandler = [new \JiraRestApi\JsonMapperHelper(), 'setUndefinedProperty']; diff --git a/src/ServiceDesk/Request/Request.php b/src/ServiceDesk/Request/Request.php index 3476520a..bc86923d 100644 --- a/src/ServiceDesk/Request/Request.php +++ b/src/ServiceDesk/Request/Request.php @@ -125,6 +125,13 @@ private function map(object $data, object $target) { $mapper = new JsonMapper(); + // Adjust settings for JsonMapper v5.0 BC + if (property_exists($mapper, 'bStrictNullTypesInArrays')) { + $mapper->bStrictNullTypesInArrays = false; // if you want to allow nulls in arrays + } + $mapper->bStrictNullTypes = false; // if you want to allow nulls + $mapper->bStrictObjectTypeChecking = false; // if you want to disable strict type checking + return $mapper->map( $data, $target From 8ef46582c9c9d85b6a34e8757e6192b040640e9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ja=CC=81n=20Hamra=CC=81k?= Date: Mon, 14 Jul 2025 19:50:10 +0200 Subject: [PATCH 2/2] codefactor fix --- src/JiraClient.php | 57 ++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/src/JiraClient.php b/src/JiraClient.php index a1710873..02a7dd52 100644 --- a/src/JiraClient.php +++ b/src/JiraClient.php @@ -205,31 +205,7 @@ public function exec(string $context, array|string|null $post_data = null, ?stri $this->log->info("Curl $custom_request: $url JsonData=".json_encode($post_data, JSON_UNESCAPED_UNICODE)); } - curl_reset($this->curl); - $ch = $this->curl; - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->configuration->getTimeout()); - curl_setopt($ch, CURLOPT_TIMEOUT, $this->configuration->getTimeout()); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_URL, $url); - - // post_data - if (!is_null($post_data)) { - // PUT REQUEST - if (!is_null($custom_request) && $custom_request == 'PUT') { - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); - curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); - } - if (!is_null($custom_request) && $custom_request == 'DELETE') { - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); - } else { - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); - } - } else { - if (!is_null($custom_request) && $custom_request == 'DELETE') { - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); - } - } + $ch = $this->prepareCurlRequest($url, $post_data, $custom_request); // save HTTP Headers $curl_http_headers = [ @@ -628,6 +604,37 @@ private function proxyConfigCurlHandle(\CurlHandle $ch): void } } + private function prepareCurlRequest(string $url, array|string|null $post_data = null, ?string $custom_request = null) + { + curl_reset($this->curl); + $ch = $this->curl; + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->configuration->getTimeout()); + curl_setopt($ch, CURLOPT_TIMEOUT, $this->configuration->getTimeout()); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_URL, $url); + + // post_data + if (!is_null($post_data)) { + // PUT REQUEST + if (!is_null($custom_request) && $custom_request == 'PUT') { + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); + } + if (!is_null($custom_request) && $custom_request == 'DELETE') { + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); + } else { + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); + } + } else { + if (!is_null($custom_request) && $custom_request == 'DELETE') { + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); + } + } + + return $ch; + } + /** * setting REST API url to V2. *