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 |
||
| 10 | class ChamiloApi |
||
| 11 | { |
||
| 12 | private static $configuration; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * ChamiloApi constructor. |
||
| 16 | * @param $configuration |
||
| 17 | */ |
||
| 18 | public function __construct(array $configuration) |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @return array |
||
| 25 | */ |
||
| 26 | public static function getConfigurationArray() |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param string $variable |
||
| 33 | * @return bool|string |
||
| 34 | */ |
||
| 35 | public static function getConfigurationValue($variable) |
||
| 44 | |||
| 45 | |||
| 46 | /** |
||
| 47 | * Returns an array of resolutions that can be used for the conversion of documents to images |
||
| 48 | * @return array |
||
| 49 | */ |
||
| 50 | public static function getDocumentConversionSizes() |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Get the platform logo path |
||
| 68 | * @return null|string |
||
| 69 | */ |
||
| 70 | public static function getWebPlatformLogoPath() |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Get the platform logo. |
||
| 91 | * Return a <img> if the logo image exists. Otherwise return a <h2> with the institution name. |
||
| 92 | * @param array $imageAttributes Optional. |
||
| 93 | * @return string |
||
| 94 | */ |
||
| 95 | public static function getPlatformLogo($imageAttributes = []) |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Like strip_tags(), but leaves an additional space and removes only the given tags |
||
| 135 | * @param string $string |
||
| 136 | * @param array $tags Tags to be removed |
||
| 137 | * @return string The original string without the given tags |
||
| 138 | */ |
||
| 139 | View Code Duplication | public static function stripGivenTags($string, $tags) |
|
| 140 | { |
||
| 141 | foreach ($tags as $tag) { |
||
| 142 | $string2 = preg_replace('#</' . $tag . '[^>]*>#i', ' ', $string); |
||
| 143 | if ($string2 != $string) { |
||
| 144 | $string = preg_replace('/<' . $tag . '[^>]*>/i', ' ', $string2); |
||
| 145 | } |
||
| 146 | } |
||
| 147 | return $string; |
||
| 148 | } |
||
| 149 | /** |
||
| 150 | * Adds or Subtract a time in hh:mm:ss to a datetime |
||
| 151 | * @param string $time Time in hh:mm:ss format |
||
| 152 | * @param string $datetime Datetime as accepted by the Datetime class constructor |
||
| 153 | * @param bool $operation True for Add, False to Subtract |
||
| 154 | * @return string |
||
| 155 | */ |
||
| 156 | public static function addOrSubTimeToDateTime($time, $datetime = 'now', $operation = true) |
||
| 175 | } |
||
| 176 |