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 |
||
29 | class PageRepository extends AbstractRepository |
||
30 | { |
||
31 | /** |
||
32 | * @var EccubeConfig |
||
33 | */ |
||
34 | protected $eccubeConfig; |
||
35 | |||
36 | /** |
||
37 | * @var string |
||
38 | * @path %eccube_theme_user_data_dir% (app/template/user_data) |
||
39 | */ |
||
40 | protected $userDataRealDir; |
||
41 | |||
42 | /** |
||
43 | * @var string |
||
44 | * @path %eccube_theme_app_dir% (app/template) |
||
45 | */ |
||
46 | protected $templateRealDir; |
||
47 | |||
48 | /** |
||
49 | * @var string |
||
50 | * @path %eccube_theme_src_dir% (src/Eccube/Resource/template) |
||
51 | */ |
||
52 | protected $templateDefaultRealDir; |
||
53 | |||
54 | /** |
||
55 | * PageRepository constructor. |
||
56 | * |
||
57 | * @param RegistryInterface $registry |
||
58 | * @param EccubeConfig $eccubeConfig |
||
59 | * @param ContainerInterface $container |
||
60 | 712 | */ |
|
61 | public function __construct(RegistryInterface $registry, EccubeConfig $eccubeConfig, ContainerInterface $container) |
||
69 | |||
70 | /** |
||
71 | * @param DeviceType $DeviceType |
||
72 | * @param int $pageId |
||
73 | * |
||
74 | * @return array |
||
75 | 1 | */ |
|
76 | public function findUnusedBlocks(DeviceType $DeviceType, $pageId) |
||
97 | |||
98 | /** |
||
99 | * @param DeviceType $DeviceType |
||
100 | * @param int $pageId |
||
101 | * |
||
102 | * @return mixed |
||
103 | 5 | */ |
|
104 | public function getByDeviceTypeAndId(DeviceType $DeviceType, $pageId) |
||
149 | |||
150 | /** |
||
151 | * @param DeviceType $DeviceType |
||
152 | * @param string $url |
||
153 | * @throw NoResultException |
||
154 | * |
||
155 | 1 | * @return Page |
|
156 | */ |
||
157 | public function getByUrl(DeviceType $DeviceType, $url) |
||
176 | |||
177 | 1 | /** |
|
178 | * @param DeviceType $DeviceType |
||
179 | 1 | * |
|
180 | * @return Page |
||
181 | */ |
||
182 | public function newPage(DeviceType $DeviceType) |
||
191 | |||
192 | 1 | /** |
|
193 | 1 | * @param int $page_id |
|
194 | 1 | * @param DeviceType $DeviceType |
|
195 | 1 | * |
|
196 | * @return Page|mixed |
||
197 | 1 | */ |
|
198 | public function findOrCreate($page_id, DeviceType $DeviceType) |
||
209 | |||
210 | 1 | /** |
|
211 | * ページの属性を取得する. |
||
212 | * |
||
213 | * この関数は, dtb_Page の情報を検索する. |
||
214 | * $deviceTypeId は必須. デフォルト値は DEVICE_TYPE_PC. |
||
215 | 1 | * |
|
216 | * @param \Eccube\Entity\Master\DeviceType $DeviceType 端末種別ID |
||
217 | * @param string $where 追加の検索条件 |
||
218 | * @param string[] $parameters 追加の検索パラメーター |
||
219 | * |
||
220 | * @return array ページ属性の配列 |
||
221 | */ |
||
222 | View Code Duplication | public function getPageList(DeviceType $DeviceType, $where = null, $parameters = []) |
|
244 | } |
||
245 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.