Conditions | 5 |
Paths | 16 |
Total Lines | 83 |
Code Lines | 49 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
45 | public function run() : void |
||
46 | { |
||
47 | $adminUser = User::where('email', $this->adminEmail)->first(); |
||
48 | if ($adminUser === null) { |
||
49 | $adminUser = factory(User::class)->states('admin')->create(['email' => $this->adminEmail]); |
||
|
|||
50 | } |
||
51 | |||
52 | $managerUser = User::where('email', $this->managerEmail)->first(); |
||
53 | // Create the test manager if it does not exist yet |
||
54 | View Code Duplication | if ($managerUser === null) { |
|
55 | $managerUser = factory(User::class)->states('manager')->create(['email' => $this->managerEmail]); |
||
56 | $managerUser->manager()->save(factory(Manager::class)->create([ |
||
57 | 'user_id' => $managerUser->id |
||
58 | ])); |
||
59 | } |
||
60 | |||
61 | factory(JobPoster::class, 3)->states('published')->create([ |
||
62 | 'manager_id' => $managerUser->manager->id |
||
63 | View Code Duplication | ])->each(function ($job) : void { |
|
64 | $job->job_applications()->saveMany(factory(JobApplication::class, 5))->create([ |
||
65 | 'job_poster_id' => $job->id |
||
66 | ]); |
||
67 | //Then create one application with a priority user |
||
68 | $job->job_applications()->save(factory(JobApplication::class)->create([ |
||
69 | 'job_poster_id' => $job->id, |
||
70 | 'applicant_id' => factory(Applicant::class)->create([ |
||
71 | 'user_id' => factory(User::class)->states('priority')->create()->id |
||
72 | ])->id |
||
73 | ])); |
||
74 | }); |
||
75 | factory(JobPoster::class, 3)->states('closed')->create([ |
||
76 | 'manager_id' => $managerUser->manager->id |
||
77 | View Code Duplication | ])->each(function ($job) : void { |
|
78 | $job->job_applications()->saveMany(factory(JobApplication::class, 5))->create([ |
||
79 | 'job_poster_id' => $job->id |
||
80 | ]); |
||
81 | //Then create one application with a priority user |
||
82 | $job->job_applications()->save(factory(JobApplication::class)->create([ |
||
83 | 'job_poster_id' => $job->id, |
||
84 | 'applicant_id' => factory(Applicant::class)->create([ |
||
85 | 'user_id' => factory(User::class)->state('priority')->create()->id |
||
86 | ])->id |
||
87 | ])); |
||
88 | }); |
||
89 | factory(JobPoster::class, 3)->states('draft')->create([ |
||
90 | 'manager_id' => $managerUser->manager->id |
||
91 | ]); |
||
92 | factory(JobPoster::class, 3)->states('review_requested')->create([ |
||
93 | 'manager_id' => $managerUser->manager->id |
||
94 | ]); |
||
95 | |||
96 | // Create a Job Poster with an Assessment Plan |
||
97 | $jobWithAssessment = factory(JobPoster::class)->states('draft')->create([ |
||
98 | 'manager_id' => $managerUser->manager->id, |
||
99 | ]); |
||
100 | foreach ($jobWithAssessment->criteria as $criterion) { |
||
101 | // Create an assessment for each criterion |
||
102 | factory(Assessment::class)->states('withRatingGuide')->create([ |
||
103 | 'criterion_id' => $criterion->id, |
||
104 | ]); |
||
105 | }; |
||
106 | |||
107 | $applicantUser = User::where('email', $this->applicantEmail)->first(); |
||
108 | View Code Duplication | if ($applicantUser === null) { |
|
109 | $applicantUser = factory(User::class)->states('applicant')->create([ |
||
110 | 'email' => $this->applicantEmail |
||
111 | ]); |
||
112 | $applicantUser->applicant()->save(factory(Applicant::class)->create([ |
||
113 | 'user_id' => $applicantUser->id |
||
114 | ])); |
||
115 | } |
||
116 | |||
117 | // Add to application profile |
||
118 | $applicantUser->applicant->references()->saveMany(factory(Reference::class, 3)->create([ |
||
119 | 'applicant_id' => $applicantUser->applicant->id |
||
120 | ])); |
||
121 | |||
122 | // Create several applications for test user. |
||
123 | $applicantUser->applicant->job_applications()->saveMany(factory(JobApplication::class, 3)->create([ |
||
124 | 'applicant_id' => $applicantUser->applicant->id, |
||
125 | ])); |
||
126 | $applicantUser->applicant->job_applications()->saveMany(factory(JobApplication::class, 2)->states('draft')->create([ |
||
127 | 'applicant_id' => $applicantUser->applicant->id, |
||
128 | ])); |
||
131 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.