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 - 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..5bfd74e 100644 --- a/src/EDI/Interpreter.php +++ b/src/EDI/Interpreter.php @@ -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]; @@ -797,7 +797,7 @@ private function processSegment(array &$segment, array &$xmlMap, $segmentIdx, ar //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, ar } 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, ar $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']; 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;