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 |
||
37 | class RbacDefinitionConfigHandler extends XmlConfigHandler |
||
38 | { |
||
39 | const XML_NAMESPACE = 'http://agavi.org/agavi/config/parts/rbac_definitions/1.1'; |
||
40 | |||
41 | /** |
||
42 | * Execute this configuration handler. |
||
43 | * |
||
44 | * @param XmlConfigDomDocument $document The document to parse. |
||
45 | * |
||
46 | * @return string Data to be written to a cache file. |
||
47 | * |
||
48 | * @throws <b>UnreadableException</b> If a requested configuration |
||
49 | * file does not exist or is not |
||
50 | * readable. |
||
51 | * @throws <b>ParseException</b> If a requested configuration file is |
||
52 | * improperly formatted. |
||
53 | * |
||
54 | * @author David Zülke <[email protected]> |
||
55 | * @since 0.11.0 |
||
56 | */ |
||
57 | View Code Duplication | public function execute(XmlConfigDomDocument $document) |
|
76 | |||
77 | /** |
||
78 | * Parse a 'roles' node. |
||
79 | * |
||
80 | * @param mixed $roles The "roles" node (element or node list) |
||
81 | * @param string $parent The name of the parent role, or null. |
||
82 | * @param array $data A reference to the output data array. |
||
83 | * |
||
84 | * @author David Zülke <[email protected]> |
||
85 | * @since 0.11.0 |
||
86 | */ |
||
87 | protected function parseRoles($roles, $parent, &$data) |
||
107 | } |
||
108 |
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.