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 |
||
8 | View Code Duplication | class BantenprovTingkat extends Seeder |
|
9 | { |
||
10 | /* text color */ |
||
11 | protected $RED ="\033[0;31m"; |
||
12 | protected $CYAN ="\033[0;36m"; |
||
13 | protected $YELLOW ="\033[1;33m"; |
||
14 | protected $ORANGE ="\033[0;33m"; |
||
15 | protected $PUR ="\033[0;35m"; |
||
16 | protected $GRN ="\e[32m"; |
||
17 | protected $WHI ="\e[37m"; |
||
18 | protected $NC ="\033[0m"; |
||
19 | /* File name */ |
||
20 | /* location : /databse/seeds/file_name.csv */ |
||
21 | protected $fileName = "BantenprovTingkat.csv"; |
||
22 | /* text info : default (true) */ |
||
23 | protected $textInfo = true; |
||
24 | /* model class */ |
||
25 | protected $model; |
||
26 | /* __construct */ |
||
27 | public function __construct(){ |
||
30 | /** |
||
31 | * Run the database seeds. |
||
32 | * |
||
33 | * @return void |
||
34 | */ |
||
35 | public function run() |
||
39 | /* function insert data */ |
||
40 | protected function insertData() |
||
65 | /* text color: orange */ |
||
66 | protected function orangeText($text) |
||
70 | /* text color: green */ |
||
71 | protected function greenText($text) |
||
75 | /* function read CSV file */ |
||
76 | protected function readCSV() |
||
89 | } |
||
90 |
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.