Total Complexity | 47 |
Total Lines | 221 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like oldSdlOldXliffSAXTranslationReplacer often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use oldSdlOldXliffSAXTranslationReplacer, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
7 | class oldSdlOldXliffSAXTranslationReplacer extends oldXliffSAXTranslationReplacer { |
||
8 | protected $segmentInUnitPosition = ""; |
||
9 | |||
10 | /** |
||
11 | * @inheritDoc |
||
12 | */ |
||
13 | protected function tagOpen( $parser, $name, $attr ) { |
||
141 | } |
||
142 | } |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * prepare segment tagging for xliff insertion |
||
147 | * |
||
148 | * @param array $seg |
||
149 | * @param string $transUnitTranslation |
||
150 | * |
||
151 | * @return string |
||
152 | */ |
||
153 | protected function prepareTranslation( $seg, $transUnitTranslation = "" ) { |
||
154 | $endTags = ""; |
||
155 | |||
156 | $segment = Strings::removeDangerousChars( $seg [ 'segment' ] ); |
||
157 | $translation = Strings::removeDangerousChars( $seg [ 'translation' ] ); |
||
158 | $dataRefMap = ( isset( $seg[ 'data_ref_map' ] ) && $seg[ 'data_ref_map' ] !== null ) ? Strings::jsonToArray( $seg[ 'data_ref_map' ] ) : []; |
||
159 | |||
160 | if ( is_null( $seg [ 'translation' ] ) || $seg [ 'translation' ] == '' ) { |
||
161 | $translation = $segment; |
||
162 | } else { |
||
163 | if ( $this->callback instanceof XliffReplacerCallbackInterface ) { |
||
164 | $error = (isset($seg['error'])) ? $seg['error'] : null; |
||
165 | if ( $this->callback->thereAreErrors( $seg[ 'sid' ], $segment, $translation, $dataRefMap, $error ) ) { |
||
166 | $translation = '|||UNTRANSLATED_CONTENT_START|||' . $segment . '|||UNTRANSLATED_CONTENT_END|||'; |
||
167 | } |
||
168 | } |
||
169 | } |
||
170 | |||
171 | // for Trados the trailing spaces after </mrk> are meaningful |
||
172 | // so we trim the translation from Matecat DB and add them after </mrk> |
||
173 | $trailingSpaces = ''; |
||
174 | for ( $s = 0; $s < Strings::getTheNumberOfTrailingSpaces( $translation ); $s++ ) { |
||
175 | $trailingSpaces .= ' '; |
||
176 | } |
||
177 | |||
178 | if ( $seg[ 'mrk_id' ] !== null && $seg[ 'mrk_id' ] != '' ) { |
||
179 | if ( $this->targetLang === 'ja-JP' ) { |
||
180 | $seg[ 'mrk_succ_tags' ] = ltrim( $seg[ 'mrk_succ_tags' ] ); |
||
181 | } |
||
182 | |||
183 | $translation = "<mrk mid=\"" . $seg[ 'mrk_id' ] . "\" mtype=\"seg\">" . $seg[ 'mrk_prev_tags' ] . rtrim( $translation ) . $seg[ 'mrk_succ_tags' ] . "</mrk>" . $trailingSpaces; |
||
184 | } |
||
185 | |||
186 | // we need to trim succ_tags here because we already added the trailing spaces after </mrk> |
||
187 | $transUnitTranslation .= $seg[ 'prev_tags' ] . $translation . $endTags . ltrim( $seg[ 'succ_tags' ] ); |
||
188 | |||
189 | return $transUnitTranslation; |
||
190 | } |
||
191 | |||
192 | /** |
||
193 | * @param $segment |
||
194 | * |
||
195 | * @return string |
||
196 | */ |
||
197 | protected function prepareTargetStatuses( $segment ) { |
||
198 | $statusMap = [ |
||
199 | 'NEW' => '', |
||
200 | 'DRAFT' => 'Draft', |
||
201 | 'TRANSLATED' => 'Translated', |
||
202 | 'APPROVED' => 'ApprovedTranslation', |
||
203 | 'REJECTED' => 'RejectedTranslation', |
||
204 | ]; |
||
205 | |||
206 | return "conf=\"{$statusMap[ $segment[ 'status' ] ]}\" "; |
||
207 | } |
||
208 | |||
209 | /** |
||
210 | * @param $seg |
||
211 | * @param $state_prop |
||
212 | * @param $lastMrkState |
||
213 | * |
||
214 | * @return array |
||
215 | */ |
||
216 | protected function setTransUnitState( $seg, $state_prop, $lastMrkState ) { |
||
218 | } |
||
219 | |||
220 | /** |
||
221 | * @param $raw_word_count |
||
222 | * @param $eq_word_count |
||
223 | * |
||
224 | * @return string |
||
225 | */ |
||
226 | protected function getWordCountGroup( $raw_word_count, $eq_word_count ) { |
||
230 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.