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 Tree extends Model |
||
| 10 | { |
||
| 11 | use AdminBuilder, ModelTree; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Create a new Eloquent model instance. |
||
| 15 | * |
||
| 16 | * @param array $attributes |
||
| 17 | */ |
||
| 18 | public function __construct(array $attributes = []) |
||
| 19 | { |
||
| 20 | $connection = config('admin.database.connection') ?: config('database.default'); |
||
| 21 | |||
| 22 | $this->setConnection($connection); |
||
| 23 | |||
| 24 | $this->setTable(config('admin.database.menu_table')); |
||
| 25 | |||
| 26 | parent::__construct($attributes); |
||
| 27 | } |
||
| 28 | } |
||
| 29 |