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 |
||
36 | class BlockRepository extends AbstractRepository |
||
37 | { |
||
38 | |||
39 | /** |
||
40 | 14 | * @deprecated 呼び出し元で制御する |
|
41 | * @param $block_id |
||
42 | 14 | * @param $DeviceType |
|
43 | * @return array|\Eccube\Entity\Block |
||
44 | */ |
||
45 | 5 | public function findOrCreate($block_id, $DeviceType) |
|
46 | { |
||
47 | |||
48 | 5 | if ($block_id == null) { |
|
49 | 1 | return $this->newBlock($DeviceType); |
|
50 | } else { |
||
51 | 5 | return $this->getBlock($block_id, $DeviceType); |
|
52 | } |
||
53 | |||
54 | } |
||
55 | |||
56 | 1 | public function newBlock($DeviceType) |
|
57 | { |
||
58 | 1 | $Block = new \Eccube\Entity\Block(); |
|
59 | $Block |
||
60 | 1 | ->setDeviceType($DeviceType) |
|
61 | 1 | ->setLogicFlg(0) |
|
62 | 1 | ->setDeletableFlg(1); |
|
63 | |||
64 | 1 | return $Block; |
|
65 | } |
||
66 | |||
67 | /** |
||
68 | * @deprecated since 3.0.0, to be removed in 3.1 |
||
69 | */ |
||
70 | private function getNewBlockId($DeviceType) |
||
82 | |||
83 | /** |
||
84 | * ブロックの情報を取得. |
||
85 | * |
||
86 | * @deprecated Use magic finder methods. BlockRepository::findOneByIdAndDeviceType() |
||
87 | * @param integer $block_id ブロックID |
||
88 | * @param \Eccube\Entity\Master\DeviceType $DeviceType |
||
89 | * @return Block |
||
90 | 6 | */ |
|
91 | public function getBlock($block_id, $DeviceType) |
||
100 | |||
101 | /** |
||
102 | * ブロック一覧の取得. |
||
103 | * |
||
104 | * @param \Eccube\Entity\Master\DeviceType $DeviceType |
||
105 | * @return array |
||
106 | 3 | */ |
|
107 | public function getList($DeviceType) |
||
120 | |||
121 | /** |
||
122 | * ページの属性を取得する. |
||
123 | * |
||
124 | * この関数は, dtb_pagelayout の情報を検索する. |
||
125 | * $deviceTypeId は必須. デフォルト値は DEVICE_TYPE_PC. |
||
126 | * |
||
127 | * @access public |
||
128 | * @param DeviceType $DeviceType 端末種別ID |
||
129 | * @param string $where 追加の検索条件 |
||
130 | * @param string[] $parameters 追加の検索パラメーター |
||
131 | * @return array ページ属性の配列 |
||
132 | * @deprecated since 3.0.0, to be removed in 3.1 |
||
133 | */ |
||
134 | View Code Duplication | public function getPageList(DeviceType $DeviceType, $where = null, $parameters = array()) |
|
155 | |||
156 | /** |
||
157 | * 書き込みパスの取得 |
||
158 | * User定義の場合: /html/user_data |
||
159 | * そうでない場合: /app/template/{template_code} |
||
160 | * |
||
161 | * @param boolean $isUser |
||
162 | * @return string |
||
163 | * |
||
164 | * @deprecated since 3.0.0, to be removed in 3.1 |
||
165 | */ |
||
166 | public function getWriteTemplatePath($isUser = false) |
||
170 | |||
171 | /** |
||
172 | * 読み込みファイルの取得 |
||
173 | * |
||
174 | * 1. block_realdir |
||
175 | * app/template/{template_code}/block |
||
176 | * 2. block_default_readldir |
||
177 | * src/Eccube/Resource/template/default/block |
||
178 | * |
||
179 | * @param string $fileName |
||
180 | * @param boolean $isUser |
||
181 | * |
||
182 | * @return array |
||
183 | 6 | */ |
|
184 | public function getReadTemplateFile($fileName, $isUser = false) |
||
201 | } |
||
202 |