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 |
||
| 7 | class UserTableSeeder extends Seeder |
||
| 8 | { |
||
| 9 | public function run() |
||
| 10 | { |
||
| 11 | factory(\Tests\Models\User::class, 50) |
||
| 12 | ->create() |
||
| 13 | ->each(function ($u) { |
||
| 14 | $u->profile()->save(factory(\Tests\Models\Profile::class)->make()); |
||
| 15 | $u->tags()->saveMany(factory(\Tests\Models\Tag::class, 5)->make()); |
||
| 16 | }); |
||
| 17 | } |
||
| 18 | } |
||
| 19 |