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