Conditions | 18 |
Paths | 50 |
Total Lines | 122 |
Code Lines | 52 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
159 | protected function tagClose( $parser, string $name ) { |
||
160 | $tag = ''; |
||
161 | |||
162 | /** |
||
163 | * if is a tag within <target> or |
||
164 | * if it is an empty tag, do not add closing tag because we have already closed it in |
||
165 | * |
||
166 | * self::tagOpen method |
||
167 | */ |
||
168 | if ( !$this->isEmpty ) { |
||
169 | |||
170 | if ( !$this->inTarget ) { |
||
171 | $tag = "</$name>"; |
||
172 | } |
||
173 | |||
174 | if ( 'target' == $name && !$this->inAltTrans ) { |
||
175 | |||
176 | if ( isset( $this->transUnits[ $this->currentTransUnitId ] ) ) { |
||
177 | |||
178 | $seg = $this->getCurrentSegment(); |
||
179 | |||
180 | // update counts |
||
181 | if ( !$this->hasWrittenCounts && !empty( $seg ) ) { |
||
182 | $this->updateSegmentCounts( $seg ); |
||
183 | } |
||
184 | |||
185 | // delete translations so the prepareSegment |
||
186 | // will put source content in target tag |
||
187 | if ( $this->sourceInTarget ) { |
||
188 | $seg[ 'translation' ] = ''; |
||
189 | $this->resetCounts(); |
||
190 | } |
||
191 | |||
192 | // append $translation |
||
193 | $translation = $this->prepareTranslation( $seg ); |
||
194 | |||
195 | //append translation |
||
196 | $tag = "<target>$translation</target>"; |
||
197 | |||
198 | } |
||
199 | |||
200 | // signal we are leaving a target |
||
201 | $this->targetWasWritten = true; |
||
202 | $this->inTarget = false; |
||
203 | $this->postProcAndFlush( $this->outputFP, $tag, true ); |
||
204 | |||
205 | } elseif ( in_array( $name, $this->nodesToBuffer ) ) { // we are closing a critical CDATA section |
||
206 | |||
207 | $this->bufferIsActive = false; |
||
208 | |||
209 | // only for Xliff 2.* |
||
210 | // write here <mda:metaGroup> and <mda:meta> if already present in the <unit> |
||
211 | if ( 'mda:metadata' === $name && $this->unitContainsMda && !$this->hasWrittenCounts ) { |
||
212 | |||
213 | // we need to update counts here |
||
214 | $this->updateCounts(); |
||
215 | $this->hasWrittenCounts = true; |
||
216 | |||
217 | $tag = $this->CDATABuffer; |
||
218 | $tag .= $this->getWordCountGroupForXliffV2( false ); |
||
219 | $tag .= " </mda:metadata>"; |
||
220 | |||
221 | } else { |
||
222 | $tag = $this->CDATABuffer . "</$name>"; |
||
223 | } |
||
224 | |||
225 | $this->CDATABuffer = ""; |
||
226 | |||
227 | //flush to the pointer |
||
228 | $this->postProcAndFlush( $this->outputFP, $tag ); |
||
229 | |||
230 | } elseif ( 'segment' === $name ) { |
||
231 | |||
232 | // only for Xliff 2.* |
||
233 | // if segment has no <target> add it BEFORE </segment> |
||
234 | if ( !$this->targetWasWritten ) { |
||
235 | |||
236 | $seg = $this->getCurrentSegment(); |
||
237 | |||
238 | if ( isset( $seg[ 'translation' ] ) ) { |
||
239 | |||
240 | $translation = $this->prepareTranslation( $seg ); |
||
241 | // replace the tag |
||
242 | $tag = "<target>$translation</target>"; |
||
243 | |||
244 | $tag .= '</segment>'; |
||
245 | |||
246 | } |
||
247 | |||
248 | } |
||
249 | |||
250 | // update segmentPositionInTu |
||
251 | $this->segmentInUnitPosition++; |
||
252 | |||
253 | $this->postProcAndFlush( $this->outputFP, $tag ); |
||
254 | |||
255 | // we are leaving <segment>, reset $segmentHasTarget |
||
256 | $this->targetWasWritten = false; |
||
257 | |||
258 | } elseif ( $this->bufferIsActive ) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag |
||
259 | $this->CDATABuffer .= "</$name>"; |
||
260 | // Do NOT Flush |
||
261 | } else { //generic tag closure do Nothing |
||
262 | // flush to pointer |
||
263 | $this->postProcAndFlush( $this->outputFP, $tag ); |
||
264 | } |
||
265 | } else { |
||
266 | //ok, nothing to be done; reset flag for next coming tag |
||
267 | $this->isEmpty = false; |
||
268 | } |
||
269 | |||
270 | // try to signal that we are leaving a target |
||
271 | $this->tryUnsetAltTrans( $name ); |
||
272 | |||
273 | // check if we are leaving a <trans-unit> (xliff v1.*) or <unit> (xliff v2.*) |
||
274 | if ( $this->tuTagName === $name ) { |
||
275 | $this->currentTransUnitIsTranslatable = null; |
||
276 | $this->inTU = false; |
||
277 | $this->unitContainsMda = false; |
||
278 | $this->hasWrittenCounts = false; |
||
279 | |||
280 | $this->resetCounts(); |
||
281 | } |
||
360 | } |