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 |
||
| 32 | class EccubeExtension extends \Twig_Extension |
||
|
|
|||
| 33 | { |
||
| 34 | private $app; |
||
| 35 | 203 | ||
| 36 | public function __construct(Application $app) |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Returns a list of functions to add to the existing list. |
||
| 43 | * |
||
| 44 | * @return array An array of functions |
||
| 45 | 83 | */ |
|
| 46 | public function getFunctions() |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Returns a list of filters. |
||
| 64 | * |
||
| 65 | * @return array |
||
| 66 | */ |
||
| 67 | 83 | public function getFilters() |
|
| 77 | 175 | ||
| 78 | /** |
||
| 79 | * Name of this extension |
||
| 80 | * |
||
| 81 | * @return string |
||
| 82 | */ |
||
| 83 | public function getName() |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Name of this extension |
||
| 90 | * |
||
| 91 | * @return string |
||
| 92 | */ |
||
| 93 | public function getCalcIncTax($price, $tax_rate, $tax_rule) |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Name of this extension |
||
| 100 | * |
||
| 101 | * @param array $menus |
||
| 102 | * @return array |
||
| 103 | */ |
||
| 104 | public function getActiveMenus($menus = array()) |
||
| 113 | |||
| 114 | 7 | /** |
|
| 115 | * Name of this extension |
||
| 116 | * |
||
| 117 | * @return string |
||
| 118 | */ |
||
| 119 | public function getCsrfTokenForAnchor() |
||
| 124 | 1 | ||
| 125 | /** |
||
| 126 | * return No Image filename |
||
| 127 | * |
||
| 128 | * @return string |
||
| 129 | */ |
||
| 130 | public function getNoImageProduct($image) |
||
| 134 | |||
| 135 | 1 | /** |
|
| 136 | * Name of this extension |
||
| 137 | * |
||
| 138 | * @return string |
||
| 139 | */ |
||
| 140 | public function getDateFormatFilter($date, $value = '', $format = 'Y/m/d') |
||
| 148 | |||
| 149 | 31 | /** |
|
| 150 | * Name of this extension |
||
| 151 | 31 | * |
|
| 152 | * @return string |
||
| 153 | */ |
||
| 154 | public function getPriceFilter($number, $decimals = 0, $decPoint = '.', $thousandsSep = ',') |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Name of this extension |
||
| 164 | * |
||
| 165 | * @return string |
||
| 166 | */ |
||
| 167 | public function getEllipsis($value, $length = 100, $end = '...') |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Name of this extension |
||
| 174 | * |
||
| 175 | * @return string |
||
| 176 | */ |
||
| 177 | public function getTimeAgo($date) |
||
| 181 | |||
| 182 | /** |
||
| 183 | * bind から URL へ変換します。 |
||
| 184 | * \Symfony\Bridge\Twig\Extension\RoutingExtension::getPath の処理を拡張し、 |
||
| 185 | * RouteNotFoundException 発生時に E_USER_WARNING を発生させ、 |
||
| 186 | * 文字列 "/404?bind={bind}" を返します。 |
||
| 187 | * |
||
| 188 | * @param string $name |
||
| 189 | * @param array $parameters |
||
| 190 | * @param boolean $relative |
||
| 191 | * @return string URL |
||
| 192 | */ |
||
| 193 | View Code Duplication | public function getPath($name, $parameters = array(), $relative = false) |
|
| 204 | |||
| 205 | /** |
||
| 206 | * bind から URL へ変換します。 |
||
| 207 | * \Symfony\Bridge\Twig\Extension\RoutingExtension::getUrl の処理を拡張し、 |
||
| 208 | * RouteNotFoundException 発生時に E_USER_WARNING を発生させ、 |
||
| 209 | * 文字列 "/404?bind={bind}" を返します。 |
||
| 210 | * |
||
| 211 | * @param string $name |
||
| 212 | * @param array $parameters |
||
| 213 | * @param boolean $schemeRelative |
||
| 214 | * @return string URL |
||
| 215 | */ |
||
| 216 | View Code Duplication | public function getUrl($name, $parameters = array(), $schemeRelative = false) |
|
| 227 | } |
||
| 228 |