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 |
||
11 | class ItemCollection extends ArrayCollection |
||
|
|||
12 | { |
||
13 | protected $type; |
||
14 | |||
15 | 197 | public function __construct($Items, $type = null) |
|
24 | |||
25 | 191 | public function reduce(\Closure $func, $initial = null) |
|
29 | |||
30 | // 明細種別ごとに返すメソッド作る |
||
31 | 188 | public function getProductClasses() |
|
38 | |||
39 | 188 | public function getDeliveryFees() |
|
46 | |||
47 | 188 | public function getCharges() |
|
54 | |||
55 | 188 | public function getDiscounts() |
|
62 | |||
63 | /** |
||
64 | * 同名の明細が存在するかどうか. |
||
65 | * |
||
66 | * TODO 暫定対応. 本来は明細種別でチェックする. |
||
67 | */ |
||
68 | View Code Duplication | public function hasProductByName($productName) |
|
78 | |||
79 | /** |
||
80 | * 指定した受注明細区分の明細が存在するかどうか. |
||
81 | * |
||
82 | * @param OrderItemType $OrderItemType 受注区分 |
||
83 | * |
||
84 | * @return bool |
||
85 | */ |
||
86 | View Code Duplication | public function hasItemByOrderItemType($OrderItemType) |
|
95 | |||
96 | public function getType() |
||
100 | |||
101 | 197 | public function sort() |
|
136 | } |
||
137 |