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 |
||
10 | class NewsletterSubscriberPermissionProvider extends AbstractTwoWaySyncActionPermissionProvider |
||
11 | { |
||
12 | /** |
||
13 | * @var SecurityFacade |
||
14 | */ |
||
15 | protected $securityFacade; |
||
16 | |||
17 | /** |
||
18 | * @var bool|null |
||
19 | */ |
||
20 | protected $subscribeGranted; |
||
21 | |||
22 | /** |
||
23 | * @var bool|null |
||
24 | */ |
||
25 | protected $unsubscribeGranted; |
||
26 | |||
27 | /** |
||
28 | * @param ResultRecordInterface $record |
||
29 | * @param array $actions |
||
30 | * |
||
31 | * @return array |
||
32 | */ |
||
33 | public function getActionsPermissions(ResultRecordInterface $record, array $actions) |
||
60 | |||
61 | /** |
||
62 | * @param SecurityFacade $securityFacade |
||
63 | * @return NewsletterSubscriberPermissionProvider |
||
64 | */ |
||
65 | public function setSecurityFacade(SecurityFacade $securityFacade) |
||
71 | |||
72 | /** |
||
73 | * Check if channel integration is applicable for magento customer. |
||
74 | * Get channel integration id from customer channel if it's does not exist in grid record |
||
75 | * |
||
76 | * @param ResultRecordInterface $record |
||
77 | * @param bool $checkExtension |
||
78 | * |
||
79 | * @return bool |
||
80 | */ |
||
81 | View Code Duplication | protected function isChannelApplicable(ResultRecordInterface $record, $checkExtension = true) |
|
91 | |||
92 | /** |
||
93 | * @param ResultRecordInterface $record |
||
94 | * |
||
95 | * @return int|null |
||
96 | */ |
||
97 | protected function getChannelId(ResultRecordInterface $record) |
||
112 | |||
113 | /** |
||
114 | * @return bool |
||
115 | */ |
||
116 | protected function isSubscribeGranted() |
||
125 | |||
126 | /** |
||
127 | * @return bool |
||
128 | */ |
||
129 | protected function isUnsubscribeGranted() |
||
138 | } |
||
139 |
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.