From 19d093f313d47e795d58905bf570e55510deb2c4 Mon Sep 17 00:00:00 2001 From: Matthias Wirtz <matthias.wirtz@hotmail.de> Date: Sat, 23 Nov 2024 09:32:04 +0100 Subject: [PATCH 1/3] implicit nullable is deprecated --- src/EDI/Analyser.php | 2 +- src/EDI/Interpreter.php | 10 +++++----- src/EDI/Reader.php | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/EDI/Analyser.php b/src/EDI/Analyser.php index eff7a8d..147f787 100644 --- a/src/EDI/Analyser.php +++ b/src/EDI/Analyser.php @@ -166,7 +166,7 @@ public function loadMultiSegmentsXml(array $segmentXmlFiles) * @param array|null $rawSegments (optional) List of raw segments from EDI\Parser::getRawSegments * @return string file */ - public function process(array $data, array $rawSegments = null): string + public function process(array $data, ?array $rawSegments = null): string { $r = []; foreach ($data as $nrow => $segment) { diff --git a/src/EDI/Interpreter.php b/src/EDI/Interpreter.php index c925a86..aa96efc 100644 --- a/src/EDI/Interpreter.php +++ b/src/EDI/Interpreter.php @@ -91,9 +91,9 @@ class Interpreter private $serviceSeg; /** - * @var array + * @var array|null */ - private $codes; + private $codes = null; /** * @var callable @@ -126,9 +126,9 @@ class Interpreter * @param string $xmlMsg Path to XML Message representation * @param array $xmlSeg Segments processed by EDI\Analyser::loadSegmentsXml or EDI\Mapping\MappingProvider * @param array $xmlSvc Service segments processed by EDI\Analyser::loadSegmentsXml or EDI\Mapping\MappingProvider - * @param array|null $messageTextConf Personalisation of error messages + * @param array|null $messageTextConf Personalization of error messages */ - public function __construct(string $xmlMsg, array $xmlSeg, array $xmlSvc, array $messageTextConf = null) + public function __construct(string $xmlMsg, array $xmlSeg, array $xmlSvc, ?array $messageTextConf = null) { // simplexml_load_file: This can be affected by a PHP bug #62577 (https://bugs.php.net/bug.php?id=62577) $xmlData = \file_get_contents($xmlMsg); @@ -735,7 +735,7 @@ private function doAddArray(array &$array, array &$jsonMessage, $maxRepeat = 1) * * @param int|null $segmentIdx */ - private function processSegment(array &$segment, array &$xmlMap, $segmentIdx, array &$errors = null): array + private function processSegment(array &$segment, array &$xmlMap, $segmentIdx, ?array &$errors = null): array { $id = $segment[0]; diff --git a/src/EDI/Reader.php b/src/EDI/Reader.php index f5eb5cf..bea003c 100644 --- a/src/EDI/Reader.php +++ b/src/EDI/Reader.php @@ -172,9 +172,10 @@ public function readEdiDataValueReq($filter, int $l1, $l2 = false) * @param int $l1 first level item number (start by 1) * @param false|int $l2 second level item number (start by 0) * @param bool $required if required, but no exist, register error + * @param int|null $offset if multiple segments found, get segment by offset * @return string|null */ - public function readEdiDataValue($filter, int $l1, $l2 = false, bool $required = false, int $offset = null) + public function readEdiDataValue($filter, int $l1, $l2 = false, bool $required = false, ?int $offset = null) { $found_segments = []; $segment_name = $filter; From 7f4712b847984f79cee72f3097688237dc00ea49 Mon Sep 17 00:00:00 2001 From: Matthias Wirtz <matthias.wirtz@hotmail.de> Date: Sat, 23 Nov 2024 18:48:27 +0100 Subject: [PATCH 2/3] test with 8.3 (preinstalled in 24.04), as using phpunit 11 --- .github/workflows/ci.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dc68426..5255675 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,16 +9,14 @@ on: jobs: build-test: - runs-on: ubuntu-latest - + runs-on: ubuntu-24.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Cache Composer dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: /tmp/composer-cache key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }} - uses: php-actions/composer@v6 - name: PHPUnit tests run: ./vendor/bin/phpunit - From 0239aa34555a3f618e211679ff61d065fcaae3bd Mon Sep 17 00:00:00 2001 From: Matthias Wirtz <matthias.wirtz@hotmail.de> Date: Sat, 23 Nov 2024 18:52:59 +0100 Subject: [PATCH 3/3] keep type as is --- src/EDI/Interpreter.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/EDI/Interpreter.php b/src/EDI/Interpreter.php index aa96efc..5bfd74e 100644 --- a/src/EDI/Interpreter.php +++ b/src/EDI/Interpreter.php @@ -91,9 +91,9 @@ class Interpreter private $serviceSeg; /** - * @var array|null + * @var array */ - private $codes = null; + private $codes; /** * @var callable @@ -797,7 +797,7 @@ private function processSegment(array &$segment, array &$xmlMap, $segmentIdx, ?a //print_r($d_sub_desc_attr); //print_r($d_detail); //die(); - if ($this->codes !== null && isset($this->codes[$d_sub_desc_attr['id']]) && is_array($this->codes[$d_sub_desc_attr['id']])) { //if codes is set enable translation of the value + if (isset($this->codes) && isset($this->codes[$d_sub_desc_attr['id']]) && is_array($this->codes[$d_sub_desc_attr['id']])) { //if codes is set enable translation of the value if (isset($this->codes[$d_sub_desc_attr['id']][$d_detail])) { $d_detail = $this->codes[$d_sub_desc_attr['id']][$d_detail]; } @@ -817,7 +817,7 @@ private function processSegment(array &$segment, array &$xmlMap, $segmentIdx, ?a } else { $d_sub_desc_attr = $sub_details_desc[0]['attributes']; - if ($this->codes !== null && isset($this->codes[$d_sub_desc_attr['id']]) && is_array($this->codes[$d_sub_desc_attr['id']])) { //if codes is set enable translation of the value + if (isset($this->codes) && isset($this->codes[$d_sub_desc_attr['id']]) && is_array($this->codes[$d_sub_desc_attr['id']])) { //if codes is set enable translation of the value if (isset($this->codes[$d_sub_desc_attr['id']][$detail]) && $this->codes[$d_sub_desc_attr['id']][$detail]) { $detail = $this->codes[$d_sub_desc_attr['id']][$detail]; } @@ -825,7 +825,7 @@ private function processSegment(array &$segment, array &$xmlMap, $segmentIdx, ?a $jsoncomposite[$d_sub_desc_attr[$this->outputKey]] = $detail; } } else { - if ($this->codes !== null && isset($this->codes[$d_desc_attr['id']]) && is_array($this->codes[$d_desc_attr['id']])) { //if codes is set enable translation of the value + if (isset($this->codes) && isset($this->codes[$d_desc_attr['id']]) && is_array($this->codes[$d_desc_attr['id']])) { //if codes is set enable translation of the value if (isset($this->codes[$d_desc_attr['id']][$detail]) && $this->codes[$d_desc_attr['id']][$detail]) { $detail = $this->codes[$d_desc_attr['id']][$detail]; } @@ -869,7 +869,7 @@ private function processService(array &$segments): array public function rebuildArray() { - if ($this->codes !== null) { + if (isset($this->codes)) { throw new \LogicException('Run the Interpreter without calling setCodes()'); } $unh = $this->serviceSeg['interchangeHeader'];