Conditions | 10 |
Paths | 36 |
Total Lines | 54 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
183 | private function prepareCard( $vcard ) { |
||
184 | |||
185 | $vcard['label'] = ''; |
||
186 | |||
187 | $additionalname = $vcard['additionalname']; |
||
188 | |||
189 | // Read fullname or guess it in a simple way from other names that are |
||
190 | // given |
||
191 | if ( $vcard['fullname'] != '' ) { |
||
192 | $vcard['label'] = $vcard['fullname']; |
||
193 | } elseif ( $vcard['firstname'] . $vcard['lastname'] != '' ) { |
||
194 | $vcard['label'] = $vcard['firstname'] . ( ( ( $vcard['firstname'] != '' ) && ( $vcard['lastname'] != '' ) ) ? ' ':'' ) . $vcard['lastname']; |
||
195 | } else { |
||
196 | $vcard['label'] = $this->text; |
||
197 | } |
||
198 | |||
199 | $vcard['label'] = self::escape( $vcard['label'] ); |
||
200 | |||
201 | // read firstname and lastname, or guess it from other names that are given |
||
202 | if ( $vcard['firstname'] . $vcard['lastname'] == '' ) { // guessing needed |
||
203 | $nameparts = explode( ' ', $vcard['label'] ); |
||
204 | // Accepted forms for guessing: |
||
205 | // "Lastname" |
||
206 | // "Firstname Lastname" |
||
207 | // "Firstname <Additionalnames> Lastname" |
||
208 | $vcard['lastname'] = self::escape( array_pop( $nameparts ) ); |
||
209 | |||
210 | if ( count( $nameparts ) > 0 ) { |
||
211 | $vcard['firstname'] = self::escape( array_shift( $nameparts ) ); |
||
212 | } |
||
213 | |||
214 | foreach ( $nameparts as $name ) { |
||
215 | $vcard['additionalname'] .= ( $vcard['additionalname'] != '' ? ',':'' ) . self::escape( $name ); |
||
216 | } |
||
217 | } else { |
||
218 | $vcard['firstname'] = self::escape( $vcard['firstname'] ); |
||
219 | $vcard['lastname'] = self::escape( $vcard['lastname'] ); |
||
220 | } |
||
221 | |||
222 | // no escape, can be a value list |
||
223 | if ( $additionalname != '' ) { |
||
224 | $vcard['additionalname'] = $additionalname; |
||
225 | } |
||
226 | |||
227 | $vcard['prefix'] = self::escape( $vcard['prefix'] ); |
||
228 | $vcard['suffix'] = self::escape( $vcard['suffix'] ); |
||
229 | $vcard['title'] = self::escape( $vcard['title'] ); |
||
230 | $vcard['role'] = self::escape( $vcard['role'] ); |
||
231 | $vcard['organization'] = self::escape( $vcard['organization'] ); |
||
232 | $vcard['department'] = self::escape( $vcard['department'] ); |
||
233 | $vcard['note'] = self::escape( $vcard['note'] ); |
||
234 | |||
235 | return $vcard; |
||
236 | } |
||
237 | |||
239 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..