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 |
||
| 34 | class EccubeExtension extends \Twig_Extension |
||
|
|
|||
| 35 | { |
||
| 36 | private $app; |
||
| 37 | 1178 | ||
| 38 | public function __construct(Application $app) |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Returns a list of functions to add to the existing list. |
||
| 45 | * |
||
| 46 | * @return array An array of functions |
||
| 47 | 96 | */ |
|
| 48 | public function getFunctions() |
||
| 93 | |||
| 94 | /** |
||
| 95 | 10 | * Returns a list of filters. |
|
| 96 | * |
||
| 97 | 10 | * @return array |
|
| 98 | */ |
||
| 99 | public function getFilters() |
||
| 109 | 142 | ||
| 110 | 87 | public function getTokenParsers() |
|
| 114 | |||
| 115 | /** |
||
| 116 | * Name of this extension |
||
| 117 | * |
||
| 118 | * @return string |
||
| 119 | */ |
||
| 120 | public function getName() |
||
| 124 | 27 | ||
| 125 | /** |
||
| 126 | * Name of this extension |
||
| 127 | * |
||
| 128 | * @return string |
||
| 129 | */ |
||
| 130 | public function getCalcIncTax($price, $tax_rate, $tax_rule) |
||
| 134 | 8 | ||
| 135 | /** |
||
| 136 | * Name of this extension |
||
| 137 | * |
||
| 138 | * @param array $menus |
||
| 139 | * @return array |
||
| 140 | */ |
||
| 141 | public function getActiveMenus($menus = array()) |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Name of this extension |
||
| 153 | * |
||
| 154 | * @return string |
||
| 155 | */ |
||
| 156 | 87 | public function getCsrfTokenForAnchor() |
|
| 161 | 87 | ||
| 162 | /** |
||
| 163 | * return No Image filename |
||
| 164 | * |
||
| 165 | * @return string |
||
| 166 | */ |
||
| 167 | public function getNoImageProduct($image) |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Name of this extension |
||
| 174 | * |
||
| 175 | * @return string |
||
| 176 | */ |
||
| 177 | public function getDateFormatFilter($date, $value = '', $format = 'Y/m/d') |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Name of this extension |
||
| 188 | * |
||
| 189 | * @return string |
||
| 190 | */ |
||
| 191 | public function getPriceFilter($number, $decimals = 0, $decPoint = '.', $thousandsSep = ',') |
||
| 198 | |||
| 199 | 225 | /** |
|
| 200 | * Name of this extension |
||
| 201 | * |
||
| 202 | * @return string |
||
| 203 | */ |
||
| 204 | public function getEllipsis($value, $length = 100, $end = '...') |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Name of this extension |
||
| 211 | * |
||
| 212 | * @return string |
||
| 213 | */ |
||
| 214 | public function getTimeAgo($date) |
||
| 218 | 216 | ||
| 219 | /** |
||
| 220 | 216 | * bind から URL へ変換します。 |
|
| 221 | * \Symfony\Bridge\Twig\Extension\RoutingExtension::getPath の処理を拡張し、 |
||
| 222 | 216 | * RouteNotFoundException 発生時に E_USER_WARNING を発生させ、 |
|
| 223 | * 文字列 "/404?bind={bind}" を返します。 |
||
| 224 | * |
||
| 225 | * @param string $name |
||
| 226 | * @param array $parameters |
||
| 227 | * @param boolean $relative |
||
| 228 | * @return string URL |
||
| 229 | */ |
||
| 230 | View Code Duplication | public function getPath($name, $parameters = array(), $relative = false) |
|
| 241 | |||
| 242 | /** |
||
| 243 | * bind から URL へ変換します。 |
||
| 244 | * \Symfony\Bridge\Twig\Extension\RoutingExtension::getUrl の処理を拡張し、 |
||
| 245 | * RouteNotFoundException 発生時に E_USER_WARNING を発生させ、 |
||
| 246 | * 文字列 "/404?bind={bind}" を返します。 |
||
| 247 | * |
||
| 248 | * @param string $name |
||
| 249 | * @param array $parameters |
||
| 250 | * @param boolean $schemeRelative |
||
| 251 | * @return string URL |
||
| 252 | */ |
||
| 253 | View Code Duplication | public function getUrl($name, $parameters = array(), $schemeRelative = false) |
|
| 264 | |||
| 265 | /** |
||
| 266 | * Check if the value is object |
||
| 267 | * |
||
| 268 | * @param object $value |
||
| 269 | * @return bool |
||
| 270 | */ |
||
| 271 | public function isObject($value) |
||
| 275 | |||
| 276 | /** |
||
| 277 | * FormView にエラーが含まれるかを返す. |
||
| 278 | * |
||
| 279 | * @return bool |
||
| 280 | */ |
||
| 281 | public function hasErrors() |
||
| 298 | } |
||
| 299 |