| Conditions | 3 |
| Paths | 3 |
| Total Lines | 71 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 50 | public function validInputProvider() { |
||
| 51 | $gregorian = 'http://www.wikidata.org/entity/Q1985727'; |
||
| 52 | $julian = 'http://www.wikidata.org/entity/Q1985786'; |
||
| 53 | |||
| 54 | $valid = array( |
||
| 55 | // YMD, typically used in ISO 8601 |
||
| 56 | '2015-12-31' => array( '+2015-12-31T00:00:00Z' ), |
||
| 57 | '2015 12 31' => array( '+2015-12-31T00:00:00Z' ), |
||
| 58 | '2015 1 13' => array( '+2015-01-13T00:00:00Z' ), |
||
| 59 | |||
| 60 | // DMY |
||
| 61 | '31.12.2015' => array( '+2015-12-31T00:00:00Z' ), |
||
| 62 | '31. 12. 2015' => array( '+2015-12-31T00:00:00Z' ), |
||
| 63 | '31/12/2015' => array( '+2015-12-31T00:00:00Z' ), |
||
| 64 | '31 12 2015' => array( '+2015-12-31T00:00:00Z' ), |
||
| 65 | '31th 12th 2015' => array( '+2015-12-31T00:00:00Z' ), |
||
| 66 | 'day 31, month 12, year 2015' => array( '+2015-12-31T00:00:00Z' ), |
||
| 67 | |||
| 68 | // MDY, almost exclusively used in the United States |
||
| 69 | '12/31/2015' => array( '+2015-12-31T00:00:00Z' ), |
||
| 70 | '12-31-2015' => array( '+2015-12-31T00:00:00Z' ), |
||
| 71 | '12 31 2015' => array( '+2015-12-31T00:00:00Z' ), |
||
| 72 | |||
| 73 | // YDM, exclusively used in Kazakhstan |
||
| 74 | // https://en.wikipedia.org/wiki/Calendar_date#Gregorian.2C_year-day-month_.28YDM.29 |
||
| 75 | '2015.31.12' => array( '+2015-12-31T00:00:00Z' ), |
||
| 76 | '2015 13 1' => array( '+2015-01-13T00:00:00Z' ), |
||
| 77 | |||
| 78 | // Month and day are the same, does not matter if DMY or MDY |
||
| 79 | '01 1 2015' => array( '+2015-01-01T00:00:00Z' ), |
||
| 80 | '12 12 2015' => array( '+2015-12-12T00:00:00Z' ), |
||
| 81 | |||
| 82 | // Month and day are the same, does not matter if YMD or YDM |
||
| 83 | '2015 01 1' => array( '+2015-01-01T00:00:00Z' ), |
||
| 84 | '2015 12 12' => array( '+2015-12-12T00:00:00Z' ), |
||
| 85 | |||
| 86 | // Julian |
||
| 87 | '32-12-31' => array( '+0032-12-31T00:00:00Z', $julian ), |
||
| 88 | '31.12.32' => array( '+0032-12-31T00:00:00Z', $julian ), |
||
| 89 | '12/31/60' => array( '+0060-12-31T00:00:00Z', $julian ), |
||
| 90 | |||
| 91 | // Negative years |
||
| 92 | '-2015-12-31' => array( '-2015-12-31T00:00:00Z', $julian ), |
||
| 93 | 'year -2015-12-31' => array( '-2015-12-31T00:00:00Z', $julian ), |
||
| 94 | '31 12 -2015' => array( '-2015-12-31T00:00:00Z', $julian ), |
||
| 95 | '12/31/-2015' => array( '-2015-12-31T00:00:00Z', $julian ), |
||
| 96 | '2015-12-31 BC' => array( '-2015-12-31T00:00:00Z', $julian ), |
||
| 97 | '31 12 2015 BC' => array( '-2015-12-31T00:00:00Z', $julian ), |
||
| 98 | '12/31/2015 BC' => array( '-2015-12-31T00:00:00Z', $julian ), |
||
| 99 | |||
| 100 | // A negative number must be the year. |
||
| 101 | 'year -3-2-13' => array( '-0003-02-13T00:00:00Z', $julian ), |
||
| 102 | '13. 2. -3' => array( '-0003-02-13T00:00:00Z', $julian ), |
||
| 103 | '23:12:-59' => array( '-0059-12-23T00:00:00Z', $julian ), |
||
| 104 | ); |
||
| 105 | |||
| 106 | $cases = array(); |
||
| 107 | |||
| 108 | foreach ( $valid as $value => $args ) { |
||
| 109 | $timestamp = $args[0]; |
||
| 110 | $calendarModel = isset( $args[1] ) ? $args[1] : $gregorian; |
||
| 111 | |||
| 112 | $cases[] = array( |
||
| 113 | // Because PHP magically turns numeric keys into ints/floats |
||
| 114 | (string)$value, |
||
| 115 | new TimeValue( $timestamp, 0, 0, 0, TimeValue::PRECISION_DAY, $calendarModel ) |
||
| 116 | ); |
||
| 117 | } |
||
| 118 | |||
| 119 | return $cases; |
||
| 120 | } |
||
| 121 | |||
| 259 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.