Skip to content

Commit

Permalink
Fixed pcpdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
Ostico committed May 24, 2024
1 parent 3a85976 commit a95f40a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
13 changes: 3 additions & 10 deletions src/Filters/DataRefReplace.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

namespace Matecat\SubFiltering\Filters;

use DOMException;
use Exception;
use Matecat\SubFiltering\Commons\AbstractHandler;
use Matecat\SubFiltering\Enum\CTypeEnum;
use Matecat\SubFiltering\Utils\DataRefReplacer;
use Matecat\XmlParser\Exception\InvalidXmlException;
use Matecat\XmlParser\Exception\XmlParsingException;
use Matecat\XmlParser\XmlParser;

class DataRefReplace extends AbstractHandler {
Expand Down Expand Up @@ -56,13 +53,13 @@ public function transform( $segment ) {
*
* We can control who sees content when with <ph id="source1" dataRef="source1"/>Visibility Constraints.
*
* is transformed to:
* Is transformed to:
*
* We can control who sees content when with &lt;ph id="mtc_ph_u_1" equiv-text="base64:PHBoIGlkPSJzb3VyY2UxIiBkYXRhUmVmPSJzb3VyY2UxIi8+"/&gt;Visibility Constraints.
*
* @param $segment
*
* @return string|string[]
* @return string
*/
private function replace_Ph_TagsWithoutDataRefCorrespondenceToMatecatPhTags( $segment ) {

Expand Down Expand Up @@ -109,10 +106,6 @@ private function isAValidPhTag( $phTag ) {
return false;
}

if ( $parsed->count() == 0 ) {
return false;
}

// check for matecat ctype
$cType = isset( $parsed[ 0 ]->attributes[ 'ctype' ] ) ? $parsed[ 0 ]->attributes[ 'ctype' ] : null;
if ( CTypeEnum::isMatecatCType( $cType ) ) {
Expand Down Expand Up @@ -146,7 +139,7 @@ private function isAValidPhTag( $phTag ) {
*
* @param $segment
*
* @return string|string[]
* @return string
*/
private function replace_Pc_TagsWithoutDataRefCorrespondenceToMatecatPhTags( $segment ) {

Expand Down
11 changes: 5 additions & 6 deletions src/Utils/DataRefReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ public function replace( $string ) {
}

// 4. replace pc tags
$string = $this->replaceOpeningPcTags( null, $string );
$string = $this->replaceOpeningPcTags( $string );
$string = $this->replaceClosingPcTags( $string, $dataRefEndMap );

} catch ( Exception $ignore ) {
// if something fails here, do not throw exception and return the original string instead
} finally {
return $string;
}
Expand Down Expand Up @@ -177,7 +178,7 @@ private function recursiveTransformDataRefToPhTag( $node, $string ) {
* @param $node
* @param $string
*
* @return mixed
* @return string
* @throws DOMException
* @throws InvalidXmlException
* @throws XmlParsingException
Expand Down Expand Up @@ -257,7 +258,7 @@ private function extractDataRefMapRecursively( $node, &$dataRefEndMap ) {
* @throws InvalidXmlException
* @throws XmlParsingException
*/
private function replaceOpeningPcTags( $node, $string ) {
private function replaceOpeningPcTags( $string ) {

preg_match_all( '|<pc ([^>/]+?)>|iu', $string, $openingPcMatches );

Expand Down Expand Up @@ -362,9 +363,7 @@ public function restore( $string ) {
return $string;
}

// replace eventual empty equiv-text=""
// $string = str_replace( ' equiv-text=""', '', $string );
$html = XmlParser::parse( $string, true );
$html = XmlParser::parse( $string, true );

foreach ( $html as $node ) {
$string = $this->recursiveRestoreOriginalTags( $node, $string );
Expand Down

0 comments on commit a95f40a

Please sign in to comment.