From c19a3afd2ca59b80aa5ec199f2073834753edf6c Mon Sep 17 00:00:00 2001 From: domenico Date: Tue, 28 May 2024 13:05:05 +0200 Subject: [PATCH] Improved coverage and some little refactory --- src/Commons/Pipeline.php | 1 + src/Filters/DataRefRestore.php | 11 +- src/Filters/Html/HtmlParser.php | 67 ++- src/Filters/Percentages.php | 2 +- src/Filters/RubyOnRailsI18n.php | 18 +- src/Filters/Variables.php | 7 +- src/Utils/ArrayList.php | 19 + src/Utils/Map.php | 138 ++++--- src/Utils/Utils.php | 19 + tests/HandlersOrderTest.php | 106 +++++ tests/MapTest.php | 538 +++++++++++++++++++++++++ tests/MateCatSubFilteringTest.php | 55 ++- tests/Mocks/Features/AirbnbFeature.php | 1 - tests/MyMemorySubFilteringTest.php | 2 +- tests/TestHandlersOrder.php | 76 ---- 15 files changed, 858 insertions(+), 202 deletions(-) create mode 100644 tests/HandlersOrderTest.php create mode 100644 tests/MapTest.php delete mode 100644 tests/TestHandlersOrder.php diff --git a/src/Commons/Pipeline.php b/src/Commons/Pipeline.php index e3a7010..8f275d5 100644 --- a/src/Commons/Pipeline.php +++ b/src/Commons/Pipeline.php @@ -142,6 +142,7 @@ public function remove( AbstractHandler $handlerToDelete ) { foreach ( $this->handlers as $pos => $handler ) { if ( $handler->getName() == $handlerToDelete->getName() ) { unset( $this->handlers[ $pos ] ); + $this->handlers = array_values( $this->handlers ); break; } } diff --git a/src/Filters/DataRefRestore.php b/src/Filters/DataRefRestore.php index a7e1a5e..fcd9196 100644 --- a/src/Filters/DataRefRestore.php +++ b/src/Filters/DataRefRestore.php @@ -59,7 +59,7 @@ public function transform( $segment ) { * @return string */ private function restoreXliffPhTagsFromMatecatPhTags( $segment ) { - preg_match_all( '||iu', $segment, $matches ); + preg_match_all( '|]+? ctype="' . CTypeEnum::ORIGINAL_PH_OR_NOT_DATA_REF . '" equiv-text="base64:(.*?)"/>|iu', $segment, $matches ); if ( empty( $matches[ 0 ] ) ) { return $segment; @@ -89,8 +89,13 @@ private function restoreXliffPhTagsFromMatecatPhTags( $segment ) { * @return string */ private function restoreXliffPcTagsFromMatecatPhTags( $segment ) { - preg_match_all( '||iu', $segment, $matches ); - preg_match_all( '||iu', $segment, $matches ); + + $matches = []; + preg_match_all( '|]+? ctype="' . CTypeEnum::ORIGINAL_PC_OPEN_NO_DATA_REF . '" equiv-text="base64:(.*?)"/>|iu', $segment, $open_matches ); + preg_match_all( '|]+? ctype="' . CTypeEnum::ORIGINAL_PC_CLOSE_NO_DATA_REF . '" equiv-text="base64:(.*?)"/>|iu', $segment, $close_matches ); + + $matches[ 0 ] = array_merge( $open_matches[ 0 ], $close_matches[ 0 ] ); + $matches[ 1 ] = array_merge( $open_matches[ 1 ], $close_matches[ 1 ] ); if ( empty( $matches[ 0 ] ) ) { return $segment; diff --git a/src/Filters/Html/HtmlParser.php b/src/Filters/Html/HtmlParser.php index 1dc7084..253cd31 100644 --- a/src/Filters/Html/HtmlParser.php +++ b/src/Filters/Html/HtmlParser.php @@ -82,6 +82,9 @@ public function __call( $name, $arguments ) { return $reflector->invoke( $this->callbacksHandler, $arguments[ 0 ] ); } + + return null; + } public function transform( $segment ) { @@ -127,9 +130,6 @@ public function transform( $segment ) { // is not possible to have angle brackets inside a tag, this case can not happen // this code would ignore '>' if inside a quote, useless // for more info see https://www.w3.org/TR/xml/#charsets -// if ( $in_quote_char ) { -// break; -// } // if we found a second less than symbol the first one IS NOT a tag, // treat the html_buffer as plain text and attach to the output @@ -141,9 +141,6 @@ public function transform( $segment ) { // is not possible to have angle brackets inside a tag, this case can not happen // this code would ignore '>' if inside a quote, useless // for more info see https://www.w3.org/TR/xml/#charsets -// if ( $in_quote_char ) { -// break; -// } if ( in_array( substr( $html_buffer, 0, 8 ), [ '