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 /** MicroACL */ |
||
24 | abstract class Acl implements Adapter |
||
25 | { |
||
26 | /** @var IDriver $db */ |
||
27 | protected $db; |
||
28 | /** @var string $groupTable name of group table */ |
||
29 | protected $groupTable; |
||
30 | |||
31 | |||
32 | /** |
||
33 | * Base constructor for ACL, make acl_user table if exists |
||
34 | * |
||
35 | * @access public |
||
36 | * |
||
37 | * @param IConnection $db |
||
38 | * @param array $params config array |
||
39 | * |
||
40 | * @result void |
||
41 | */ |
||
42 | public function __construct(IConnection $db, array $params = []) |
||
60 | |||
61 | /** |
||
62 | * Get permissions in role |
||
63 | * |
||
64 | * @access protected |
||
65 | * |
||
66 | * @param string $role role name |
||
67 | * |
||
68 | * @return array |
||
69 | * @abstract |
||
70 | */ |
||
71 | abstract protected function rolePerms($role); |
||
72 | } |
||
73 |
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.