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 |
||
| 35 | class CustomerAddressRepository extends EntityRepository |
||
| 36 | { |
||
| 37 | /** |
||
| 38 | * @param \Eccube\Entity\Customer $Customer |
||
| 39 | * @param null $id |
||
|
|
|||
| 40 | * @return \Eccube\Entity\CustomerAddress|mixed |
||
| 41 | * @throws \Doctrine\ORM\NoResultException |
||
| 42 | * @throws \Doctrine\ORM\NonUniqueResultException |
||
| 43 | */ |
||
| 44 | 6 | public function findOrCreateByCustomerAndId(\Eccube\Entity\Customer $Customer, $id = null) |
|
| 45 | { |
||
| 46 | 6 | if (!$id) { |
|
| 47 | $CustomerAddress = new \Eccube\Entity\CustomerAddress(); |
||
| 48 | $CustomerAddress |
||
| 49 | 4 | ->setCustomer($Customer) |
|
| 50 | ->setDelFlg(0); |
||
| 51 | } else { |
||
| 52 | 4 | $qb = $this->createQueryBuilder('od') |
|
| 53 | 4 | ->andWhere('od.Customer = :Customer AND od.id = :id') |
|
| 54 | ->setParameters(array( |
||
| 55 | 'Customer' => $Customer, |
||
| 56 | 'id' => $id, |
||
| 57 | )); |
||
| 58 | |||
| 59 | $CustomerAddress = $qb |
||
| 60 | 4 | ->getQuery() |
|
| 61 | 1 | ->getSingleResult(); |
|
| 62 | 4 | } |
|
| 63 | |||
| 64 | 5 | return $CustomerAddress; |
|
| 65 | 6 | } |
|
| 66 | |||
| 67 | /** |
||
| 68 | * @param \Eccube\Entity\Customer $Customer |
||
| 69 | * @param integer $id |
||
| 70 | * @return bool |
||
| 71 | */ |
||
| 72 | 4 | View Code Duplication | public function deleteByCustomerAndId(\Eccube\Entity\Customer $Customer, $id) |
| 95 | } |
||
| 96 |