| Conditions | 28 |
| Paths | 23 |
| Total Lines | 61 |
| Code Lines | 40 |
| 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 |
||
| 25 | public static function getState( string $status, int $xliffVersion, ?string $state_prop = '', ?string $lastMrkState = '' ): array { |
||
| 26 | |||
| 27 | switch ( $status ) { |
||
| 28 | |||
| 29 | case TranslationStatus::STATUS_FIXED: |
||
| 30 | case TranslationStatus::STATUS_APPROVED2: |
||
| 31 | if ( $lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_APPROVED2 ) { |
||
|
|
|||
| 32 | $state_prop = "state=\"final\""; |
||
| 33 | $lastMrkState = TranslationStatus::STATUS_APPROVED2; |
||
| 34 | } |
||
| 35 | break; |
||
| 36 | case TranslationStatus::STATUS_APPROVED: |
||
| 37 | if ( $lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_APPROVED ) { |
||
| 38 | $state_prop = ( $xliffVersion === 2 ) ? "state=\"reviewed\"" : "state=\"signed-off\""; |
||
| 39 | $lastMrkState = TranslationStatus::STATUS_APPROVED; |
||
| 40 | } |
||
| 41 | break; |
||
| 42 | |||
| 43 | case TranslationStatus::STATUS_TRANSLATED: |
||
| 44 | if ( $lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_TRANSLATED || $lastMrkState == TranslationStatus::STATUS_APPROVED ) { |
||
| 45 | $state_prop = "state=\"translated\""; |
||
| 46 | $lastMrkState = TranslationStatus::STATUS_TRANSLATED; |
||
| 47 | } |
||
| 48 | break; |
||
| 49 | |||
| 50 | case TranslationStatus::STATUS_REJECTED: // if there is a mark REJECTED and there is not a DRAFT, all the trans-unit is REJECTED. In V2 there is no way to mark |
||
| 51 | case TranslationStatus::STATUS_REBUTTED: |
||
| 52 | if ( ( $lastMrkState == null ) || ( $lastMrkState != TranslationStatus::STATUS_NEW || $lastMrkState != TranslationStatus::STATUS_DRAFT ) ) { |
||
| 53 | $state_prop = ( $xliffVersion === 2 ) ? "state=\"initial\"" : "state=\"needs-review-translation\""; |
||
| 54 | $lastMrkState = TranslationStatus::STATUS_REJECTED; |
||
| 55 | } |
||
| 56 | break; |
||
| 57 | |||
| 58 | case TranslationStatus::STATUS_NEW: |
||
| 59 | if ( ( $lastMrkState == null ) || $lastMrkState != TranslationStatus::STATUS_NEW ) { |
||
| 60 | $state_prop = ( $xliffVersion === 2 ) ? "state=\"initial\"" : "state=\"new\""; |
||
| 61 | $lastMrkState = TranslationStatus::STATUS_NEW; |
||
| 62 | } |
||
| 63 | break; |
||
| 64 | |||
| 65 | case TranslationStatus::STATUS_DRAFT: |
||
| 66 | if ( ( $lastMrkState == null ) || $lastMrkState != TranslationStatus::STATUS_DRAFT ) { |
||
| 67 | $state_prop = ( $xliffVersion === 2 ) ? "state=\"initial\"" : "state=\"new\""; |
||
| 68 | $lastMrkState = TranslationStatus::STATUS_DRAFT; |
||
| 69 | } |
||
| 70 | break; |
||
| 71 | |||
| 72 | default: |
||
| 73 | // this is the case when a segment is not showed in cattool, so the row in |
||
| 74 | // segment_translations does not exists and |
||
| 75 | // ---> $seg[ 'status' ] is NULL |
||
| 76 | if ( $lastMrkState == null ) { //this is the first MRK ID |
||
| 77 | $state_prop = "state=\"translated\""; |
||
| 78 | $lastMrkState = TranslationStatus::STATUS_TRANSLATED; |
||
| 79 | } else { |
||
| 80 | /* Do nothing and preserve the last state */ |
||
| 81 | } |
||
| 82 | break; |
||
| 83 | } |
||
| 84 | |||
| 85 | return [ $state_prop, $lastMrkState ]; |
||
| 86 | |||
| 89 | } |