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 |
||
100 | protected function tagClose( $parser, string $name ) { |
||
101 | $tag = ''; |
||
102 | |||
103 | /** |
||
104 | * if is a tag within <target> or |
||
105 | * if it is an empty tag, do not add closing tag because we have already closed it in |
||
106 | * |
||
107 | * self::tagOpen method |
||
108 | */ |
||
109 | if ( !$this->isEmpty ) { |
||
110 | |||
111 | // write closing tag if is not a target |
||
112 | // EXCLUDE the target nodes with currentTransUnitIsTranslatable = 'NO' |
||
113 | if ( !$this->inTarget and $this->currentTransUnitIsTranslatable !== 'no' ) { |
||
|
|||
114 | $tag = "</$name>"; |
||
115 | } |
||
116 | |||
117 | if ( 'target' == $name && !$this->inAltTrans ) { |
||
118 | |||
119 | if ( isset( $this->transUnits[ $this->currentTransUnitId ] ) ) { |
||
120 | |||
121 | // get translation of current segment, by indirect indexing: id -> positional index -> segment |
||
122 | // actually there may be more than one segment to that ID if there are two mrk of the same source segment |
||
123 | $tag = $this->rebuildTarget(); |
||
124 | |||
125 | } elseif( !empty($this->CDATABuffer) and $this->currentTransUnitIsTranslatable === 'no' ) { |
||
126 | |||
127 | // These are target nodes with currentTransUnitIsTranslatable = 'NO' |
||
128 | $this->bufferIsActive = false; |
||
129 | $tag = $this->CDATABuffer . "</$name>"; |
||
130 | $this->CDATABuffer = ""; |
||
131 | } |
||
132 | |||
133 | $this->targetWasWritten = true; |
||
134 | // signal we are leaving a target |
||
135 | $this->inTarget = false; |
||
136 | $this->postProcAndFlush( $this->outputFP, $tag, true ); |
||
137 | |||
138 | } elseif ( in_array( $name, $this->nodesToBuffer ) ) { // we are closing a critical CDATA section |
||
139 | |||
140 | $this->bufferIsActive = false; |
||
141 | $tag = $this->CDATABuffer . "</$name>"; |
||
142 | $this->CDATABuffer = ""; |
||
143 | |||
144 | //flush to the pointer |
||
145 | $this->postProcAndFlush( $this->outputFP, $tag ); |
||
146 | |||
147 | } elseif ( $name === $this->tuTagName ) { |
||
148 | |||
149 | $tag = ""; |
||
150 | |||
151 | // handling </trans-unit> closure |
||
152 | if ( !$this->targetWasWritten ) { |
||
153 | |||
154 | if ( isset( $this->transUnits[ $this->currentTransUnitId ] ) ) { |
||
155 | $tag = $this->rebuildTarget(); |
||
156 | } else { |
||
157 | $tag = $this->createTargetTag( "", "" ); |
||
158 | } |
||
159 | |||
160 | } |
||
161 | |||
162 | $tag .= "</$this->tuTagName>"; |
||
163 | $this->targetWasWritten = false; |
||
164 | $this->postProcAndFlush( $this->outputFP, $tag ); |
||
165 | |||
166 | } elseif ( $this->bufferIsActive ) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag |
||
167 | $this->CDATABuffer .= "</$name>"; |
||
168 | // Do NOT Flush |
||
169 | } else { //generic tag closure do Nothing |
||
170 | // flush to pointer |
||
171 | $this->postProcAndFlush( $this->outputFP, $tag ); |
||
172 | } |
||
173 | |||
174 | } elseif ( in_array( $name, $this->nodesToBuffer ) ) { |
||
175 | |||
176 | $this->isEmpty = false; |
||
177 | $this->bufferIsActive = false; |
||
178 | $tag = $this->CDATABuffer; |
||
179 | $this->CDATABuffer = ""; |
||
180 | |||
181 | //flush to the pointer |
||
182 | $this->postProcAndFlush( $this->outputFP, $tag ); |
||
183 | |||
184 | } else { |
||
185 | //ok, nothing to be done; reset flag for next coming tag |
||
186 | $this->isEmpty = false; |
||
187 | } |
||
188 | |||
189 | // try to signal that we are leaving a target |
||
190 | $this->tryUnsetAltTrans( $name ); |
||
191 | |||
192 | // check if we are leaving a <trans-unit> (xliff v1.*) or <unit> (xliff v2.*) |
||
193 | if ( $this->tuTagName === $name ) { |
||
194 | $this->currentTransUnitIsTranslatable = null; |
||
195 | $this->inTU = false; |
||
196 | $this->hasWrittenCounts = false; |
||
197 | |||
198 | $this->resetCounts(); |
||
199 | } |
||
329 | } |
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
die
introduces 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 withthrow
at this point:These limitations lead to logical operators rarely being of use in current PHP code.