Complex classes like EccubeExtension often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use EccubeExtension, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
28 | class EccubeExtension extends AbstractExtension |
||
29 | { |
||
30 | /** |
||
31 | 471 | * @var EccubeConfig |
|
32 | */ |
||
33 | 471 | protected $eccubeConfig; |
|
34 | |||
35 | /** |
||
36 | * @var ProductRepository |
||
37 | */ |
||
38 | private $productRepository; |
||
39 | |||
40 | /** |
||
41 | 241 | * EccubeExtension constructor. |
|
42 | * |
||
43 | * @param EccubeConfig $eccubeConfig |
||
44 | 241 | * @param ProductRepository $productRepository |
|
45 | 241 | */ |
|
46 | 241 | public function __construct(EccubeConfig $eccubeConfig, ProductRepository $productRepository) |
|
51 | 10 | ||
52 | /** |
||
53 | * Returns a list of functions to add to the existing list. |
||
54 | 241 | * |
|
55 | * @return TwigFunction[] An array of functions |
||
56 | */ |
||
57 | public function getFunctions() |
||
68 | 241 | ||
69 | 241 | /** |
|
70 | 241 | * Returns a list of filters. |
|
71 | 241 | * |
|
72 | * @return TwigFilter[] |
||
73 | */ |
||
74 | public function getFilters() |
||
85 | |||
86 | /** |
||
87 | * Name of this extension |
||
88 | * |
||
89 | * @return string |
||
90 | */ |
||
91 | public function getName() |
||
95 | 153 | ||
96 | 113 | /** |
|
97 | * Name of this extension |
||
98 | * |
||
99 | 153 | * @param array $menus |
|
100 | * |
||
101 | * @return array |
||
102 | */ |
||
103 | public function getActiveMenus($menus = []) |
||
112 | |||
113 | /** |
||
114 | * return No Image filename |
||
115 | * |
||
116 | * @return string |
||
117 | */ |
||
118 | public function getNoImageProduct($image) |
||
122 | |||
123 | /** |
||
124 | * Name of this extension |
||
125 | * |
||
126 | * @return string |
||
127 | */ |
||
128 | public function getDateFormatFilter($date, $value = '', $format = 'Y/m/d') |
||
136 | |||
137 | 142 | /** |
|
138 | * Name of this extension |
||
139 | * |
||
140 | * @return string |
||
141 | */ |
||
142 | public function getPriceFilter($number, $decimals = 0, $decPoint = '.', $thousandsSep = ',') |
||
150 | |||
151 | /** |
||
152 | * Name of this extension |
||
153 | * |
||
154 | * @return string |
||
155 | */ |
||
156 | public function getEllipsis($value, $length = 100, $end = '...') |
||
160 | |||
161 | /** |
||
162 | * Name of this extension |
||
163 | * |
||
164 | * @return string |
||
165 | 13 | */ |
|
166 | public function getTimeAgo($date) |
||
170 | 13 | ||
171 | 13 | /** |
|
172 | * FormView にエラーが含まれるかを返す. |
||
173 | * |
||
174 | 13 | * @return bool |
|
175 | 1 | */ |
|
176 | 13 | public function hasErrors() |
|
193 | |||
194 | /** |
||
195 | * product_idで指定したProductを取得 |
||
196 | * Productが取得できない場合、または非公開の場合、商品情報は表示させない。 |
||
197 | * デバッグ環境以外ではProductが取得できなくでもエラー画面は表示させず無視される。 |
||
198 | * |
||
199 | * @param $id |
||
200 | * |
||
201 | * @return Product|null |
||
202 | */ |
||
203 | public function getProduct($id) |
||
217 | |||
218 | /** |
||
219 | * Twigでphp関数を使用できるようにする。 |
||
220 | * |
||
221 | * @return mixed|null |
||
222 | */ |
||
223 | public function getPhpFunctions() |
||
236 | |||
237 | /** |
||
238 | * Get the ClassCategories as JSON. |
||
239 | 16 | * |
|
240 | 16 | * @param Product $Product |
|
241 | * |
||
242 | * @return string |
||
243 | */ |
||
244 | 16 | public function getClassCategoriesAsJson(Product $Product) |
|
295 | |||
296 | /** |
||
297 | * Display file extension icon |
||
298 | * |
||
299 | * @param $ext |
||
300 | * @param $attr |
||
301 | * @param $iconOnly アイコンのクラス名のみ返す場合はtrue |
||
302 | * |
||
303 | * @return string |
||
304 | */ |
||
305 | public function getExtensionIcon($ext, $attr = [], $iconOnly = false) |
||
356 | |||
357 | /** |
||
358 | * Get currency symbol |
||
359 | * |
||
360 | * @param null $currency |
||
361 | * |
||
362 | * @return bool|string |
||
363 | */ |
||
364 | public function getCurrencySymbol($currency = null) |
||
373 | } |
||
374 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.