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 PhpCompatGreaterFiveSixHelper extends AbstractHelper |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * PhpCompatLessFiveSixHelper constructor. |
||
| 13 | * |
||
| 14 | * @throws DomainException |
||
| 15 | */ |
||
| 16 | View Code Duplication | public function __construct() |
|
| 31 | |||
| 32 | /** |
||
| 33 | * Returns a timezone string for the provided gmt_offset. |
||
| 34 | * This is a valid timezone string that can be sent into DateTimeZone |
||
| 35 | * |
||
| 36 | * @param float|string $gmt_offset |
||
| 37 | * @return string |
||
| 38 | */ |
||
| 39 | public function getTimezoneStringFromGmtOffset($gmt_offset = '') |
||
| 46 | |||
| 47 | |||
| 48 | |||
| 49 | /** |
||
| 50 | * Returns a formatted offset for use as an argument for constructing DateTimeZone |
||
| 51 | * @param float $gmt_offset This should be a float representing the gmt_offset. |
||
| 52 | * @return string |
||
| 53 | */ |
||
| 54 | protected function convertWpGmtOffsetForDateTimeZone($gmt_offset) |
||
| 68 | |||
| 69 | |||
| 70 | /** |
||
| 71 | * Converts something like `1550` to `1530` or `0275` to `0245` |
||
| 72 | * Incoming offset should be a positive value, this will mutate negative values. Be aware! |
||
| 73 | * @param int $offset |
||
| 74 | * @return mixed |
||
| 75 | */ |
||
| 76 | protected function convertToTimeFraction($offset) |
||
| 83 | |||
| 84 | |||
| 85 | /** |
||
| 86 | * Get Timezone offset for given timezone object |
||
| 87 | * |
||
| 88 | * @param DateTimeZone $date_time_zone |
||
| 89 | * @param null|int $time |
||
| 90 | * @return int |
||
| 91 | */ |
||
| 92 | public function getTimezoneOffset(DateTimezone $date_time_zone, $time = NULL) |
||
| 98 | } |
||
| 99 |