| Conditions | 13 |
| Paths | 12 |
| Total Lines | 39 |
| Code Lines | 26 |
| Lines | 8 |
| Ratio | 20.51 % |
| 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 |
||
| 45 | public function date( $ts, $adj = false, $format = true, $tc = false ) { |
||
| 46 | $ts = wfTimestamp( TS_MW, $ts ); |
||
| 47 | if ( $adj ) { |
||
| 48 | $ts = $this->userAdjust( $ts, $tc ); |
||
|
|
|||
| 49 | } |
||
| 50 | $datePreference = $this->dateFormat( $format ); |
||
| 51 | |||
| 52 | # ISO (YYYY-mm-dd) format |
||
| 53 | # we also output this format for YMD (eg: 2001 January 15) |
||
| 54 | View Code Duplication | if ( $datePreference == 'ISO 8601' ) { |
|
| 55 | $d = substr( $ts, 0, 4 ) . '-' . substr( $ts, 4, 2 ) . '-' . substr( $ts, 6, 2 ); |
||
| 56 | return $d; |
||
| 57 | } |
||
| 58 | |||
| 59 | # dd/mm/YYYY format |
||
| 60 | View Code Duplication | if ( $datePreference == 'walloon short' ) { |
|
| 61 | $d = substr( $ts, 6, 2 ) . '/' . substr( $ts, 4, 2 ) . '/' . substr( $ts, 0, 4 ); |
||
| 62 | return $d; |
||
| 63 | } |
||
| 64 | |||
| 65 | # Walloon format |
||
| 66 | # we output this in all other cases |
||
| 67 | $m = substr( $ts, 4, 2 ); |
||
| 68 | $n = substr( $ts, 6, 2 ); |
||
| 69 | if ( $n == 1 ) { |
||
| 70 | $d = "1î d' " . $this->getMonthName( $m ) . |
||
| 71 | " " . substr( $ts, 0, 4 ); |
||
| 72 | } elseif ( $n == 2 || $n == 3 || $n == 20 || $n == 22 || $n == 23 ) { |
||
| 73 | $d = ( 0 + $n ) . " d' " . $this->getMonthName( $m ) . |
||
| 74 | " " . substr( $ts, 0, 4 ); |
||
| 75 | } elseif ( $m == 4 || $m == 8 || $m == 10 ) { |
||
| 76 | $d = ( 0 + $n ) . " d' " . $this->getMonthName( $m ) . |
||
| 77 | " " . substr( $ts, 0, 4 ); |
||
| 78 | } else { |
||
| 79 | $d = ( 0 + $n ) . " di " . $this->getMonthName( $m ) . |
||
| 80 | " " . substr( $ts, 0, 4 ); |
||
| 81 | } |
||
| 82 | return $d; |
||
| 83 | } |
||
| 84 | |||
| 105 |
This check looks for type mismatches where the missing type is
false. This is usually indicative of an error condtion.Consider the follow example
This function either returns a new
DateTimeobject or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returnedfalsebefore passing on the value to another function or method that may not be able to handle afalse.