Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 9 | class HelperTest extends BaseTestCase |
||
| 10 | { |
||
| 11 | protected $timestamps = array( |
||
| 12 | array(1412399250, '2014-10-04T05:07:30Z'), |
||
| 13 | array(1412368132, '2014-10-03T20:28:52Z'), |
||
| 14 | array(1412331547, '2014-10-03T10:19:07Z'), |
||
| 15 | ); |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @return array |
||
| 19 | */ |
||
| 20 | public function timestamp2StringProvider() |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @return array |
||
| 27 | */ |
||
| 28 | public function string2TimestampProvider() |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @param string $timestamp |
||
| 57 | * @param string $string |
||
| 58 | * @dataProvider timestamp2StringProvider |
||
| 59 | */ |
||
| 60 | public function test__time_to_string($timestamp, $string) |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @param string $value |
||
| 67 | * @param int $timestamp |
||
| 68 | * |
||
| 69 | * @dataProvider string2TimestampProvider |
||
| 70 | */ |
||
| 71 | public function test__get_timestamp_from_value_with_string($value, $timestamp) |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @param string $value |
||
| 78 | * @param int $timestamp |
||
| 79 | * |
||
| 80 | * @dataProvider string2TimestampProvider |
||
| 81 | */ |
||
| 82 | public function test__get_timestamp_from_value_with_date_time($value, $timestamp) |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @param string $value |
||
| 90 | * @param int $timestamp |
||
| 91 | * |
||
| 92 | * @dataProvider string2TimestampProvider |
||
| 93 | */ |
||
| 94 | public function test__get_timestamp_from_value_with_int($value, $timestamp) |
||
| 98 | |||
| 99 | public function test__get_timestamp_from_value_with_invalid_value() |
||
| 104 | |||
| 105 | public function test__generate_random_bytes_length() |
||
| 116 | |||
| 117 | public function test__generate_random_bytes_error_on_invalid_length() |
||
| 122 | |||
| 123 | public function test__generate_id() |
||
| 136 | |||
| 137 | public function test__validate_id_string_returns_true_for_valid_string() |
||
| 142 | |||
| 143 | public function test__validate_id_string_returns_false_for_non_string() |
||
| 148 | |||
| 149 | public function test__validate_id_string_returns_false_for_short_string() |
||
| 155 | |||
| 156 | public function test__validate_required_string_returns_true_for_non_empty_string() |
||
| 162 | |||
| 163 | public function test__validate_required_string_returns_false_for_empty_string() |
||
| 167 | |||
| 168 | public function test__validate_required_string_returns_false_for_null() |
||
| 172 | |||
| 173 | public function test__validate_required_string_returns_false_for_non_string() |
||
| 178 | |||
| 179 | public function test__validate_optional_string_returns_true_for_null() |
||
| 183 | |||
| 184 | public function test__validate_optional_string_returns_true_for_non_empty_string() |
||
| 189 | |||
| 190 | public function test__validate_optional_string_returns_false_for_empty_string() |
||
| 194 | |||
| 195 | public function test__validate_optional_string_returns_false_for_non_string() |
||
| 200 | |||
| 201 | public function test__validate_well_formed_uri_string_returns_false_for_empty_string() |
||
| 205 | |||
| 206 | public function test__validate_well_formed_uri_string_returns_false_for_null() |
||
| 210 | |||
| 211 | public function test__validate_well_formed_uri_string_returns_false_for_too_big_string() |
||
| 216 | |||
| 217 | public function test__validate_well_formed_uri_string_returns_false_for_string_with_spaces() |
||
| 221 | |||
| 222 | public function test__validate_well_formed_uri_string_returns_false_for_string_without_scheme() |
||
| 228 | |||
| 229 | public function test__validate_well_formed_uri_string_returns_false_for_string_with_invalid_scheme() |
||
| 235 | |||
| 236 | public function test__validate_well_formed_uri_string_returns_false_for_valid_string() |
||
| 246 | |||
| 247 | View Code Duplication | public function notBeforeProvider() |
|
| 254 | |||
| 255 | /** |
||
| 256 | * @dataProvider notBeforeProvider |
||
| 257 | */ |
||
| 258 | public function test__validate_not_before($notBefore, $now, $allowedSecondsSkew, $expected) |
||
| 262 | |||
| 263 | View Code Duplication | public function notOnOrAfterProvider() |
|
| 270 | |||
| 271 | /** |
||
| 272 | * @dataProvider notOnOrAfterProvider |
||
| 273 | */ |
||
| 274 | public function test__validate_not_on_or_after($notOnOrAfter, $now, $allowedSecondsSkew, $expected) |
||
| 278 | } |
||
| 279 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.