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 |
||
33 | class EccubeExtension extends \Twig_Extension |
||
|
|||
34 | { |
||
35 | private $app; |
||
36 | |||
37 | 1178 | public function __construct(Application $app) |
|
41 | |||
42 | /** |
||
43 | * Returns a list of functions to add to the existing list. |
||
44 | * |
||
45 | * @return array An array of functions |
||
46 | */ |
||
47 | 96 | public function getFunctions() |
|
91 | |||
92 | /** |
||
93 | * Returns a list of filters. |
||
94 | * |
||
95 | 10 | * @return array |
|
96 | */ |
||
97 | 10 | public function getFilters() |
|
107 | |||
108 | 142 | public function getTokenParsers() |
|
112 | |||
113 | 142 | /** |
|
114 | * Name of this extension |
||
115 | * |
||
116 | * @return string |
||
117 | */ |
||
118 | public function getName() |
||
122 | |||
123 | 27 | /** |
|
124 | 27 | * Name of this extension |
|
125 | * |
||
126 | * @return string |
||
127 | */ |
||
128 | public function getCalcIncTax($price, $tax_rate, $tax_rule) |
||
132 | 8 | ||
133 | /** |
||
134 | 8 | * Name of this extension |
|
135 | * |
||
136 | * @param array $menus |
||
137 | * @return array |
||
138 | */ |
||
139 | public function getActiveMenus($menus = array()) |
||
148 | |||
149 | /** |
||
150 | * Name of this extension |
||
151 | * |
||
152 | * @return string |
||
153 | */ |
||
154 | public function getCsrfTokenForAnchor() |
||
159 | 87 | ||
160 | /** |
||
161 | 87 | * return No Image filename |
|
162 | * |
||
163 | * @return string |
||
164 | */ |
||
165 | public function getNoImageProduct($image) |
||
169 | |||
170 | /** |
||
171 | * Name of this extension |
||
172 | * |
||
173 | * @return string |
||
174 | */ |
||
175 | public function getDateFormatFilter($date, $value = '', $format = 'Y/m/d') |
||
183 | |||
184 | /** |
||
185 | * Name of this extension |
||
186 | * |
||
187 | * @return string |
||
188 | */ |
||
189 | public function getPriceFilter($number, $decimals = 0, $decPoint = '.', $thousandsSep = ',') |
||
196 | |||
197 | 225 | /** |
|
198 | * Name of this extension |
||
199 | 225 | * |
|
200 | * @return string |
||
201 | */ |
||
202 | public function getEllipsis($value, $length = 100, $end = '...') |
||
206 | |||
207 | /** |
||
208 | * Name of this extension |
||
209 | * |
||
210 | * @return string |
||
211 | */ |
||
212 | public function getTimeAgo($date) |
||
216 | |||
217 | /** |
||
218 | 216 | * bind から URL へ変換します。 |
|
219 | * \Symfony\Bridge\Twig\Extension\RoutingExtension::getPath の処理を拡張し、 |
||
220 | 216 | * RouteNotFoundException 発生時に E_USER_WARNING を発生させ、 |
|
221 | * 文字列 "/404?bind={bind}" を返します。 |
||
222 | 216 | * |
|
223 | * @param string $name |
||
224 | * @param array $parameters |
||
225 | * @param boolean $relative |
||
226 | * @return string URL |
||
227 | */ |
||
228 | View Code Duplication | public function getPath($name, $parameters = array(), $relative = false) |
|
239 | |||
240 | /** |
||
241 | * bind から URL へ変換します。 |
||
242 | * \Symfony\Bridge\Twig\Extension\RoutingExtension::getUrl の処理を拡張し、 |
||
243 | * RouteNotFoundException 発生時に E_USER_WARNING を発生させ、 |
||
244 | * 文字列 "/404?bind={bind}" を返します。 |
||
245 | * |
||
246 | * @param string $name |
||
247 | * @param array $parameters |
||
248 | * @param boolean $schemeRelative |
||
249 | * @return string URL |
||
250 | */ |
||
251 | View Code Duplication | public function getUrl($name, $parameters = array(), $schemeRelative = false) |
|
262 | |||
263 | /** |
||
264 | * Check if the value is object |
||
265 | * |
||
266 | * @param object $value |
||
267 | * @return bool |
||
268 | */ |
||
269 | public function isObject($value) |
||
273 | } |
||
274 |