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 |
||
9 | class DirectoryCreator |
||
10 | { |
||
11 | use Loggable, Paths; |
||
12 | |||
13 | /** |
||
14 | * Yarak config. |
||
15 | * |
||
16 | * @var Config |
||
17 | */ |
||
18 | protected $config; |
||
19 | |||
20 | /** |
||
21 | * Construct. |
||
22 | * |
||
23 | * @param Config $config |
||
24 | */ |
||
25 | public function __construct(Config $config) |
||
29 | |||
30 | /** |
||
31 | * Create all the directories and files necessary for Yarak DB functions. |
||
32 | */ |
||
33 | public function create() |
||
41 | |||
42 | /** |
||
43 | * Create all needed directories. |
||
44 | */ |
||
45 | protected function createAllDirectories() |
||
53 | |||
54 | /** |
||
55 | * Create factory file stub. |
||
56 | */ |
||
57 | View Code Duplication | protected function createFactoriesFile() |
|
72 | |||
73 | /** |
||
74 | * Create seeder file stub. |
||
75 | */ |
||
76 | View Code Duplication | protected function createSeederFile() |
|
91 | } |
||
92 |
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.