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 |
||
| 7 | class WorkflowFieldTransitionController extends RequestHandler { |
||
|
|
|||
| 8 | |||
| 9 | public static $url_handlers = array( |
||
| 10 | 'new/$ParentID!' => 'handleAdd', |
||
| 11 | 'item/$ID!' => 'handleItem' |
||
| 12 | ); |
||
| 13 | |||
| 14 | public static $allowed_actions = array( |
||
| 15 | 'handleAdd', |
||
| 16 | 'handleItem' |
||
| 17 | ); |
||
| 18 | |||
| 19 | protected $parent; |
||
| 20 | protected $name; |
||
| 21 | |||
| 22 | public function __construct($parent, $name) { |
||
| 23 | $this->parent = $parent; |
||
| 24 | $this->name = $name; |
||
| 25 | |||
| 26 | parent::__construct(); |
||
| 27 | } |
||
| 28 | |||
| 29 | public function handleAdd() { |
||
| 46 | |||
| 47 | View Code Duplication | public function handleItem() { |
|
| 61 | |||
| 62 | public function RootField() { |
||
| 65 | |||
| 66 | public function Link($action = null) { |
||
| 69 | |||
| 70 | } |
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.