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 |
||
30 | 1 | final class Configuration |
|
31 | { |
||
32 | /** |
||
33 | * Implement nette smart magic |
||
34 | */ |
||
35 | 1 | use Nette\SmartObject; |
|
36 | |||
37 | /** |
||
38 | * Flag if use lazy association or not |
||
39 | * |
||
40 | * @var bool |
||
41 | */ |
||
42 | public $lazyAssociation = FALSE; |
||
43 | |||
44 | /** |
||
45 | * User entity name |
||
46 | * |
||
47 | * @var string|NULL |
||
48 | */ |
||
49 | public $userEntity; |
||
50 | |||
51 | /** |
||
52 | * Automatically map filed if not set |
||
53 | * |
||
54 | * @var bool |
||
55 | */ |
||
56 | public $automapField = TRUE; |
||
57 | |||
58 | /** |
||
59 | * @param string|NULL $userEntity |
||
60 | * @param bool $lazyAssociation |
||
61 | * @param bool $automapField |
||
62 | */ |
||
63 | public function __construct(string $userEntity = NULL, bool $lazyAssociation = FALSE, bool $automapField = FALSE) |
||
69 | |||
70 | /** |
||
71 | * @return bool |
||
72 | */ |
||
73 | View Code Duplication | public function automapWithAssociation() : bool |
|
81 | |||
82 | /** |
||
83 | * @return bool |
||
84 | */ |
||
85 | View Code Duplication | public function automapWithField() : bool |
|
93 | |||
94 | /** |
||
95 | * @return bool |
||
96 | */ |
||
97 | public function useLazyAssociation() : bool |
||
101 | } |
||
102 |
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.