Conditions | 11 |
Paths | 18 |
Total Lines | 45 |
Code Lines | 17 |
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, string $name, array $attr ) { |
||
20 | |||
21 | $this->handleOpenUnit( $name, $attr ); |
||
22 | |||
23 | // check if we are entering into a <target> |
||
24 | $this->checkSetInTarget( $name ); |
||
25 | |||
26 | // reset Marker positions |
||
27 | if ( 'sdl:seg-defs' == $name ) { |
||
28 | $this->segmentInUnitPosition = 0; |
||
29 | } |
||
30 | |||
31 | // open buffer |
||
32 | $this->setInBuffer( $name ); |
||
33 | |||
34 | // check if we are inside a <target>, obviously this happen only if there are targets inside the trans-unit |
||
35 | // <target> must be stripped to be replaced, so this check avoids <target> reconstruction |
||
36 | if ( !$this->inTarget ) { |
||
37 | |||
38 | // costruct tag |
||
39 | $tag = "<$name "; |
||
40 | |||
41 | foreach ( $attr as $k => $v ) { |
||
42 | |||
43 | // if tag name is file, we must replace the target-language attribute |
||
44 | if ( $name == 'file' && $k == 'target-language' && !empty( $this->targetLang ) ) { |
||
45 | //replace Target language with job language provided from constructor |
||
46 | $tag .= "$k=\"$this->targetLang\" "; |
||
47 | } else { |
||
48 | //normal tag flux, put attributes in it |
||
49 | // Warning, this is NOT an elseif |
||
50 | if ( $k != 'conf' ) { |
||
51 | //put also the current attribute in it if it is not a "conf" attribute |
||
52 | $tag .= "$k=\"$v\" "; |
||
53 | } |
||
54 | } |
||
55 | } |
||
56 | |||
57 | $seg = $this->getCurrentSegment(); |
||
58 | |||
59 | if ( 'sdl:seg' == $name && !empty( $seg ) && isset( $seg[ 'sid' ] ) ) { |
||
60 | $tag .= $this->prepareTargetStatuses( $seg ); |
||
61 | } |
||
62 | |||
63 | $this->checkForSelfClosedTagAndFlush( $parser, $tag ); |
||
64 | |||
103 | } |