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 | class BantenprovPrestasiSeederMasterPrestasi 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 = "BantenprovPrestasiSeederMasterPrestasi.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() |
||
| 80 | /* text color: orange */ |
||
| 81 | protected function orangeText($text) |
||
| 85 | /* text color: green */ |
||
| 86 | protected function greenText($text) |
||
| 90 | /* function read CSV file */ |
||
| 91 | View Code Duplication | protected function readCSV() |
|
| 109 | } |
||
| 110 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.