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 |
||
| 11 | class BantenprovAkademikSeeder extends Seeder |
||
|
|
|||
| 12 | { |
||
| 13 | /* text color */ |
||
| 14 | protected $RED ="\033[0;31m"; |
||
| 15 | protected $CYAN ="\033[0;36m"; |
||
| 16 | protected $YELLOW ="\033[1;33m"; |
||
| 17 | protected $ORANGE ="\033[0;33m"; |
||
| 18 | protected $PUR ="\033[0;35m"; |
||
| 19 | protected $GRN ="\e[32m"; |
||
| 20 | protected $WHI ="\e[37m"; |
||
| 21 | protected $NC ="\033[0m"; |
||
| 22 | |||
| 23 | /* File name */ |
||
| 24 | /* location : /databse/seeds/file_name.csv */ |
||
| 25 | protected $fileName = "BantenprovAkademikSeeder.csv"; |
||
| 26 | |||
| 27 | /* text info : default (true) */ |
||
| 28 | protected $textInfo = true; |
||
| 29 | |||
| 30 | /* model class */ |
||
| 31 | protected $model; |
||
| 32 | |||
| 33 | /* __construct */ |
||
| 34 | public function __construct(){ |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Run the database seeds. |
||
| 42 | * |
||
| 43 | * @return void |
||
| 44 | */ |
||
| 45 | public function run() |
||
| 49 | |||
| 50 | /* function insert data */ |
||
| 51 | protected function insertData() |
||
| 84 | |||
| 85 | /* text color: orange */ |
||
| 86 | protected function orangeText($text) |
||
| 90 | |||
| 91 | /* text color: green */ |
||
| 92 | protected function greenText($text) |
||
| 96 | |||
| 97 | /* function read CSV file */ |
||
| 98 | View Code Duplication | protected function readCSV() |
|
| 116 | } |
||
| 117 |
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.