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 |
||
22 | class AccountCommand extends AbstractCommand |
||
23 | { |
||
24 | /** |
||
25 | * The console command name. |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | protected $name = 'aimeos:account'; |
||
30 | |||
31 | /** |
||
32 | * The console command description. |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $description = 'Creates new (admin) accounts'; |
||
37 | |||
38 | |||
39 | /** |
||
40 | * Execute the console command. |
||
41 | * |
||
42 | * @return mixed |
||
43 | */ |
||
44 | public function fire() |
||
67 | |||
68 | |||
69 | /** |
||
70 | * Associates the user to the group by their given IDs |
||
71 | * |
||
72 | * @param \Aimeos\MShop\Context\Item\Iface $context Aimeos context object |
||
73 | * @param string $userid Unique user ID |
||
74 | * @param string $groupid Unique group ID |
||
75 | */ |
||
76 | protected function addListItem( \Aimeos\MShop\Context\Item\Iface $context, $userid, $groupid ) |
||
103 | |||
104 | |||
105 | /** |
||
106 | * Adds the group to the given user |
||
107 | * |
||
108 | * @param \Aimeos\MShop\Context\Item\Iface $context Aimeos context object |
||
109 | * @param \Aimeos\MShop\Customer\Item\Iface $user Aimeos customer object |
||
110 | * @param string $group Unique customer group code |
||
111 | */ |
||
112 | protected function addGroup( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MShop\Customer\Item\Iface $user, $group ) |
||
131 | |||
132 | |||
133 | /** |
||
134 | * Returns the customer item for the given e-mail and set its password |
||
135 | * |
||
136 | * If the customer doesn't exist yet, it will be created. |
||
137 | * |
||
138 | * @param \Aimeos\MShop\Context\Item\Iface $context Aimeos context object |
||
139 | * @param string $email Unique e-mail address |
||
140 | * @param string $password New user password |
||
141 | * @return \Aimeos\MShop\Customer\Item\Iface Aimeos customer item object |
||
142 | */ |
||
143 | View Code Duplication | protected function createCustomerItem( \Aimeos\MShop\Context\Item\Iface $context, $email, $password ) |
|
161 | |||
162 | |||
163 | /** |
||
164 | * Get the console command arguments. |
||
165 | * |
||
166 | * @return array |
||
167 | */ |
||
168 | protected function getArguments() |
||
175 | |||
176 | |||
177 | /** |
||
178 | * Returns the customer group item for the given code |
||
179 | * |
||
180 | * @param \Aimeos\MShop\Context\Item\Iface $context Aimeos context object |
||
181 | * @param string $code Unique customer group code |
||
182 | * @return \Aimeos\MShop\Customer\Item\Group\Iface Aimeos customer group item object |
||
183 | */ |
||
184 | View Code Duplication | protected function getGroupItem( \Aimeos\MShop\Context\Item\Iface $context, $code ) |
|
203 | |||
204 | |||
205 | /** |
||
206 | * Get the console command options. |
||
207 | * |
||
208 | * @return array |
||
209 | */ |
||
210 | protected function getOptions() |
||
218 | } |
||
219 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.