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 | abstract class Entity extends Entitizer { |
||
8 | |||
9 | use Entity\Action\Init, Entity\Action\Create, Entity\Action\Fill, Entity\Action\Edit, Entity\Action\Remove; |
||
10 | |||
11 | protected $definition = null, $error = false, $id = 0, $data = []; |
||
12 | |||
13 | # Init parent entities |
||
14 | |||
15 | private function getPath() { |
||
32 | |||
33 | # Constructor |
||
34 | |||
35 | public function __construct(int $id = 0) { |
||
57 | |||
58 | # Check if unique param value exists |
||
59 | |||
60 | public function check(string $name, $value) { |
||
76 | |||
77 | # Count children |
||
78 | |||
79 | public function children() { |
||
89 | |||
90 | # Check for error |
||
91 | |||
92 | public function error() { |
||
96 | |||
97 | # Return id |
||
98 | |||
99 | public function id() { |
||
103 | |||
104 | # Return data |
||
105 | |||
106 | public function data() { |
||
110 | |||
111 | # Getter |
||
112 | |||
113 | public function __get(string $name) { |
||
119 | } |
||
120 | } |
||
121 |