| Conditions | 16 |
| Paths | 40 |
| Total Lines | 99 |
| Code Lines | 47 |
| 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 |
||
| 105 | protected function tagClose( $parser, string $name ) { |
||
| 106 | $tag = ''; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * if is a tag within <target> or |
||
| 110 | * if it is an empty tag, do not add closing tag because we have already closed it in |
||
| 111 | * |
||
| 112 | * self::tagOpen method |
||
| 113 | */ |
||
| 114 | if ( !$this->isEmpty ) { |
||
| 115 | |||
| 116 | // write closing tag if is not a target |
||
| 117 | // EXCLUDE the target nodes with currentTransUnitIsTranslatable = 'NO' |
||
| 118 | if ( !$this->inTarget and $this->currentTransUnitIsTranslatable !== 'no' ) { |
||
| 119 | $tag = "</$name>"; |
||
| 120 | } |
||
| 121 | |||
| 122 | if ( 'target' == $name && !$this->inAltTrans ) { |
||
| 123 | |||
| 124 | if ( isset( $this->transUnits[ $this->currentTransUnitId ] ) ) { |
||
| 125 | |||
| 126 | // get translation of current segment, by indirect indexing: id -> positional index -> segment |
||
| 127 | // actually there may be more than one segment to that ID if there are two mrk of the same source segment |
||
| 128 | $tag = $this->rebuildTarget(); |
||
| 129 | |||
| 130 | } elseif( !empty($this->CDATABuffer) and $this->currentTransUnitIsTranslatable === 'no' ) { |
||
| 131 | |||
| 132 | // These are target nodes with currentTransUnitIsTranslatable = 'NO' |
||
| 133 | $this->bufferIsActive = false; |
||
| 134 | $tag = $this->CDATABuffer . "</$name>"; |
||
| 135 | $this->CDATABuffer = ""; |
||
| 136 | } |
||
| 137 | |||
| 138 | $this->targetWasWritten = true; |
||
| 139 | // signal we are leaving a target |
||
| 140 | $this->inTarget = false; |
||
| 141 | $this->postProcAndFlush( $this->outputFP, $tag, true ); |
||
| 142 | |||
| 143 | } elseif ( in_array( $name, $this->nodesToBuffer ) ) { // we are closing a critical CDATA section |
||
| 144 | |||
| 145 | $this->bufferIsActive = false; |
||
| 146 | $tag = $this->CDATABuffer . "</$name>"; |
||
| 147 | $this->CDATABuffer = ""; |
||
| 148 | |||
| 149 | //flush to the pointer |
||
| 150 | $this->postProcAndFlush( $this->outputFP, $tag ); |
||
| 151 | |||
| 152 | } elseif ( $name === $this->tuTagName ) { |
||
| 153 | |||
| 154 | $tag = ""; |
||
| 155 | |||
| 156 | // handling </trans-unit> closure |
||
| 157 | if ( !$this->targetWasWritten ) { |
||
| 158 | |||
| 159 | if ( isset( $this->transUnits[ $this->currentTransUnitId ] ) ) { |
||
| 160 | $tag = $this->rebuildTarget(); |
||
| 161 | } else { |
||
| 162 | $tag = $this->createTargetTag( "", "" ); |
||
| 163 | } |
||
| 164 | |||
| 165 | } |
||
| 166 | |||
| 167 | $tag .= "</$this->tuTagName>"; |
||
| 168 | $this->targetWasWritten = false; |
||
| 169 | $this->postProcAndFlush( $this->outputFP, $tag ); |
||
| 170 | |||
| 171 | } elseif ( $this->bufferIsActive ) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag |
||
| 172 | $this->CDATABuffer .= "</$name>"; |
||
| 173 | // Do NOT Flush |
||
| 174 | } else { //generic tag closure do Nothing |
||
| 175 | // flush to pointer |
||
| 176 | $this->postProcAndFlush( $this->outputFP, $tag ); |
||
| 177 | } |
||
| 178 | |||
| 179 | } elseif ( in_array( $name, $this->nodesToBuffer ) ) { |
||
| 180 | |||
| 181 | $this->isEmpty = false; |
||
| 182 | $this->bufferIsActive = false; |
||
| 183 | $tag = $this->CDATABuffer; |
||
| 184 | $this->CDATABuffer = ""; |
||
| 185 | |||
| 186 | //flush to the pointer |
||
| 187 | $this->postProcAndFlush( $this->outputFP, $tag ); |
||
| 188 | |||
| 189 | } else { |
||
| 190 | //ok, nothing to be done; reset flag for next coming tag |
||
| 191 | $this->isEmpty = false; |
||
| 192 | } |
||
| 193 | |||
| 194 | // try to signal that we are leaving a target |
||
| 195 | $this->tryUnsetAltTrans( $name ); |
||
| 196 | |||
| 197 | // check if we are leaving a <trans-unit> (xliff v1.*) or <unit> (xliff v2.*) |
||
| 198 | if ( $this->tuTagName === $name ) { |
||
| 199 | $this->currentTransUnitIsTranslatable = null; |
||
| 200 | $this->inTU = false; |
||
| 201 | $this->hasWrittenCounts = false; |
||
| 202 | |||
| 203 | $this->resetCounts(); |
||
| 204 | } |
||
| 334 | } |
PHP has two types of connecting operators (logical operators, and boolean operators):
and&&or||The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&, or||.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
dieintroduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrowat this point:These limitations lead to logical operators rarely being of use in current PHP code.