| Conditions | 14 |
| Paths | 108 |
| Total Lines | 58 |
| Code Lines | 23 |
| 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 |
||
| 19 | protected function tagOpen( $parser, $name, $attr ) { |
||
| 20 | |||
| 21 | $this->handleOpenUnit( $name, $attr ); |
||
| 22 | |||
| 23 | // check if we are entering into a <target> |
||
| 24 | if ( 'target' == $name ) { |
||
| 25 | if ( $this->currentTransUnitIsTranslatable === 'no' ) { |
||
| 26 | $this->inTarget = false; |
||
| 27 | } else { |
||
| 28 | $this->inTarget = true; |
||
| 29 | } |
||
| 30 | } |
||
| 31 | |||
| 32 | // reset Marker positions |
||
| 33 | if ( 'sdl:seg-defs' == $name ) { |
||
| 34 | $this->segmentInUnitPosition = 0; |
||
| 35 | } |
||
| 36 | |||
| 37 | // open buffer |
||
| 38 | if ( in_array( $name, $this->nodesToBuffer ) ) { |
||
| 39 | $this->bufferIsActive = true; |
||
| 40 | } |
||
| 41 | |||
| 42 | // check if we are inside a <target>, obviously this happen only if there are targets inside the trans-unit |
||
| 43 | // <target> must be stripped to be replaced, so this check avoids <target> reconstruction |
||
| 44 | if ( !$this->inTarget ) { |
||
| 45 | |||
| 46 | // costruct tag |
||
| 47 | $tag = "<$name "; |
||
| 48 | |||
| 49 | // needed to avoid multiple conf writing inside the same tag |
||
| 50 | // because the "conf" attribute could be not present in the tag, |
||
| 51 | // so the check on it's name is not enough |
||
| 52 | $_sdlStatus_confWritten = false; |
||
|
|
|||
| 53 | |||
| 54 | foreach ( $attr as $k => $v ) { |
||
| 55 | |||
| 56 | // if tag name is file, we must replace the target-language attribute |
||
| 57 | if ( $name == 'file' && $k == 'target-language' && !empty( $this->targetLang ) ) { |
||
| 58 | //replace Target language with job language provided from constructor |
||
| 59 | $tag .= "$k=\"$this->targetLang\" "; |
||
| 60 | } else { |
||
| 61 | //normal tag flux, put attributes in it |
||
| 62 | // Warning, this is NOT an elseif |
||
| 63 | if ( $k != 'conf' ) { |
||
| 64 | //put also the current attribute in it if it is not a "conf" attribute |
||
| 65 | $tag .= "$k=\"$v\" "; |
||
| 66 | } |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | $seg = $this->getCurrentSegment(); |
||
| 71 | |||
| 72 | if ( 'sdl:seg' == $name && !empty( $seg ) and isset( $seg[ 'sid' ] ) ) { |
||
| 73 | $tag .= $this->prepareTargetStatuses( $seg ); |
||
| 74 | } |
||
| 75 | |||
| 76 | $this->checkForSelfClosedTagAndFlush( $parser, $tag ); |
||
| 77 | |||
| 118 | } |