@@ -23,23 +23,23 @@ discard block |
||
23 | 23 | /** |
24 | 24 | * @inheritDoc |
25 | 25 | */ |
26 | - public function transform( $segment ) { |
|
26 | + public function transform($segment) { |
|
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( $segment ) { |
|
62 | - preg_match_all( '|<ph[^>]+? ctype="' . CTypeEnum::ORIGINAL_PH_OR_NOT_DATA_REF . '" equiv-text="base64:(.*?)"/>|iu', $segment, $matches ); |
|
61 | + private function restoreXliffPhTagsFromMatecatPhTags($segment) { |
|
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( $segment ) { |
|
91 | + private function restoreXliffPcTagsFromMatecatPhTags($segment) { |
|
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; |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * |
28 | 28 | * @return string |
29 | 29 | */ |
30 | - public function transform( $segment ) { |
|
30 | + public function transform($segment) { |
|
31 | 31 | |
32 | 32 | /* |
33 | 33 | * Examples: |
@@ -36,14 +36,14 @@ discard block |
||
36 | 36 | * - %{vars} |
37 | 37 | * |
38 | 38 | */ |
39 | - preg_match_all( '/%{(?!<ph )[^{}]*?}/', $segment, $html, PREG_SET_ORDER ); |
|
40 | - foreach ( $html as $pos => $ruby_variable ) { |
|
39 | + preg_match_all('/%{(?!<ph )[^{}]*?}/', $segment, $html, PREG_SET_ORDER); |
|
40 | + foreach ($html as $pos => $ruby_variable) { |
|
41 | 41 | //check if inside twig variable there is a tag because in this case shouldn't replace the content with PH tag |
42 | - if ( !strstr( $ruby_variable[ 0 ], ConstantEnum::GTPLACEHOLDER ) ) { |
|
42 | + if (!strstr($ruby_variable[0], ConstantEnum::GTPLACEHOLDER)) { |
|
43 | 43 | //replace subsequent elements excluding already encoded |
44 | 44 | $segment = preg_replace( |
45 | - '/' . preg_quote( $ruby_variable[ 0 ], '/' ) . '/', |
|
46 | - '<ph id="' . $this->getPipeline()->getNextId() . '" ctype="' . CTypeEnum::RUBY_ON_RAILS . '" equiv-text="base64:' . base64_encode( $ruby_variable[ 0 ] ) . '"/>', |
|
45 | + '/'.preg_quote($ruby_variable[0], '/').'/', |
|
46 | + '<ph id="'.$this->getPipeline()->getNextId().'" ctype="'.CTypeEnum::RUBY_ON_RAILS.'" equiv-text="base64:'.base64_encode($ruby_variable[0]).'"/>', |
|
47 | 47 | $segment, |
48 | 48 | 1 |
49 | 49 | ); |
@@ -12,17 +12,17 @@ |
||
12 | 12 | * |
13 | 13 | * @return string |
14 | 14 | */ |
15 | - public function transform( $segment ) { |
|
15 | + public function transform($segment) { |
|
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 | ); |
@@ -27,15 +27,15 @@ |
||
27 | 27 | * |
28 | 28 | * @return string |
29 | 29 | */ |
30 | - public function transform( $segment ) { |
|
31 | - preg_match_all( '/%%[^<>\s%{}]+?%%/', $segment, $html, PREG_SET_ORDER ); // removed single percentage support '/(?<!{)%[^<>\s%]+?%/' |
|
32 | - foreach ( $html as $pos => $percentage_variable ) { |
|
30 | + public function transform($segment) { |
|
31 | + preg_match_all('/%%[^<>\s%{}]+?%%/', $segment, $html, PREG_SET_ORDER); // removed single percentage support '/(?<!{)%[^<>\s%]+?%/' |
|
32 | + foreach ($html as $pos => $percentage_variable) { |
|
33 | 33 | //check if inside twig variable there is a tag because in this case shouldn't replace the content with PH tag |
34 | - if ( !strstr( $percentage_variable[ 0 ], ConstantEnum::GTPLACEHOLDER ) ) { |
|
34 | + if (!strstr($percentage_variable[0], ConstantEnum::GTPLACEHOLDER)) { |
|
35 | 35 | //replace subsequent elements excluding already encoded |
36 | 36 | $segment = preg_replace( |
37 | - '/' . preg_quote( $percentage_variable[ 0 ], '/' ) . '/', |
|
38 | - '<ph id="' . $this->getPipeline()->getNextId() . '" ctype="' . CTypeEnum::PERCENTAGES . '" equiv-text="base64:' . base64_encode( $percentage_variable[ 0 ] ) . '"/>', |
|
37 | + '/'.preg_quote($percentage_variable[0], '/').'/', |
|
38 | + '<ph id="'.$this->getPipeline()->getNextId().'" ctype="'.CTypeEnum::PERCENTAGES.'" equiv-text="base64:'.base64_encode($percentage_variable[0]).'"/>', |
|
39 | 39 | $segment, |
40 | 40 | 1 |
41 | 41 | ); |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @param Pipeline $pipeline |
49 | 49 | */ |
50 | - public function __construct( Pipeline $pipeline = null ) { |
|
50 | + public function __construct(Pipeline $pipeline = null) { |
|
51 | 51 | $this->pipeline = $pipeline; |
52 | 52 | } |
53 | 53 | |
@@ -56,10 +56,10 @@ discard block |
||
56 | 56 | */ |
57 | 57 | protected $callbacksHandler; |
58 | 58 | |
59 | - public function registerCallbacksHandler( $class ) { |
|
59 | + public function registerCallbacksHandler($class) { |
|
60 | 60 | //check: $class must use CallbacksHandler trait |
61 | - if ( !in_array( CallbacksHandler::class, class_uses( $class ) ) ) { |
|
62 | - throw new RuntimeException( "Class passed to " . __METHOD__ . " must use " . CallbacksHandler::class . " trait." ); |
|
61 | + if (!in_array(CallbacksHandler::class, class_uses($class))) { |
|
62 | + throw new RuntimeException("Class passed to ".__METHOD__." must use ".CallbacksHandler::class." trait."); |
|
63 | 63 | } |
64 | 64 | $this->callbacksHandler = $class; |
65 | 65 | } |
@@ -71,25 +71,25 @@ discard block |
||
71 | 71 | * @return mixed |
72 | 72 | * @throws ReflectionException |
73 | 73 | */ |
74 | - public function __call( $name, $arguments ) { |
|
74 | + public function __call($name, $arguments) { |
|
75 | 75 | |
76 | - if ( $this->callbacksHandler !== null ) { |
|
76 | + if ($this->callbacksHandler !== null) { |
|
77 | 77 | //Reflection to allow protected/private methods to be set as callback |
78 | - $reflector = new ReflectionMethod( $this->callbacksHandler, $name ); |
|
79 | - if ( !$reflector->isPublic() ) { |
|
80 | - $reflector->setAccessible( true ); |
|
78 | + $reflector = new ReflectionMethod($this->callbacksHandler, $name); |
|
79 | + if (!$reflector->isPublic()) { |
|
80 | + $reflector->setAccessible(true); |
|
81 | 81 | } |
82 | 82 | |
83 | - return $reflector->invoke( $this->callbacksHandler, $arguments[ 0 ] ); |
|
83 | + return $reflector->invoke($this->callbacksHandler, $arguments[0]); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | return null; |
87 | 87 | |
88 | 88 | } |
89 | 89 | |
90 | - public function transform( $segment ) { |
|
90 | + public function transform($segment) { |
|
91 | 91 | |
92 | - $originalSplit = preg_split( '//u', $segment, -1, PREG_SPLIT_NO_EMPTY ); |
|
92 | + $originalSplit = preg_split('//u', $segment, -1, PREG_SPLIT_NO_EMPTY); |
|
93 | 93 | |
94 | 94 | $state = static::STATE_PLAINTEXT; |
95 | 95 | $html_buffer = ''; |
@@ -97,14 +97,14 @@ discard block |
||
97 | 97 | $in_quote_char = ''; |
98 | 98 | $output = ''; |
99 | 99 | |
100 | - foreach ( $originalSplit as $idx => $char ) { |
|
100 | + foreach ($originalSplit as $idx => $char) { |
|
101 | 101 | |
102 | - if ( $state == static::STATE_PLAINTEXT ) { |
|
103 | - switch ( $char ) { |
|
102 | + if ($state == static::STATE_PLAINTEXT) { |
|
103 | + switch ($char) { |
|
104 | 104 | case '<': |
105 | 105 | $state = static::STATE_HTML; |
106 | 106 | $html_buffer .= $char; |
107 | - $output .= $this->_finalizePlainText( $plain_text_buffer ); |
|
107 | + $output .= $this->_finalizePlainText($plain_text_buffer); |
|
108 | 108 | $plain_text_buffer = ''; |
109 | 109 | break; |
110 | 110 | |
@@ -117,15 +117,15 @@ discard block |
||
117 | 117 | // otherwise is ignored and leaved as >. |
118 | 118 | // |
119 | 119 | case '>': |
120 | - $plain_text_buffer .= $this->_fixWrongBuffer( $char ); |
|
120 | + $plain_text_buffer .= $this->_fixWrongBuffer($char); |
|
121 | 121 | break; |
122 | 122 | |
123 | 123 | default: |
124 | 124 | $plain_text_buffer .= $char; |
125 | 125 | break; |
126 | 126 | } |
127 | - } elseif ( $state == static::STATE_HTML ) { |
|
128 | - switch ( $char ) { |
|
127 | + } elseif ($state == static::STATE_HTML) { |
|
128 | + switch ($char) { |
|
129 | 129 | case '<': |
130 | 130 | // is not possible to have angle brackets inside a tag, this case can not happen |
131 | 131 | // this code would ignore '>' if inside a quote, useless |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | |
134 | 134 | // if we found a second less than symbol the first one IS NOT a tag, |
135 | 135 | // treat the html_buffer as plain text and attach to the output |
136 | - $output .= $this->_fixWrongBuffer( $html_buffer ); |
|
136 | + $output .= $this->_fixWrongBuffer($html_buffer); |
|
137 | 137 | $html_buffer = $char; |
138 | 138 | break; |
139 | 139 | |
@@ -142,24 +142,24 @@ discard block |
||
142 | 142 | // this code would ignore '>' if inside a quote, useless |
143 | 143 | // for more info see https://www.w3.org/TR/xml/#charsets |
144 | 144 | |
145 | - if ( in_array( substr( $html_buffer, 0, 8 ), [ '<script ', '<style', '<script', '<style ' ] ) ) { |
|
145 | + if (in_array(substr($html_buffer, 0, 8), ['<script ', '<style', '<script', '<style '])) { |
|
146 | 146 | $html_buffer .= $char; |
147 | - $state = static::STATE_JS_CSS; |
|
147 | + $state = static::STATE_JS_CSS; |
|
148 | 148 | break; |
149 | 149 | } |
150 | 150 | |
151 | 151 | // this is closing the tag in tag_buffer |
152 | 152 | $in_quote_char = ''; |
153 | 153 | $state = static::STATE_PLAINTEXT; |
154 | - $html_buffer .= $char; |
|
154 | + $html_buffer .= $char; |
|
155 | 155 | |
156 | - if ( $this->_isTagValid( $html_buffer ) ) { |
|
157 | - $output .= $this->_finalizeHTMLTag( $html_buffer ); |
|
156 | + if ($this->_isTagValid($html_buffer)) { |
|
157 | + $output .= $this->_finalizeHTMLTag($html_buffer); |
|
158 | 158 | } else { |
159 | - $output .= $this->_fixWrongBuffer( $html_buffer ); |
|
159 | + $output .= $this->_fixWrongBuffer($html_buffer); |
|
160 | 160 | } |
161 | 161 | |
162 | - if ( $this->_isTagValid( $html_buffer ) and null !== $this->pipeline ) { |
|
162 | + if ($this->_isTagValid($html_buffer) and null !== $this->pipeline) { |
|
163 | 163 | $this->_setSegmentContainsHtml(); |
164 | 164 | } |
165 | 165 | |
@@ -170,17 +170,17 @@ discard block |
||
170 | 170 | case '\'': |
171 | 171 | // catch both single and double quotes |
172 | 172 | |
173 | - if ( $char == $in_quote_char ) { |
|
173 | + if ($char == $in_quote_char) { |
|
174 | 174 | $in_quote_char = ''; |
175 | 175 | } else { |
176 | - $in_quote_char = ( !empty( $in_quote_char ) ? $in_quote_char : $char ); |
|
176 | + $in_quote_char = (!empty($in_quote_char) ? $in_quote_char : $char); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | $html_buffer .= $char; |
180 | 180 | break; |
181 | 181 | |
182 | 182 | case '-': |
183 | - if ( $html_buffer == '<!-' ) { |
|
183 | + if ($html_buffer == '<!-') { |
|
184 | 184 | $state = static::STATE_COMMENT; |
185 | 185 | } |
186 | 186 | |
@@ -189,12 +189,12 @@ discard block |
||
189 | 189 | |
190 | 190 | case ' ': //0x20, is a space |
191 | 191 | case '\n': |
192 | - if ( $html_buffer === '<' ) { |
|
192 | + if ($html_buffer === '<') { |
|
193 | 193 | $state = static::STATE_PLAINTEXT; // but we work in XML text, so encode it |
194 | - $output .= $this->_fixWrongBuffer( '< ' ); |
|
194 | + $output .= $this->_fixWrongBuffer('< '); |
|
195 | 195 | $html_buffer = ''; |
196 | 196 | |
197 | - if ( $this->_isTagValid( $html_buffer ) and null !== $this->pipeline ) { |
|
197 | + if ($this->_isTagValid($html_buffer) and null !== $this->pipeline) { |
|
198 | 198 | $this->_setSegmentContainsHtml(); |
199 | 199 | } |
200 | 200 | |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | default: |
208 | 208 | |
209 | 209 | // Check the last char |
210 | - if ( $idx === ( count( $originalSplit ) - 1 ) ) { |
|
210 | + if ($idx === (count($originalSplit) - 1)) { |
|
211 | 211 | |
212 | 212 | $html_buffer .= $char; |
213 | 213 | |
@@ -225,12 +225,12 @@ discard block |
||
225 | 225 | // |
226 | 226 | // is not a valid tag, so it's converted to $plain_text_buffer |
227 | 227 | // |
228 | - if ( !$this->_isTagValid( $html_buffer ) ) { |
|
228 | + if (!$this->_isTagValid($html_buffer)) { |
|
229 | 229 | $state = static::STATE_PLAINTEXT; // but we work in XML text, so encode it |
230 | - $plain_text_buffer .= $this->_fixWrongBuffer( $html_buffer ); |
|
230 | + $plain_text_buffer .= $this->_fixWrongBuffer($html_buffer); |
|
231 | 231 | $html_buffer = ''; |
232 | 232 | |
233 | - if ( $this->_isTagValid( $html_buffer ) and null !== $this->pipeline ) { |
|
233 | + if ($this->_isTagValid($html_buffer) and null !== $this->pipeline) { |
|
234 | 234 | $this->_setSegmentContainsHtml(); |
235 | 235 | } |
236 | 236 | |
@@ -243,35 +243,35 @@ discard block |
||
243 | 243 | $html_buffer .= $char; |
244 | 244 | break; |
245 | 245 | } |
246 | - } elseif ( $state == static::STATE_COMMENT ) { |
|
246 | + } elseif ($state == static::STATE_COMMENT) { |
|
247 | 247 | |
248 | 248 | $html_buffer .= $char; |
249 | 249 | |
250 | - if ( $char == '>' ) { |
|
251 | - if ( substr( $html_buffer, -3 ) == '-->' ) { |
|
250 | + if ($char == '>') { |
|
251 | + if (substr($html_buffer, -3) == '-->') { |
|
252 | 252 | // close the comment |
253 | 253 | $state = static::STATE_PLAINTEXT; |
254 | - $output .= $this->_finalizeScriptTag( $html_buffer ); |
|
254 | + $output .= $this->_finalizeScriptTag($html_buffer); |
|
255 | 255 | $html_buffer = ''; |
256 | 256 | |
257 | - if ( $this->_isTagValid( $html_buffer ) and null !== $this->pipeline ) { |
|
257 | + if ($this->_isTagValid($html_buffer) and null !== $this->pipeline) { |
|
258 | 258 | $this->_setSegmentContainsHtml(); |
259 | 259 | } |
260 | 260 | } |
261 | 261 | } |
262 | 262 | |
263 | - } elseif ( $state == static::STATE_JS_CSS ) { |
|
263 | + } elseif ($state == static::STATE_JS_CSS) { |
|
264 | 264 | |
265 | 265 | $html_buffer .= $char; |
266 | 266 | |
267 | - if ( $char == '>' ) { |
|
268 | - if ( in_array( substr( $html_buffer, -6 ), [ 'cript>', 'style>' ] ) ) { |
|
267 | + if ($char == '>') { |
|
268 | + if (in_array(substr($html_buffer, -6), ['cript>', 'style>'])) { |
|
269 | 269 | // close the comment |
270 | 270 | $state = static::STATE_PLAINTEXT; |
271 | - $output .= $this->_finalizeScriptTag( $html_buffer ); |
|
271 | + $output .= $this->_finalizeScriptTag($html_buffer); |
|
272 | 272 | $html_buffer = ''; |
273 | 273 | |
274 | - if ( $this->_isTagValid( $html_buffer ) and null !== $this->pipeline ) { |
|
274 | + if ($this->_isTagValid($html_buffer) and null !== $this->pipeline) { |
|
275 | 275 | $this->_setSegmentContainsHtml(); |
276 | 276 | } |
277 | 277 | } |
@@ -281,18 +281,18 @@ discard block |
||
281 | 281 | } |
282 | 282 | |
283 | 283 | //HTML Partial, add wrong HTML to preserve string content |
284 | - if ( !empty( $html_buffer ) ) { |
|
284 | + if (!empty($html_buffer)) { |
|
285 | 285 | |
286 | - if ( $this->_isTagValid( $html_buffer ) and null !== $this->pipeline ) { |
|
286 | + if ($this->_isTagValid($html_buffer) and null !== $this->pipeline) { |
|
287 | 287 | $this->_setSegmentContainsHtml(); |
288 | 288 | } |
289 | 289 | |
290 | - $output .= $this->_fixWrongBuffer( $html_buffer ); |
|
290 | + $output .= $this->_fixWrongBuffer($html_buffer); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | //string ends with plain text, so no state change is triggered at the end of string |
294 | - if ( '' !== $plain_text_buffer and null !== $plain_text_buffer ) { |
|
295 | - $output .= $this->_finalizePlainText( $plain_text_buffer ); |
|
294 | + if ('' !== $plain_text_buffer and null !== $plain_text_buffer) { |
|
295 | + $output .= $this->_finalizePlainText($plain_text_buffer); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | return $output; |
@@ -21,15 +21,15 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * @param array $list |
23 | 23 | */ |
24 | - public function __construct( array $list = [] ) { |
|
25 | - if ( !empty( $list ) && !Utils::array_is_list( $list ) ) { |
|
26 | - throw new DomainException( "Invalid list provided" ); |
|
24 | + public function __construct(array $list = []) { |
|
25 | + if (!empty($list) && !Utils::array_is_list($list)) { |
|
26 | + throw new DomainException("Invalid list provided"); |
|
27 | 27 | } |
28 | - parent::__construct( $list ); |
|
28 | + parent::__construct($list); |
|
29 | 29 | } |
30 | 30 | |
31 | - public static function instance( array $list = [] ) { |
|
32 | - return new static( $list ); |
|
31 | + public static function instance(array $list = []) { |
|
32 | + return new static($list); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -37,9 +37,9 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @return false|mixed|null |
39 | 39 | */ |
40 | - public function offsetGet( $key ) { |
|
41 | - if ( $this->offsetExists( $key ) ) { |
|
42 | - return parent::offsetGet( $key ); |
|
40 | + public function offsetGet($key) { |
|
41 | + if ($this->offsetExists($key)) { |
|
42 | + return parent::offsetGet($key); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | return null; |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @return false|mixed|null the element at the specified position in this list |
54 | 54 | */ |
55 | - public function get( $key ) { |
|
56 | - return $this->offsetGet( $key ); |
|
55 | + public function get($key) { |
|
56 | + return $this->offsetGet($key); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | * |
64 | 64 | * @return true |
65 | 65 | */ |
66 | - public function add( $value ) { |
|
67 | - parent::append( $value ); |
|
66 | + public function add($value) { |
|
67 | + parent::append($value); |
|
68 | 68 | return true; |
69 | 69 | } |
70 | 70 |
@@ -27,9 +27,9 @@ discard block |
||
27 | 27 | */ |
28 | 28 | private $map; |
29 | 29 | |
30 | - public function __construct( array $map ) { |
|
31 | - if ( !empty( $map ) && Utils::array_is_list( $map ) ) { |
|
32 | - throw new DomainException( "Invalid map provided" ); |
|
30 | + public function __construct(array $map) { |
|
31 | + if (!empty($map) && Utils::array_is_list($map)) { |
|
32 | + throw new DomainException("Invalid map provided"); |
|
33 | 33 | } |
34 | 34 | $this->map = $map; |
35 | 35 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * @return int |
39 | 39 | */ |
40 | 40 | public function count() { |
41 | - return sizeof( $this->map ); |
|
41 | + return sizeof($this->map); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | * @return ArrayIterator |
47 | 47 | */ |
48 | 48 | public function getIterator() { |
49 | - return new ArrayIterator( $this->map ); |
|
49 | + return new ArrayIterator($this->map); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -54,8 +54,8 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @return bool |
56 | 56 | */ |
57 | - public function offsetExists( $offset ) { |
|
58 | - return array_key_exists( $offset, $this->map ); |
|
57 | + public function offsetExists($offset) { |
|
58 | + return array_key_exists($offset, $this->map); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | * |
64 | 64 | * @return mixed|null |
65 | 65 | */ |
66 | - public function offsetGet( $offset ) { |
|
67 | - return $this->get( $offset ); |
|
66 | + public function offsetGet($offset) { |
|
67 | + return $this->get($offset); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | * |
74 | 74 | * @return void |
75 | 75 | */ |
76 | - public function offsetSet( $offset, $value ) { |
|
77 | - $this->put( $offset, $value ); |
|
76 | + public function offsetSet($offset, $value) { |
|
77 | + $this->put($offset, $value); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -82,8 +82,8 @@ discard block |
||
82 | 82 | * |
83 | 83 | * @return void |
84 | 84 | */ |
85 | - public function offsetUnset( $offset ) { |
|
86 | - $this->remove( $offset ); |
|
85 | + public function offsetUnset($offset) { |
|
86 | + $this->remove($offset); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -93,8 +93,8 @@ discard block |
||
93 | 93 | * |
94 | 94 | * @return static |
95 | 95 | */ |
96 | - public static function instance( array $map = [] ) { |
|
97 | - return new static( $map ); |
|
96 | + public static function instance(array $map = []) { |
|
97 | + return new static($map); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | * |
105 | 105 | * @return mixed|null |
106 | 106 | */ |
107 | - public function get( $needle ) { |
|
108 | - return $this->getOrDefault( $needle, null ); |
|
107 | + public function get($needle) { |
|
108 | + return $this->getOrDefault($needle, null); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -114,8 +114,8 @@ discard block |
||
114 | 114 | * |
115 | 115 | * @return mixed |
116 | 116 | */ |
117 | - public function getOrDefault( $needle, $default ) { |
|
118 | - return array_key_exists( $needle, $this->map ) ? $this->map [ $needle ] : $default; |
|
117 | + public function getOrDefault($needle, $default) { |
|
118 | + return array_key_exists($needle, $this->map) ? $this->map [$needle] : $default; |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -131,11 +131,11 @@ discard block |
||
131 | 131 | * @return $this |
132 | 132 | */ |
133 | 133 | public function __clone() { |
134 | - return new static( $this->map ); |
|
134 | + return new static($this->map); |
|
135 | 135 | } |
136 | 136 | |
137 | - public function containsKey( $offset ) { |
|
138 | - return array_key_exists( $offset, $this->map ); |
|
137 | + public function containsKey($offset) { |
|
138 | + return array_key_exists($offset, $this->map); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | * |
147 | 147 | * @return boolean |
148 | 148 | */ |
149 | - public function containsValue( $value ) { |
|
150 | - return !empty( array_search( $value, $this->map, true ) ); |
|
149 | + public function containsValue($value) { |
|
150 | + return !empty(array_search($value, $this->map, true)); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -158,9 +158,9 @@ discard block |
||
158 | 158 | * |
159 | 159 | * @return Generator |
160 | 160 | */ |
161 | - public function for_each( callable $callable ) { |
|
162 | - foreach ( $this->map as $k => $v ) { |
|
163 | - $callable( $k, $v ); |
|
161 | + public function for_each(callable $callable) { |
|
162 | + foreach ($this->map as $k => $v) { |
|
163 | + $callable($k, $v); |
|
164 | 164 | } |
165 | 165 | } |
166 | 166 | |
@@ -170,14 +170,14 @@ discard block |
||
170 | 170 | * @return bool |
171 | 171 | */ |
172 | 172 | public function isEmpty() { |
173 | - return empty( $this->map ); |
|
173 | + return empty($this->map); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
177 | 177 | * @return string[] |
178 | 178 | */ |
179 | 179 | public function keySet() { |
180 | - return array_keys( $this->map ); |
|
180 | + return array_keys($this->map); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -188,9 +188,9 @@ discard block |
||
188 | 188 | * |
189 | 189 | * @return mixed|null the previous value associated with `key`, or null if there was no mapping for `key`. |
190 | 190 | */ |
191 | - public function put( $offset, $value ) { |
|
192 | - $previousValue = $this->get( $offset ); |
|
193 | - $this->map[ $offset ] = $value; |
|
191 | + public function put($offset, $value) { |
|
192 | + $previousValue = $this->get($offset); |
|
193 | + $this->map[$offset] = $value; |
|
194 | 194 | |
195 | 195 | return $previousValue; |
196 | 196 | } |
@@ -200,9 +200,9 @@ discard block |
||
200 | 200 | * |
201 | 201 | * @return void |
202 | 202 | */ |
203 | - public function putAll( $map ) { |
|
204 | - foreach ( $map as $k => $v ) { |
|
205 | - $this->map[ $k ] = $v; |
|
203 | + public function putAll($map) { |
|
204 | + foreach ($map as $k => $v) { |
|
205 | + $this->map[$k] = $v; |
|
206 | 206 | } |
207 | 207 | } |
208 | 208 | |
@@ -215,10 +215,10 @@ discard block |
||
215 | 215 | * @return mixed|null the previous value associated with the specified key, or null if there was no mapping for the key. |
216 | 216 | * A null return can also indicate that the map previously associated null with the `key` |
217 | 217 | */ |
218 | - public function putIfAbsent( $offset, $value ) { |
|
219 | - $previousValue = $this->get( $offset ); |
|
220 | - if ( $previousValue === null ) { |
|
221 | - $this->map[ $offset ] = $value; |
|
218 | + public function putIfAbsent($offset, $value) { |
|
219 | + $previousValue = $this->get($offset); |
|
220 | + if ($previousValue === null) { |
|
221 | + $this->map[$offset] = $value; |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | return $previousValue; |
@@ -231,10 +231,10 @@ discard block |
||
231 | 231 | * |
232 | 232 | * @return bool true if the value was removed |
233 | 233 | */ |
234 | - public function remove( $offset ) { |
|
235 | - $exists = array_key_exists( $offset, $this->map ); |
|
236 | - if ( $exists ) { |
|
237 | - unset( $this->map[ $offset ] ); |
|
234 | + public function remove($offset) { |
|
235 | + $exists = array_key_exists($offset, $this->map); |
|
236 | + if ($exists) { |
|
237 | + unset($this->map[$offset]); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | return $exists; |
@@ -246,11 +246,11 @@ discard block |
||
246 | 246 | * @return mixed|null the previous value associated with the specified key, or null if there was no mapping for the key. |
247 | 247 | * A null return can also indicate that the map previously associated null with the key. |
248 | 248 | */ |
249 | - public function replace( $offset, $value ) { |
|
250 | - $exists = array_key_exists( $offset, $this->map ); |
|
251 | - $previousValue = $this->get( $offset ); |
|
252 | - if ( $exists ) { |
|
253 | - $this->map[ $offset ] = $value; |
|
249 | + public function replace($offset, $value) { |
|
250 | + $exists = array_key_exists($offset, $this->map); |
|
251 | + $previousValue = $this->get($offset); |
|
252 | + if ($exists) { |
|
253 | + $this->map[$offset] = $value; |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | return $previousValue; |
@@ -265,11 +265,11 @@ discard block |
||
265 | 265 | * |
266 | 266 | * @return boolean true if the value was replaced |
267 | 267 | */ |
268 | - public function replaceIfEquals( $offset, $newValue, $oldValue ) { |
|
269 | - $exists = array_key_exists( $offset, $this->map ); |
|
270 | - $previousValue = $this->get( $offset ); |
|
271 | - if ( $exists && $previousValue === $oldValue ) { |
|
272 | - $this->map[ $offset ] = $newValue; |
|
268 | + public function replaceIfEquals($offset, $newValue, $oldValue) { |
|
269 | + $exists = array_key_exists($offset, $this->map); |
|
270 | + $previousValue = $this->get($offset); |
|
271 | + if ($exists && $previousValue === $oldValue) { |
|
272 | + $this->map[$offset] = $newValue; |
|
273 | 273 | |
274 | 274 | return true; |
275 | 275 | } |
@@ -286,9 +286,9 @@ discard block |
||
286 | 286 | * |
287 | 287 | * @return void |
288 | 288 | */ |
289 | - public function replaceAll( callable $callable ) { |
|
290 | - foreach ( $this->map as $offset => $value ) { |
|
291 | - $this->map[ $offset ] = $callable( $offset, $value ); |
|
289 | + public function replaceAll(callable $callable) { |
|
290 | + foreach ($this->map as $offset => $value) { |
|
291 | + $this->map[$offset] = $callable($offset, $value); |
|
292 | 292 | } |
293 | 293 | } |
294 | 294 | |
@@ -296,14 +296,14 @@ discard block |
||
296 | 296 | * @return int |
297 | 297 | */ |
298 | 298 | public function size() { |
299 | - return sizeof( $this->map ); |
|
299 | + return sizeof($this->map); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
303 | 303 | * @return array |
304 | 304 | */ |
305 | 305 | public function values() { |
306 | - return array_values( $this->map ); |
|
306 | + return array_values($this->map); |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | /** |
@@ -322,16 +322,16 @@ discard block |
||
322 | 322 | * |
323 | 323 | * @return mixed|null the new value associated with the specified key, or null if none |
324 | 324 | */ |
325 | - public function compute( $offset, callable $callable ) { |
|
326 | - $exists = array_key_exists( $offset, $this->map ); |
|
327 | - if ( $exists ) { |
|
328 | - $res = $callable( $offset, $this->get( $offset ) ); |
|
329 | - if ( $res == null ) { |
|
330 | - unset( $this->map[ $offset ] ); |
|
325 | + public function compute($offset, callable $callable) { |
|
326 | + $exists = array_key_exists($offset, $this->map); |
|
327 | + if ($exists) { |
|
328 | + $res = $callable($offset, $this->get($offset)); |
|
329 | + if ($res == null) { |
|
330 | + unset($this->map[$offset]); |
|
331 | 331 | } else { |
332 | - $this->map[ $offset ] = $callable( $offset, $this->get( $offset ) ); |
|
332 | + $this->map[$offset] = $callable($offset, $this->get($offset)); |
|
333 | 333 | |
334 | - return $this->map[ $offset ]; |
|
334 | + return $this->map[$offset]; |
|
335 | 335 | } |
336 | 336 | } |
337 | 337 | |
@@ -352,14 +352,14 @@ discard block |
||
352 | 352 | * |
353 | 353 | * @return mixed|null the current (existing or computed) value associated with the specified key, or null if the computed value is null |
354 | 354 | */ |
355 | - public function computeIfAbsent( $offset, callable $callable ) { |
|
356 | - $exists = array_key_exists( $offset, $this->map ); |
|
357 | - $previousValue = $this->get( $offset ); |
|
355 | + public function computeIfAbsent($offset, callable $callable) { |
|
356 | + $exists = array_key_exists($offset, $this->map); |
|
357 | + $previousValue = $this->get($offset); |
|
358 | 358 | $res = null; |
359 | - if ( !$exists || $previousValue === null ) { |
|
360 | - $res = $callable( $offset, $this->get( $offset ) ); |
|
361 | - if ( $res != null ) { |
|
362 | - $this->map[ $offset ] = $res; |
|
359 | + if (!$exists || $previousValue === null) { |
|
360 | + $res = $callable($offset, $this->get($offset)); |
|
361 | + if ($res != null) { |
|
362 | + $this->map[$offset] = $res; |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | } |
@@ -379,16 +379,16 @@ discard block |
||
379 | 379 | * |
380 | 380 | * @return mixed|null the new value associated with the specified key, or null if none |
381 | 381 | */ |
382 | - public function computeIfPresent( $offset, callable $callable ) { |
|
383 | - $exists = array_key_exists( $offset, $this->map ); |
|
384 | - $previousValue = $this->get( $offset ); |
|
382 | + public function computeIfPresent($offset, callable $callable) { |
|
383 | + $exists = array_key_exists($offset, $this->map); |
|
384 | + $previousValue = $this->get($offset); |
|
385 | 385 | $res = null; |
386 | - if ( $exists && $previousValue !== null ) { |
|
387 | - $res = $callable( $offset, $this->map[ $offset ] ); |
|
388 | - if ( $res == null ) { |
|
389 | - unset( $this->map[ $offset ] ); |
|
386 | + if ($exists && $previousValue !== null) { |
|
387 | + $res = $callable($offset, $this->map[$offset]); |
|
388 | + if ($res == null) { |
|
389 | + unset($this->map[$offset]); |
|
390 | 390 | } else { |
391 | - $this->map[ $offset ] = $res; |
|
391 | + $this->map[$offset] = $res; |
|
392 | 392 | } |
393 | 393 | } |
394 | 394 |
@@ -9,18 +9,18 @@ discard block |
||
9 | 9 | * |
10 | 10 | * @return bool |
11 | 11 | */ |
12 | - public static function array_is_list( $array ) { |
|
12 | + public static function array_is_list($array) { |
|
13 | 13 | |
14 | - if ( !function_exists( 'array_is_list' ) ) { // since php 8.1 |
|
14 | + if (!function_exists('array_is_list')) { // since php 8.1 |
|
15 | 15 | |
16 | - if ( $array === [] ) { |
|
16 | + if ($array === []) { |
|
17 | 17 | return true; |
18 | 18 | } |
19 | 19 | |
20 | - return array_keys( $array ) === range( 0, count( $array ) - 1 ); |
|
20 | + return array_keys($array) === range(0, count($array) - 1); |
|
21 | 21 | } |
22 | 22 | |
23 | - return array_is_list( $array ); |
|
23 | + return array_is_list($array); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -29,8 +29,8 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @return bool |
31 | 31 | */ |
32 | - public static function contains( $needle, $haystack ) { |
|
33 | - return strpos( $haystack, $needle ) !== false; |
|
32 | + public static function contains($needle, $haystack) { |
|
33 | + return strpos($haystack, $needle) !== false; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -43,22 +43,22 @@ discard block |
||
43 | 43 | * @return int |
44 | 44 | * |
45 | 45 | */ |
46 | - public static function fastUnicode2ord( $mb_char ) { |
|
47 | - switch ( strlen( $mb_char ) ) { |
|
46 | + public static function fastUnicode2ord($mb_char) { |
|
47 | + switch (strlen($mb_char)) { |
|
48 | 48 | case 1: |
49 | - return ord( $mb_char ); |
|
49 | + return ord($mb_char); |
|
50 | 50 | case 2: |
51 | - return ( ord( $mb_char[ 0 ] ) - 0xC0 ) * 0x40 + |
|
52 | - ord( $mb_char[ 1 ] ) - 0x80; |
|
51 | + return (ord($mb_char[0]) - 0xC0) * 0x40 + |
|
52 | + ord($mb_char[1]) - 0x80; |
|
53 | 53 | case 3: |
54 | - return ( ord( $mb_char[ 0 ] ) - 0xE0 ) * 0x1000 + |
|
55 | - ( ord( $mb_char[ 1 ] ) - 0x80 ) * 0x40 + |
|
56 | - ord( $mb_char[ 2 ] ) - 0x80; |
|
54 | + return (ord($mb_char[0]) - 0xE0) * 0x1000 + |
|
55 | + (ord($mb_char[1]) - 0x80) * 0x40 + |
|
56 | + ord($mb_char[2]) - 0x80; |
|
57 | 57 | case 4: |
58 | - return ( ord( $mb_char[ 0 ] ) - 0xF0 ) * 0x40000 + |
|
59 | - ( ord( $mb_char[ 1 ] ) - 0x80 ) * 0x1000 + |
|
60 | - ( ord( $mb_char[ 2 ] ) - 0x80 ) * 0x40 + |
|
61 | - ord( $mb_char[ 3 ] ) - 0x80; |
|
58 | + return (ord($mb_char[0]) - 0xF0) * 0x40000 + |
|
59 | + (ord($mb_char[1]) - 0x80) * 0x1000 + |
|
60 | + (ord($mb_char[2]) - 0x80) * 0x40 + |
|
61 | + ord($mb_char[3]) - 0x80; |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | return 20; //as default return a space ( should never happen ) |
@@ -69,8 +69,8 @@ discard block |
||
69 | 69 | * |
70 | 70 | * @return string |
71 | 71 | */ |
72 | - public static function htmlentitiesFromUnicode( $str ) { |
|
73 | - return "&#" . self::fastUnicode2ord( $str[ 1 ] ) . ";"; |
|
72 | + public static function htmlentitiesFromUnicode($str) { |
|
73 | + return "&#".self::fastUnicode2ord($str[1]).";"; |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -83,11 +83,11 @@ discard block |
||
83 | 83 | * |
84 | 84 | * @return string |
85 | 85 | */ |
86 | - public static function unicode2chr( $o ) { |
|
87 | - if ( function_exists( 'mb_convert_encoding' ) ) { |
|
88 | - return mb_convert_encoding( '&#' . intval( $o ) . ';', 'UTF-8', 'HTML-ENTITIES' ); |
|
86 | + public static function unicode2chr($o) { |
|
87 | + if (function_exists('mb_convert_encoding')) { |
|
88 | + return mb_convert_encoding('&#'.intval($o).';', 'UTF-8', 'HTML-ENTITIES'); |
|
89 | 89 | } |
90 | 90 | |
91 | - return chr( intval( $o ) ); |
|
91 | + return chr(intval($o)); |
|
92 | 92 | } |
93 | 93 | } |
94 | 94 | \ No newline at end of file |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | */ |
33 | 33 | private $segmentContainsHtml = false; |
34 | 34 | |
35 | - public function __construct( $source = null, $target = null, $dataRefMap = [] ) { |
|
35 | + public function __construct($source = null, $target = null, $dataRefMap = []) { |
|
36 | 36 | $this->source = $source; |
37 | 37 | $this->target = $target; |
38 | 38 | $this->dataRefMap = $dataRefMap; |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | public function getNextId() { |
42 | 42 | $this->id_number++; |
43 | 43 | |
44 | - return ConstantEnum::INTERNAL_ATTR_ID_PREFIX . $this->id_number; |
|
44 | + return ConstantEnum::INTERNAL_ATTR_ID_PREFIX.$this->id_number; |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | public function resetId() { |
@@ -86,9 +86,9 @@ discard block |
||
86 | 86 | * |
87 | 87 | * @return Pipeline |
88 | 88 | */ |
89 | - public function addFirst( AbstractHandler $handler ) { |
|
90 | - $this->_register( $handler ); |
|
91 | - array_unshift( $this->handlers, $handler ); |
|
89 | + public function addFirst(AbstractHandler $handler) { |
|
90 | + $this->_register($handler); |
|
91 | + array_unshift($this->handlers, $handler); |
|
92 | 92 | |
93 | 93 | return $this; |
94 | 94 | } |
@@ -99,11 +99,11 @@ discard block |
||
99 | 99 | * |
100 | 100 | * @return Pipeline |
101 | 101 | */ |
102 | - public function addBefore( AbstractHandler $before, AbstractHandler $newPipeline ) { |
|
103 | - $this->_register( $newPipeline ); |
|
104 | - foreach ( $this->handlers as $pos => $handler ) { |
|
105 | - if ( $handler->getName() == $before->getName() ) { |
|
106 | - array_splice( $this->handlers, $pos, 0, [ $newPipeline ] ); |
|
102 | + public function addBefore(AbstractHandler $before, AbstractHandler $newPipeline) { |
|
103 | + $this->_register($newPipeline); |
|
104 | + foreach ($this->handlers as $pos => $handler) { |
|
105 | + if ($handler->getName() == $before->getName()) { |
|
106 | + array_splice($this->handlers, $pos, 0, [$newPipeline]); |
|
107 | 107 | break; |
108 | 108 | } |
109 | 109 | } |
@@ -118,11 +118,11 @@ discard block |
||
118 | 118 | * |
119 | 119 | * @return Pipeline |
120 | 120 | */ |
121 | - public function addAfter( AbstractHandler $after, AbstractHandler $newPipeline ) { |
|
122 | - $this->_register( $newPipeline ); |
|
123 | - foreach ( $this->handlers as $pos => $handler ) { |
|
124 | - if ( $handler->getName() == $after->getName() ) { |
|
125 | - array_splice( $this->handlers, $pos + 1, 0, [ $newPipeline ] ); |
|
121 | + public function addAfter(AbstractHandler $after, AbstractHandler $newPipeline) { |
|
122 | + $this->_register($newPipeline); |
|
123 | + foreach ($this->handlers as $pos => $handler) { |
|
124 | + if ($handler->getName() == $after->getName()) { |
|
125 | + array_splice($this->handlers, $pos + 1, 0, [$newPipeline]); |
|
126 | 126 | break; |
127 | 127 | } |
128 | 128 | } |
@@ -138,11 +138,11 @@ discard block |
||
138 | 138 | * |
139 | 139 | * @return $this |
140 | 140 | */ |
141 | - public function remove( AbstractHandler $handlerToDelete ) { |
|
142 | - foreach ( $this->handlers as $pos => $handler ) { |
|
143 | - if ( $handler->getName() == $handlerToDelete->getName() ) { |
|
144 | - unset( $this->handlers[ $pos ] ); |
|
145 | - $this->handlers = array_values( $this->handlers ); |
|
141 | + public function remove(AbstractHandler $handlerToDelete) { |
|
142 | + foreach ($this->handlers as $pos => $handler) { |
|
143 | + if ($handler->getName() == $handlerToDelete->getName()) { |
|
144 | + unset($this->handlers[$pos]); |
|
145 | + $this->handlers = array_values($this->handlers); |
|
146 | 146 | break; |
147 | 147 | } |
148 | 148 | } |
@@ -155,8 +155,8 @@ discard block |
||
155 | 155 | * |
156 | 156 | * @return Pipeline |
157 | 157 | */ |
158 | - public function addLast( AbstractHandler $handler ) { |
|
159 | - $this->_register( $handler ); |
|
158 | + public function addLast(AbstractHandler $handler) { |
|
159 | + $this->_register($handler); |
|
160 | 160 | $this->handlers[] = $handler; |
161 | 161 | |
162 | 162 | return $this; |
@@ -167,21 +167,21 @@ discard block |
||
167 | 167 | * |
168 | 168 | * @return mixed |
169 | 169 | */ |
170 | - public function transform( $segment ) { |
|
170 | + public function transform($segment) { |
|
171 | 171 | $this->id_number = -1; |
172 | - foreach ( $this->handlers as $handler ) { |
|
173 | - $segment = $handler->transform( $segment ); |
|
172 | + foreach ($this->handlers as $handler) { |
|
173 | + $segment = $handler->transform($segment); |
|
174 | 174 | } |
175 | 175 | |
176 | - return $this->realignIDs( $segment ); |
|
176 | + return $this->realignIDs($segment); |
|
177 | 177 | } |
178 | 178 | |
179 | - protected function realignIDs( $segment ) { |
|
180 | - if ( $this->id_number > -1 ) { |
|
181 | - preg_match_all( '/"__mtc_[0-9]+"/', $segment, $html, PREG_SET_ORDER ); |
|
182 | - foreach ( $html as $pos => $tag_id ) { |
|
179 | + protected function realignIDs($segment) { |
|
180 | + if ($this->id_number > -1) { |
|
181 | + preg_match_all('/"__mtc_[0-9]+"/', $segment, $html, PREG_SET_ORDER); |
|
182 | + foreach ($html as $pos => $tag_id) { |
|
183 | 183 | //replace subsequent elements excluding already encoded |
184 | - $segment = preg_replace( '/' . $tag_id[ 0 ] . '/', '"mtc_' . ( $pos + 1 ) . '"', $segment, 1 ); |
|
184 | + $segment = preg_replace('/'.$tag_id[0].'/', '"mtc_'.($pos + 1).'"', $segment, 1); |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 | |
@@ -193,8 +193,8 @@ discard block |
||
193 | 193 | * |
194 | 194 | * @return $this |
195 | 195 | */ |
196 | - protected function _register( AbstractHandler $handler ) { |
|
197 | - $handler->setPipeline( $this ); |
|
196 | + protected function _register(AbstractHandler $handler) { |
|
197 | + $handler->setPipeline($this); |
|
198 | 198 | |
199 | 199 | return $this; |
200 | 200 | } |