| Conditions | 4 |
| Paths | 5 |
| Total Lines | 100 |
| Code Lines | 76 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 41 | public function validInputProvider() { |
||
| 42 | $monthNames = array( 9 => array( 'Sep', 'September' ) ); |
||
| 43 | |||
| 44 | $valid = array( |
||
| 45 | 'Default options' => array( |
||
| 46 | '1 9 2014', |
||
| 47 | 'd M Y', null, null, |
||
| 48 | '+2014-09-01T00:00:00Z' |
||
| 49 | ), |
||
| 50 | 'Transform map' => array( |
||
| 51 | 'Z g Zo15', |
||
| 52 | 'd M Y', array( '0' => 'o', 2 => 'Z', 9 => 'g' ), null, |
||
| 53 | '+2015-09-02T00:00:00Z' |
||
| 54 | ), |
||
| 55 | 'Default month map' => array( |
||
| 56 | '1. September 2014', |
||
| 57 | 'd. M Y', null, $monthNames, |
||
| 58 | '+2014-09-01T00:00:00Z' |
||
| 59 | ), |
||
| 60 | 'Simple month map' => array( |
||
| 61 | '1 September 2014', |
||
| 62 | 'd M Y', null, array( 9 => 'September' ), |
||
| 63 | '+2014-09-01T00:00:00Z' |
||
| 64 | ), |
||
| 65 | 'Escapes' => array( |
||
| 66 | '1s 9s 2014', |
||
| 67 | 'd\s M\s Y', null, null, |
||
| 68 | '+2014-09-01T00:00:00Z' |
||
| 69 | ), |
||
| 70 | 'Quotes' => array( |
||
| 71 | '1th 9th 2014', |
||
| 72 | 'd"th" M"th" Y', null, null, |
||
| 73 | '+2014-09-01T00:00:00Z' |
||
| 74 | ), |
||
| 75 | 'Raw modifiers' => array( |
||
| 76 | '2014 9 1', |
||
| 77 | 'Y xNmxN xnd', null, null, |
||
| 78 | '+2014-09-01T00:00:00Z' |
||
| 79 | ), |
||
| 80 | 'Whitespace is optional' => array( |
||
| 81 | '1September2014', |
||
| 82 | 'd M Y', null, $monthNames, |
||
| 83 | '+2014-09-01T00:00:00Z' |
||
| 84 | ), |
||
| 85 | 'Delimiters are optional' => array( |
||
| 86 | '1 9 2014', |
||
| 87 | 'd. M. Y', null, null, |
||
| 88 | '+2014-09-01T00:00:00Z' |
||
| 89 | ), |
||
| 90 | 'Delimiters are ignored' => array( |
||
| 91 | '1. 9. 2014', |
||
| 92 | 'd M Y', null, null, |
||
| 93 | '+2014-09-01T00:00:00Z' |
||
| 94 | ), |
||
| 95 | 'Year precision' => array( |
||
| 96 | '2014', |
||
| 97 | 'Y', null, null, |
||
| 98 | '+2014-00-00T00:00:00Z', TimeValue::PRECISION_YEAR |
||
| 99 | ), |
||
| 100 | 'Month precision' => array( |
||
| 101 | '9 2014', |
||
| 102 | 'M Y', null, null, |
||
| 103 | '+2014-09-00T00:00:00Z', TimeValue::PRECISION_MONTH |
||
| 104 | ), |
||
| 105 | 'Minute precision' => array( |
||
| 106 | '1 9 2014 15:30', |
||
| 107 | 'd M Y H:i', null, null, |
||
| 108 | '+2014-09-01T15:30:00Z', TimeValue::PRECISION_MINUTE |
||
| 109 | ), |
||
| 110 | 'Second precision' => array( |
||
| 111 | '1 9 2014 15:30:59', |
||
| 112 | 'd M Y H:i:s', null, null, |
||
| 113 | '+2014-09-01T15:30:59Z', TimeValue::PRECISION_SECOND |
||
| 114 | ), |
||
| 115 | ); |
||
| 116 | |||
| 117 | $cases = array(); |
||
| 118 | |||
| 119 | foreach ( $valid as $key => $args ) { |
||
| 120 | $dateString = $args[0]; |
||
| 121 | $dateFormat = $args[1]; |
||
| 122 | $digitTransformTable = $args[2]; |
||
| 123 | $monthNames = $args[3]; |
||
| 124 | $timestamp = $args[4]; |
||
| 125 | $precision = isset( $args[5] ) ? $args[5] : TimeValue::PRECISION_DAY; |
||
| 126 | $calendarModel = isset( $args[6] ) ? $args[6] : TimeValue::CALENDAR_GREGORIAN; |
||
| 127 | |||
| 128 | $cases[$key] = array( |
||
| 129 | $dateString, |
||
| 130 | new TimeValue( $timestamp, 0, 0, 0, $precision, $calendarModel ), |
||
| 131 | new DateFormatParser( new ParserOptions( array( |
||
| 132 | DateFormatParser::OPT_DATE_FORMAT => $dateFormat, |
||
| 133 | DateFormatParser::OPT_DIGIT_TRANSFORM_TABLE => $digitTransformTable, |
||
| 134 | DateFormatParser::OPT_MONTH_NAMES => $monthNames, |
||
| 135 | ) ) ) |
||
| 136 | ); |
||
| 137 | } |
||
| 138 | |||
| 139 | return $cases; |
||
| 140 | } |
||
| 141 | |||
| 168 |