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 |
||
| 14 | class CustomerGroup implements SubscriberInterface |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var ModelManager |
||
| 18 | */ |
||
| 19 | private $modelManager; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var Logger |
||
| 23 | */ |
||
| 24 | private $logger; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @param ModelManager $modelManager |
||
| 28 | * @param Logger $logger |
||
| 29 | */ |
||
| 30 | public function __construct(ModelManager $modelManager, Logger $logger) |
||
| 35 | |||
| 36 | /** |
||
| 37 | * {@inheritdoc} |
||
| 38 | */ |
||
| 39 | public static function getSubscribedEvents() |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Remove 'connect' customer group from the base store - except 'showConnect' is set |
||
| 50 | * |
||
| 51 | * @param \Enlight_Event_EventArgs $args |
||
| 52 | */ |
||
| 53 | public function filterCustomerGroup(\Enlight_Event_EventArgs $args) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * This one will remove connect from the default customer group query |
||
| 82 | * |
||
| 83 | * @param \Enlight_Hook_HookArgs $args |
||
| 84 | */ |
||
| 85 | public function filterCustomerGroupFromQueryBuilder(\Enlight_Hook_HookArgs $args) |
||
| 102 | |||
| 103 | /** |
||
| 104 | * This one is used by the category module e.g. |
||
| 105 | * |
||
| 106 | * @param \Enlight_Hook_HookArgs $args |
||
| 107 | */ |
||
| 108 | public function addToWithoutIdsQueryBuilder(\Enlight_Hook_HookArgs $args) |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Will return the id of the connect customer group - or null if no such group can be found |
||
| 126 | * |
||
| 127 | * @return int|null |
||
| 128 | */ |
||
| 129 | View Code Duplication | private function getConnectCustomerGroupId() |
|
| 142 | } |
||
| 143 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: