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 |
||
15 | class WorkflowFieldActionController extends RequestHandler |
||
16 | { |
||
17 | private static $url_handlers = array( |
||
|
|||
18 | 'new/$Class' => 'handleAdd', |
||
19 | 'item/$ID' => 'handleItem' |
||
20 | ); |
||
21 | |||
22 | private static $allowed_actions = array( |
||
23 | 'handleAdd', |
||
24 | 'handleItem' |
||
25 | ); |
||
26 | |||
27 | protected $parent; |
||
28 | protected $name; |
||
29 | |||
30 | public function __construct($parent, $name) |
||
37 | |||
38 | public function handleAdd() |
||
61 | |||
62 | View Code Duplication | public function handleItem() |
|
78 | |||
79 | public function RootField() |
||
83 | |||
84 | public function Link($action = null) |
||
88 | |||
89 | /** |
||
90 | * Sanitise a model class' name for inclusion in a link |
||
91 | * |
||
92 | * @param string $class |
||
93 | * @return string |
||
94 | */ |
||
95 | protected function sanitiseClassName($class) |
||
99 | |||
100 | /** |
||
101 | * Unsanitise a model class' name from a URL param |
||
102 | * |
||
103 | * @param string $class |
||
104 | * @return string |
||
105 | */ |
||
106 | protected function unsanitiseClassName($class) |
||
110 | } |
||
111 |