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 |
||
21 | class Credo |
||
22 | { |
||
23 | /** |
||
24 | * @var \Doctrine\ORM\EntityManager |
||
25 | */ |
||
26 | protected $entityManager; |
||
27 | |||
28 | /** |
||
29 | * @param \CI_DB_query_builder $database |
||
30 | */ |
||
31 | 9 | public function __construct(\CI_DB_query_builder $database) |
|
44 | |||
45 | /** |
||
46 | * Sets up the database configuration from CodeIgniter. |
||
47 | * |
||
48 | * @param \CI_DB_query_builder $database |
||
49 | * @return array |
||
50 | */ |
||
51 | 9 | private function setDatabaseConnection(\CI_DB_query_builder $database) |
|
76 | |||
77 | /** |
||
78 | * Calls methods from EntityManager in underscore case. |
||
79 | * |
||
80 | * @param string $method |
||
81 | * @param mixed $parameters |
||
82 | * @return mixed |
||
83 | */ |
||
84 | 15 | View Code Duplication | public function __call($method, $parameters) |
97 | } |
||
98 |
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.