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 | |||
36 | 483 | 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 | */ |
||
46 | 99 | public function getFunctions() |
|
62 | |||
63 | /** |
||
64 | * Returns a list of filters. |
||
65 | * |
||
66 | * @return array |
||
67 | 99 | */ |
|
68 | public function getFilters() |
||
78 | |||
79 | /** |
||
80 | * Name of this extension |
||
81 | * |
||
82 | * @return string |
||
83 | 483 | */ |
|
84 | public function getName() |
||
88 | |||
89 | /** |
||
90 | * Name of this extension |
||
91 | * |
||
92 | * @return string |
||
93 | 19 | */ |
|
94 | public function getCalcIncTax($price, $tax_rate, $tax_rule) |
||
98 | |||
99 | /** |
||
100 | * Name of this extension |
||
101 | * |
||
102 | * @param array $menus |
||
103 | * @return array |
||
104 | 145 | */ |
|
105 | public function getActiveMenus($menus = array()) |
||
114 | |||
115 | /** |
||
116 | * Name of this extension |
||
117 | * |
||
118 | * @return string |
||
119 | 27 | */ |
|
120 | public function getCsrfTokenForAnchor() |
||
125 | |||
126 | /** |
||
127 | * return No Image filename |
||
128 | * |
||
129 | * @return string |
||
130 | 40 | */ |
|
131 | public function getNoImageProduct($image) |
||
135 | |||
136 | /** |
||
137 | * Name of this extension |
||
138 | * |
||
139 | * @return string |
||
140 | 14 | */ |
|
141 | public function getDateFormatFilter($date, $value = '', $format = 'Y/m/d') |
||
149 | |||
150 | /** |
||
151 | * Name of this extension |
||
152 | * |
||
153 | * @return string |
||
154 | 120 | */ |
|
155 | public function getPriceFilter($number, $decimals = 0, $decPoint = '.', $thousandsSep = ',') |
||
162 | |||
163 | /** |
||
164 | * Name of this extension |
||
165 | * |
||
166 | * @return string |
||
167 | */ |
||
168 | public function getEllipsis($value, $length = 100, $end = '...') |
||
172 | |||
173 | /** |
||
174 | * Name of this extension |
||
175 | * |
||
176 | * @return string |
||
177 | */ |
||
178 | public function getTimeAgo($date) |
||
182 | |||
183 | /** |
||
184 | * bind から URL へ変換します。 |
||
185 | * \Symfony\Bridge\Twig\Extension\RoutingExtension::getPath の処理を拡張し、 |
||
186 | * RouteNotFoundException 発生時に E_USER_WARNING を発生させ、 |
||
187 | * 文字列 "/404?bind={bind}" を返します。 |
||
188 | * |
||
189 | * @param string $name |
||
190 | * @param array $parameters |
||
191 | * @param boolean $relative |
||
192 | * @return string URL |
||
193 | 225 | */ |
|
194 | View Code Duplication | public function getPath($name, $parameters = array(), $relative = false) |
|
205 | |||
206 | /** |
||
207 | * bind から URL へ変換します。 |
||
208 | * \Symfony\Bridge\Twig\Extension\RoutingExtension::getUrl の処理を拡張し、 |
||
209 | * RouteNotFoundException 発生時に E_USER_WARNING を発生させ、 |
||
210 | * 文字列 "/404?bind={bind}" を返します。 |
||
211 | * |
||
212 | * @param string $name |
||
213 | * @param array $parameters |
||
214 | * @param boolean $schemeRelative |
||
215 | * @return string URL |
||
216 | 249 | */ |
|
217 | View Code Duplication | public function getUrl($name, $parameters = array(), $schemeRelative = false) |
|
228 | |||
229 | /** |
||
230 | * Check if the value is object |
||
231 | * |
||
232 | * @param object $value |
||
233 | * @return bool |
||
234 | */ |
||
235 | public function isObject($value) |
||
239 | } |
||
240 |