Conditions | 17 |
Paths | 50 |
Total Lines | 119 |
Code Lines | 51 |
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 |
||
142 | protected function tagClose( $parser, string $name ) { |
||
143 | $tag = ''; |
||
144 | |||
145 | /** |
||
146 | * if is a tag within <target> or |
||
147 | * if it is an empty tag, do not add closing tag because we have already closed it in |
||
148 | * |
||
149 | * self::tagOpen method |
||
150 | */ |
||
151 | if ( !$this->isEmpty ) { |
||
152 | |||
153 | if ( !$this->inTarget ) { |
||
154 | $tag = "</$name>"; |
||
155 | } |
||
156 | |||
157 | if ( 'target' == $name ) { |
||
158 | |||
159 | if ( isset( $this->transUnits[ $this->currentTransUnitId ] ) ) { |
||
160 | |||
161 | $seg = $this->getCurrentSegment(); |
||
162 | |||
163 | // update counts |
||
164 | if ( !$this->hasWrittenCounts && !empty( $seg ) ) { |
||
165 | $this->updateSegmentCounts( $seg ); |
||
166 | } |
||
167 | |||
168 | // delete translations so the prepareSegment |
||
169 | // will put source content in target tag |
||
170 | if ( $this->sourceInTarget ) { |
||
171 | $seg[ 'translation' ] = ''; |
||
172 | $this->resetCounts(); |
||
173 | } |
||
174 | |||
175 | // append $translation |
||
176 | $translation = $this->prepareTranslation( $seg ); |
||
177 | |||
178 | //append translation |
||
179 | $tag = "<target>$translation</target>"; |
||
180 | |||
181 | } |
||
182 | |||
183 | // signal we are leaving a target |
||
184 | $this->targetWasWritten = true; |
||
185 | $this->inTarget = false; |
||
186 | $this->postProcAndFlush( $this->outputFP, $tag, true ); |
||
187 | |||
188 | } elseif ( in_array( $name, $this->nodesToBuffer ) ) { // we are closing a critical CDATA section |
||
189 | |||
190 | $this->bufferIsActive = false; |
||
191 | |||
192 | // only for Xliff 2.* |
||
193 | // write here <mda:metaGroup> and <mda:meta> if already present in the <unit> |
||
194 | if ( 'mda:metadata' === $name && $this->unitContainsMda && !$this->hasWrittenCounts ) { |
||
195 | |||
196 | // we need to update counts here |
||
197 | $this->updateCounts(); |
||
198 | $this->hasWrittenCounts = true; |
||
199 | |||
200 | $tag = $this->CDATABuffer; |
||
201 | $tag .= $this->getWordCountGroupForXliffV2( false ); |
||
202 | $tag .= " </mda:metadata>"; |
||
203 | |||
204 | } else { |
||
205 | $tag = $this->CDATABuffer . "</$name>"; |
||
206 | } |
||
207 | |||
208 | $this->CDATABuffer = ""; |
||
209 | |||
210 | //flush to the pointer |
||
211 | $this->postProcAndFlush( $this->outputFP, $tag ); |
||
212 | |||
213 | } elseif ( 'segment' === $name ) { |
||
214 | |||
215 | // only for Xliff 2.* |
||
216 | // if segment has no <target> add it BEFORE </segment> |
||
217 | if ( !$this->targetWasWritten ) { |
||
218 | |||
219 | $seg = $this->getCurrentSegment(); |
||
220 | |||
221 | if ( isset( $seg[ 'translation' ] ) ) { |
||
222 | |||
223 | $translation = $this->prepareTranslation( $seg ); |
||
224 | // replace the tag |
||
225 | $tag = "<target>$translation</target>"; |
||
226 | |||
227 | $tag .= '</segment>'; |
||
228 | |||
229 | } |
||
230 | |||
231 | } |
||
232 | |||
233 | // update segmentPositionInTu |
||
234 | $this->segmentInUnitPosition++; |
||
235 | |||
236 | $this->postProcAndFlush( $this->outputFP, $tag ); |
||
237 | |||
238 | // we are leaving <segment>, reset $segmentHasTarget |
||
239 | $this->targetWasWritten = false; |
||
240 | |||
241 | } elseif ( $this->bufferIsActive ) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag |
||
242 | $this->CDATABuffer .= "</$name>"; |
||
243 | // Do NOT Flush |
||
244 | } else { //generic tag closure do Nothing |
||
245 | // flush to pointer |
||
246 | $this->postProcAndFlush( $this->outputFP, $tag ); |
||
247 | } |
||
248 | } else { |
||
249 | //ok, nothing to be done; reset flag for next coming tag |
||
250 | $this->isEmpty = false; |
||
251 | } |
||
252 | |||
253 | // check if we are leaving a <trans-unit> (xliff v1.*) or <unit> (xliff v2.*) |
||
254 | if ( $this->tuTagName === $name ) { |
||
255 | $this->currentTransUnitIsTranslatable = null; |
||
256 | $this->inTU = false; |
||
257 | $this->unitContainsMda = false; |
||
258 | $this->hasWrittenCounts = false; |
||
259 | |||
260 | $this->resetCounts(); |
||
261 | } |
||
340 | } |