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 |
||
4 | class UpdateSecondHandProduct extends Controller |
||
|
|||
5 | { |
||
6 | |||
7 | private static $allowed_actions = array( |
||
8 | 'unpublish' => '->MyPermissionCheck', |
||
9 | 'archive' => '->MyPermissionCheck' |
||
10 | ); |
||
11 | |||
12 | |||
13 | /** |
||
14 | * make the page less easy to access |
||
15 | * (but still accessible) |
||
16 | * - code => ip address |
||
17 | * @var string |
||
18 | */ |
||
19 | private static $secret_codes = array(); |
||
20 | |||
21 | function init() |
||
28 | |||
29 | function unpublish($request) |
||
40 | |||
41 | function archive($request) |
||
55 | |||
56 | /** |
||
57 | * @return Boolean |
||
58 | */ |
||
59 | View Code Duplication | function MyPermissionCheck() |
|
78 | } |
||
79 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.