Conditions | 10 |
Paths | 13 |
Total Lines | 63 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
27 | public function run() |
||
28 | { |
||
29 | // Create 100 users |
||
30 | $users = factory(User::class, 100)->create(); |
||
31 | |||
32 | // Create 50 groups |
||
33 | $groups = factory(Group::class, 50)->create(); |
||
34 | |||
35 | // Create 10 positions |
||
36 | $positions = factory(Position::class, 10)->create(); |
||
37 | |||
38 | // Give each group 10 users and each role in the group 1 or 2 users |
||
39 | foreach ($groups as $group) { |
||
40 | foreach ($users->random(10) as $user) { |
||
41 | app(UserGroup::class)->addUserToGroup($user, $group); |
||
42 | } |
||
43 | |||
44 | $roles = collect(); |
||
45 | foreach ($positions->random(5) as $position) { |
||
46 | $roles->push(factory(Role::class)->create([ |
||
47 | 'group_id' => $group->id(), |
||
48 | 'position_id' => $position->id() |
||
49 | ])); |
||
50 | } |
||
51 | foreach ($roles as $role) { |
||
52 | foreach ($users->random(rand(1, 2)) as $user) { |
||
53 | app(UserRole::class)->addUserToRole($user, $role); |
||
54 | } |
||
55 | } |
||
56 | } |
||
57 | |||
58 | // Tag groups |
||
59 | factory(GroupTagCategory::class, 15)->create()->each(function (GroupTagCategory $groupTagCategory) { |
||
60 | factory(GroupTag::class, 15)->create(['tag_category_id' => $groupTagCategory->id()])->each(function (GroupTag $groupTag) { |
||
61 | foreach (Group::all()->random(10) as $group) { |
||
62 | app(GroupGroupTag::class)->addTagToGroup($groupTag, $group); |
||
63 | } |
||
64 | }); |
||
65 | }); |
||
66 | |||
67 | // Tag users |
||
68 | factory(UserTagCategory::class, 15)->create()->each(function (UserTagCategory $userTagCategory) { |
||
69 | factory(UserTag::class, 15)->create(['tag_category_id' => $userTagCategory->id()])->each(function (UserTag $userTag) { |
||
70 | foreach (User::all()->random(10) as $user) { |
||
71 | app(UserUserTag::class)->addTagToUser($userTag, $user); |
||
72 | } |
||
73 | }); |
||
74 | }); |
||
75 | |||
76 | // Tag roles |
||
77 | factory(RoleTagCategory::class, 15)->create()->each(function (RoleTagCategory $roleTagCategory) { |
||
78 | factory(RoleTag::class, 15)->create(['tag_category_id' => $roleTagCategory->id()])->each(function (RoleTag $roleTag) { |
||
79 | foreach (Role::all()->random(10) as $role) { |
||
80 | app(RoleRoleTag::class)->addTagToRole($roleTag, $role); |
||
81 | } |
||
82 | }); |
||
83 | }); |
||
84 | |||
85 | // Tag positions |
||
86 | factory(PositionTagCategory::class, 15)->create()->each(function (PositionTagCategory $positionTagCategory) { |
||
87 | factory(PositionTag::class, 15)->create(['tag_category_id' => $positionTagCategory->id()])->each(function (PositionTag $positionTag) { |
||
88 | foreach (Position::all()->random(10) as $position) { |
||
89 | app(PositionPositionTag::class)->addTagToPosition($positionTag, $position); |
||
90 | } |
||
96 | } |