@@ -45,17 +45,17 @@ discard block |
||
45 | 45 | * @return array |
46 | 46 | */ |
47 | 47 | protected static function getAllConstantValuesMap(): array { |
48 | - if ( empty( static::$allConstantValues ) ) { |
|
49 | - $reflectedProperty = ( new ReflectionClass( static::class ) )->getConstants(); |
|
50 | - static::$allConstantValues = array_flip( $reflectedProperty ); |
|
48 | + if (empty(static::$allConstantValues)) { |
|
49 | + $reflectedProperty = (new ReflectionClass(static::class))->getConstants(); |
|
50 | + static::$allConstantValues = array_flip($reflectedProperty); |
|
51 | 51 | static::$layer2ConstantValues = array_flip( |
52 | - array_filter( $reflectedProperty, function ( $key ) { |
|
53 | - return Utils::contains( 'DATA_REF', $key ); |
|
54 | - }, ARRAY_FILTER_USE_KEY ) |
|
52 | + array_filter($reflectedProperty, function($key) { |
|
53 | + return Utils::contains('DATA_REF', $key); |
|
54 | + }, ARRAY_FILTER_USE_KEY) |
|
55 | 55 | ); |
56 | 56 | } |
57 | 57 | |
58 | - return [ 'all' => static::$allConstantValues, 'layer2' => static::$layer2ConstantValues ]; |
|
58 | + return ['all' => static::$allConstantValues, 'layer2' => static::$layer2ConstantValues]; |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | * |
64 | 64 | * @return bool |
65 | 65 | */ |
66 | - public static function isMatecatCType( string $ctype ): bool { |
|
67 | - return array_key_exists( $ctype, static::getAllConstantValuesMap()[ 'all' ] ); |
|
66 | + public static function isMatecatCType(string $ctype): bool { |
|
67 | + return array_key_exists($ctype, static::getAllConstantValuesMap()['all']); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -72,8 +72,8 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @return bool |
74 | 74 | */ |
75 | - public static function isLayer2Constant( string $ctype ): bool { |
|
76 | - return array_key_exists( $ctype, static::getAllConstantValuesMap()[ 'layer2' ] ); |
|
75 | + public static function isLayer2Constant(string $ctype): bool { |
|
76 | + return array_key_exists($ctype, static::getAllConstantValuesMap()['layer2']); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | } |
80 | 80 | \ No newline at end of file |
@@ -17,5 +17,5 @@ |
||
17 | 17 | * modified in cascade to the next function in the queue. |
18 | 18 | * @throws Exception |
19 | 19 | */ |
20 | - public function filter( $method, $filterable ); |
|
20 | + public function filter($method, $filterable); |
|
21 | 21 | } |
22 | 22 | \ No newline at end of file |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * @param string|null $source |
37 | 37 | * @param string|null $target |
38 | 38 | */ |
39 | - public function __construct( ?string $source = null, ?string $target = null ) { |
|
39 | + public function __construct(?string $source = null, ?string $target = null) { |
|
40 | 40 | $this->source = $source; |
41 | 41 | $this->target = $target; |
42 | 42 | $this->notAllowedMap = $this->createNotAllowedMap(); |
@@ -48,17 +48,17 @@ discard block |
||
48 | 48 | private function createNotAllowedMap(): array { |
49 | 49 | $map = []; |
50 | 50 | |
51 | - $all = include __DIR__ . "/language/all/not_allowed.php"; |
|
52 | - $map = array_merge( $map, $all ); |
|
51 | + $all = include __DIR__."/language/all/not_allowed.php"; |
|
52 | + $map = array_merge($map, $all); |
|
53 | 53 | |
54 | - if ( $this->source and file_exists( __DIR__ . "/language/" . $this->source . "/not_allowed.php" ) ) { |
|
55 | - $source = include __DIR__ . "/language/" . $this->source . "/not_allowed.php"; |
|
56 | - $map = array_merge( $map, $source ); |
|
54 | + if ($this->source and file_exists(__DIR__."/language/".$this->source."/not_allowed.php")) { |
|
55 | + $source = include __DIR__."/language/".$this->source."/not_allowed.php"; |
|
56 | + $map = array_merge($map, $source); |
|
57 | 57 | } |
58 | 58 | |
59 | - if ( $this->target and file_exists( __DIR__ . "/language/" . $this->target . "/not_allowed.php" ) ) { |
|
60 | - $target = include __DIR__ . "/language/" . $this->target . "/not_allowed.php"; |
|
61 | - $map = array_merge( $map, $target ); |
|
59 | + if ($this->target and file_exists(__DIR__."/language/".$this->target."/not_allowed.php")) { |
|
60 | + $target = include __DIR__."/language/".$this->target."/not_allowed.php"; |
|
61 | + $map = array_merge($map, $target); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | return $map; |
@@ -69,11 +69,11 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @return string |
71 | 71 | */ |
72 | - public function lock( string $segment ): string { |
|
73 | - $replacementMap = $this->createReplacementMap( $segment ); |
|
72 | + public function lock(string $segment): string { |
|
73 | + $replacementMap = $this->createReplacementMap($segment); |
|
74 | 74 | $this->replacementMap = $replacementMap; |
75 | 75 | |
76 | - return str_replace( array_keys( $replacementMap ), array_values( $replacementMap ), $segment ); |
|
76 | + return str_replace(array_keys($replacementMap), array_values($replacementMap), $segment); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
@@ -81,10 +81,10 @@ discard block |
||
81 | 81 | * |
82 | 82 | * @return string |
83 | 83 | */ |
84 | - public function unlock(string $segment ): string { |
|
84 | + public function unlock(string $segment): string { |
|
85 | 85 | $replacementMap = $this->replacementMap; |
86 | 86 | |
87 | - return str_replace( array_values( $replacementMap ), array_keys( $replacementMap ), $segment ); |
|
87 | + return str_replace(array_values($replacementMap), array_keys($replacementMap), $segment); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -94,23 +94,23 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @return array |
96 | 96 | */ |
97 | - private function createReplacementMap( string $segment ): array { |
|
97 | + private function createReplacementMap(string $segment): array { |
|
98 | 98 | $replacementMap = []; |
99 | 99 | |
100 | - foreach ( $this->notAllowedMap as $item => $details ) { |
|
100 | + foreach ($this->notAllowedMap as $item => $details) { |
|
101 | 101 | |
102 | - $type = $details[ 'type' ]; |
|
102 | + $type = $details['type']; |
|
103 | 103 | |
104 | - switch ( $type ) { |
|
104 | + switch ($type) { |
|
105 | 105 | case 'exact': |
106 | - $replacementMap[ $item ] = self::PRE_LOCK_TAG . $this->maskString( $item ) . self::POST_LOCK_TAG; |
|
106 | + $replacementMap[$item] = self::PRE_LOCK_TAG.$this->maskString($item).self::POST_LOCK_TAG; |
|
107 | 107 | break; |
108 | 108 | |
109 | 109 | case 'regex': |
110 | - preg_match_all( '/' . $item . '/', $segment, $matches ); |
|
110 | + preg_match_all('/'.$item.'/', $segment, $matches); |
|
111 | 111 | |
112 | - foreach ( $matches[ 0 ] as $match ) { |
|
113 | - $replacementMap[ $match ] = self::PRE_LOCK_TAG . $this->maskString( $match ) . self::POST_LOCK_TAG; |
|
112 | + foreach ($matches[0] as $match) { |
|
113 | + $replacementMap[$match] = self::PRE_LOCK_TAG.$this->maskString($match).self::POST_LOCK_TAG; |
|
114 | 114 | } |
115 | 115 | break; |
116 | 116 | } |
@@ -124,8 +124,8 @@ discard block |
||
124 | 124 | * |
125 | 125 | * @return string |
126 | 126 | */ |
127 | - private function maskString( string $string ): string { |
|
128 | - return str_replace( [ '%', '-', '_' ], '', $string ); |
|
127 | + private function maskString(string $string): string { |
|
128 | + return str_replace(['%', '-', '_'], '', $string); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | } |
132 | 132 | \ No newline at end of file |
@@ -13,18 +13,18 @@ |
||
13 | 13 | |
14 | 14 | class RestoreEquivText extends AbstractHandler { |
15 | 15 | |
16 | - public function transform( string $segment ): string { |
|
16 | + public function transform(string $segment): string { |
|
17 | 17 | |
18 | 18 | // extract equiv-text attribute |
19 | - preg_match_all( '/equiv-text=\"(.*?)\"/', $segment, $equiv_tags ); |
|
19 | + preg_match_all('/equiv-text=\"(.*?)\"/', $segment, $equiv_tags); |
|
20 | 20 | |
21 | - if ( !empty( $equiv_tags[ 0 ] ) ) { |
|
22 | - foreach ( $equiv_tags[ 0 ] as $index => $equiv_tag ) { |
|
23 | - $tag = $equiv_tags[ 1 ][ $index ]; |
|
21 | + if (!empty($equiv_tags[0])) { |
|
22 | + foreach ($equiv_tags[0] as $index => $equiv_tag) { |
|
23 | + $tag = $equiv_tags[1][$index]; |
|
24 | 24 | |
25 | - if ( strpos( $tag, "base64:" ) !== false ) { |
|
26 | - $b = base64_decode( str_replace( "base64:", "", $tag ) ); |
|
27 | - $segment = str_replace( $equiv_tags[ $index ], 'equiv-text="' . $b . '"', $segment ); |
|
25 | + if (strpos($tag, "base64:") !== false) { |
|
26 | + $b = base64_decode(str_replace("base64:", "", $tag)); |
|
27 | + $segment = str_replace($equiv_tags[$index], 'equiv-text="'.$b.'"', $segment); |
|
28 | 28 | } |
29 | 29 | } |
30 | 30 | } |
@@ -12,17 +12,17 @@ |
||
12 | 12 | * |
13 | 13 | * @return string |
14 | 14 | */ |
15 | - public function transform( string $segment ): string { |
|
15 | + public function transform(string $segment): string { |
|
16 | 16 | /* |
17 | 17 | * Examples: |
18 | 18 | * - %{{(text-align=center)}} |
19 | 19 | */ |
20 | - preg_match_all( '/%{{(?!<ph )[^{}]*?}}/', $segment, $html, PREG_SET_ORDER ); |
|
21 | - foreach ( $html as $pos => $variable ) { |
|
20 | + preg_match_all('/%{{(?!<ph )[^{}]*?}}/', $segment, $html, PREG_SET_ORDER); |
|
21 | + foreach ($html as $pos => $variable) { |
|
22 | 22 | //replace subsequent elements excluding already encoded |
23 | 23 | $segment = preg_replace( |
24 | - '/' . preg_quote( $variable[ 0 ], '/' ) . '/', |
|
25 | - '<ph id="' . $this->getPipeline()->getNextId() . '" ctype="' . CTypeEnum::PERCENT_VARIABLE . '" equiv-text="base64:' . base64_encode( $variable[ 0 ] ) . "\"/>", |
|
24 | + '/'.preg_quote($variable[0], '/').'/', |
|
25 | + '<ph id="'.$this->getPipeline()->getNextId().'" ctype="'.CTypeEnum::PERCENT_VARIABLE.'" equiv-text="base64:'.base64_encode($variable[0])."\"/>", |
|
26 | 26 | $segment, |
27 | 27 | 1 |
28 | 28 | ); |
@@ -6,41 +6,41 @@ |
||
6 | 6 | use Matecat\SubFiltering\Utils\Utils; |
7 | 7 | |
8 | 8 | class EncodeToRawXML extends AbstractHandler { |
9 | - public function transform( string $segment ): string { |
|
9 | + public function transform(string $segment): string { |
|
10 | 10 | |
11 | 11 | // handling (line feed) |
12 | 12 | // prevent to convert it to \n |
13 | - $segment = preg_replace( '/&(#10;|#x0A;)|\n/', '##_ent_0A_##', $segment ); |
|
13 | + $segment = preg_replace('/&(#10;|#x0A;)|\n/', '##_ent_0A_##', $segment); |
|
14 | 14 | |
15 | 15 | // handling (carriage return) |
16 | 16 | // prevent to convert it to \r |
17 | - $segment = preg_replace( '/&(#13;|#x0D;)|\r/', '##_ent_0D_##', $segment ); |
|
17 | + $segment = preg_replace('/&(#13;|#x0D;)|\r/', '##_ent_0D_##', $segment); |
|
18 | 18 | |
19 | 19 | // handling 	 (tab) |
20 | 20 | // prevent to convert it to \t |
21 | - $segment = preg_replace( '/	|\t/', '##_ent_09_##', $segment ); |
|
21 | + $segment = preg_replace('/	|\t/', '##_ent_09_##', $segment); |
|
22 | 22 | |
23 | 23 | //Substitute 4(+)-byte characters from a UTF-8 string to htmlentities |
24 | - $segment = preg_replace_callback( '/([\xF0-\xF7]...)/s', [ Utils::class, 'htmlentitiesFromUnicode' ], $segment ); |
|
24 | + $segment = preg_replace_callback('/([\xF0-\xF7]...)/s', [Utils::class, 'htmlentitiesFromUnicode'], $segment); |
|
25 | 25 | |
26 | 26 | // handling |
27 | - if ( strpos( $segment, '##_ent_0D_##' ) !== false ) { |
|
28 | - $segment = str_replace( '##_ent_0D_##', ' ', $segment ); |
|
27 | + if (strpos($segment, '##_ent_0D_##') !== false) { |
|
28 | + $segment = str_replace('##_ent_0D_##', ' ', $segment); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | // handling |
32 | - if ( strpos( $segment, '##_ent_0A_##' ) !== false ) { |
|
33 | - $segment = str_replace( '##_ent_0A_##', ' ', $segment ); |
|
32 | + if (strpos($segment, '##_ent_0A_##') !== false) { |
|
33 | + $segment = str_replace('##_ent_0A_##', ' ', $segment); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | // handling 	 (tab) |
37 | 37 | // prevent to convert it to \t |
38 | - if ( strpos( $segment, '##_ent_09_##' ) !== false ) { |
|
39 | - $segment = str_replace( '##_ent_09_##', '	', $segment ); |
|
38 | + if (strpos($segment, '##_ent_09_##') !== false) { |
|
39 | + $segment = str_replace('##_ent_09_##', '	', $segment); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | |
43 | 43 | //encode all not valid XML entities |
44 | - return preg_replace( '/&(?!lt;|gt;|amp;|quot;|apos;|#[x]{0,1}[0-9A-F]{1,7};)/', '&', $segment ); |
|
44 | + return preg_replace('/&(?!lt;|gt;|amp;|quot;|apos;|#[x]{0,1}[0-9A-F]{1,7};)/', '&', $segment); |
|
45 | 45 | } |
46 | 46 | } |
47 | 47 | \ No newline at end of file |
@@ -14,8 +14,8 @@ |
||
14 | 14 | |
15 | 15 | class EmojiToEntity extends AbstractHandler { |
16 | 16 | |
17 | - public function transform( string $segment ): string { |
|
18 | - return Emoji::toEntity( $segment ); |
|
17 | + public function transform(string $segment): string { |
|
18 | + return Emoji::toEntity($segment); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | } |
22 | 22 | \ No newline at end of file |
@@ -23,23 +23,23 @@ discard block |
||
23 | 23 | /** |
24 | 24 | * @inheritDoc |
25 | 25 | */ |
26 | - public function transform( string $segment ): string { |
|
26 | + public function transform(string $segment): string { |
|
27 | 27 | |
28 | - if ( empty( $this->dataRefMap ) ) { |
|
28 | + if (empty($this->dataRefMap)) { |
|
29 | 29 | $this->dataRefMap = $this->pipeline->getDataRefMap(); |
30 | 30 | } |
31 | 31 | |
32 | - if ( empty( $this->dataRefMap ) ) { |
|
33 | - $segment = $this->restoreXliffPhTagsFromMatecatPhTags( $segment ); |
|
32 | + if (empty($this->dataRefMap)) { |
|
33 | + $segment = $this->restoreXliffPhTagsFromMatecatPhTags($segment); |
|
34 | 34 | |
35 | - return $this->restoreXliffPcTagsFromMatecatPhTags( $segment ); |
|
35 | + return $this->restoreXliffPcTagsFromMatecatPhTags($segment); |
|
36 | 36 | } |
37 | 37 | |
38 | - $dataRefReplacer = new DataRefReplacer( $this->dataRefMap ); |
|
39 | - $segment = $dataRefReplacer->restore( $segment ); |
|
40 | - $segment = $this->restoreXliffPhTagsFromMatecatPhTags( $segment ); |
|
38 | + $dataRefReplacer = new DataRefReplacer($this->dataRefMap); |
|
39 | + $segment = $dataRefReplacer->restore($segment); |
|
40 | + $segment = $this->restoreXliffPhTagsFromMatecatPhTags($segment); |
|
41 | 41 | |
42 | - return $this->restoreXliffPcTagsFromMatecatPhTags( $segment ); |
|
42 | + return $this->restoreXliffPcTagsFromMatecatPhTags($segment); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -58,15 +58,15 @@ discard block |
||
58 | 58 | * |
59 | 59 | * @return string |
60 | 60 | */ |
61 | - private function restoreXliffPhTagsFromMatecatPhTags( string $segment ): string { |
|
62 | - preg_match_all( '|<ph[^>]+? ctype="' . CTypeEnum::ORIGINAL_PH_OR_NOT_DATA_REF . '" equiv-text="base64:(.*?)"/>|iu', $segment, $matches ); |
|
61 | + private function restoreXliffPhTagsFromMatecatPhTags(string $segment): string { |
|
62 | + preg_match_all('|<ph[^>]+? ctype="'.CTypeEnum::ORIGINAL_PH_OR_NOT_DATA_REF.'" equiv-text="base64:(.*?)"/>|iu', $segment, $matches); |
|
63 | 63 | |
64 | - if ( empty( $matches[ 0 ] ) ) { |
|
64 | + if (empty($matches[0])) { |
|
65 | 65 | return $segment; |
66 | 66 | } |
67 | 67 | |
68 | - foreach ( $matches[ 0 ] as $index => $match ) { |
|
69 | - $segment = str_replace( $match, base64_decode( $matches[ 1 ][ $index ] ), $segment ); |
|
68 | + foreach ($matches[0] as $index => $match) { |
|
69 | + $segment = str_replace($match, base64_decode($matches[1][$index]), $segment); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | return $segment; |
@@ -88,21 +88,21 @@ discard block |
||
88 | 88 | * |
89 | 89 | * @return string |
90 | 90 | */ |
91 | - private function restoreXliffPcTagsFromMatecatPhTags( string $segment ): string { |
|
91 | + private function restoreXliffPcTagsFromMatecatPhTags(string $segment): string { |
|
92 | 92 | |
93 | 93 | $matches = []; |
94 | - preg_match_all( '|<ph[^>]+? ctype="' . CTypeEnum::ORIGINAL_PC_OPEN_NO_DATA_REF . '" equiv-text="base64:(.*?)"/>|iu', $segment, $open_matches ); |
|
95 | - preg_match_all( '|<ph[^>]+? ctype="' . CTypeEnum::ORIGINAL_PC_CLOSE_NO_DATA_REF . '" equiv-text="base64:(.*?)"/>|iu', $segment, $close_matches ); |
|
94 | + preg_match_all('|<ph[^>]+? ctype="'.CTypeEnum::ORIGINAL_PC_OPEN_NO_DATA_REF.'" equiv-text="base64:(.*?)"/>|iu', $segment, $open_matches); |
|
95 | + preg_match_all('|<ph[^>]+? ctype="'.CTypeEnum::ORIGINAL_PC_CLOSE_NO_DATA_REF.'" equiv-text="base64:(.*?)"/>|iu', $segment, $close_matches); |
|
96 | 96 | |
97 | - $matches[ 0 ] = array_merge( $open_matches[ 0 ], $close_matches[ 0 ] ); |
|
98 | - $matches[ 1 ] = array_merge( $open_matches[ 1 ], $close_matches[ 1 ] ); |
|
97 | + $matches[0] = array_merge($open_matches[0], $close_matches[0]); |
|
98 | + $matches[1] = array_merge($open_matches[1], $close_matches[1]); |
|
99 | 99 | |
100 | - if ( empty( $matches[ 0 ] ) ) { |
|
100 | + if (empty($matches[0])) { |
|
101 | 101 | return $segment; |
102 | 102 | } |
103 | 103 | |
104 | - foreach ( $matches[ 0 ] as $index => $match ) { |
|
105 | - $segment = str_replace( $match, base64_decode( $matches[ 1 ][ $index ] ), $segment ); |
|
104 | + foreach ($matches[0] as $index => $match) { |
|
105 | + $segment = str_replace($match, base64_decode($matches[1][$index]), $segment); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | return $segment; |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | /** |
10 | 10 | * @inheritDoc |
11 | 11 | */ |
12 | - public function transform( string $segment ): string { |
|
12 | + public function transform(string $segment): string { |
|
13 | 13 | |
14 | 14 | $tags = [ |
15 | 15 | '\[%s\]', |
@@ -29,15 +29,15 @@ discard block |
||
29 | 29 | '\[%[a-z_]+:\d+%\]', |
30 | 30 | ]; |
31 | 31 | |
32 | - $regex = '/' . implode( "|", $tags ) . '/iu'; |
|
32 | + $regex = '/'.implode("|", $tags).'/iu'; |
|
33 | 33 | |
34 | - preg_match_all( $regex, $segment, $html, PREG_SET_ORDER ); |
|
34 | + preg_match_all($regex, $segment, $html, PREG_SET_ORDER); |
|
35 | 35 | |
36 | - foreach ( $html as $pos => $percentSnailVariable ) { |
|
36 | + foreach ($html as $pos => $percentSnailVariable) { |
|
37 | 37 | |
38 | 38 | $segment = preg_replace( |
39 | - '/' . preg_quote( $percentSnailVariable[ 0 ], '/' ) . '/', |
|
40 | - '<ph id="' . $this->getPipeline()->getNextId() . '" ctype="' . CTypeEnum::SQUARE_SPRINTF . '" equiv-text="base64:' . base64_encode( $percentSnailVariable[ 0 ] ) . '"/>', |
|
39 | + '/'.preg_quote($percentSnailVariable[0], '/').'/', |
|
40 | + '<ph id="'.$this->getPipeline()->getNextId().'" ctype="'.CTypeEnum::SQUARE_SPRINTF.'" equiv-text="base64:'.base64_encode($percentSnailVariable[0]).'"/>', |
|
41 | 41 | $segment, |
42 | 42 | 1 |
43 | 43 | ); |