| Conditions | 7 |
| Paths | 11 |
| Total Lines | 55 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 20 | public function index() |
||
| 21 | { |
||
| 22 | |||
| 23 | $stream_names = TalentStream::all(); |
||
| 24 | $stream_specialties = TalentStreamCategory::all(); |
||
| 25 | $job_skill_levels = JobSkillLevel::orderBy('id', 'asc')->get(); |
||
| 26 | |||
| 27 | $strategic_response_id = config('app.strategic_response_department_id'); |
||
|
|
|||
| 28 | $strategic_response_jobs = JobPoster::where('department_id', $strategic_response_id) |
||
| 29 | ->where('job_poster_status_id', JobPosterStatus::where('key', 'live')->first()->id) |
||
| 30 | ->get(); |
||
| 31 | |||
| 32 | $streams = []; |
||
| 33 | // Iterate through all talent streams. |
||
| 34 | foreach ($stream_names as $stream) { |
||
| 35 | $stream_jobs = $strategic_response_jobs->where('talent_stream_id', $stream->id); |
||
| 36 | $specialties = []; |
||
| 37 | $specialties_count = 0; |
||
| 38 | foreach ($stream_specialties as $specialty) { |
||
| 39 | $stream_specialty_jobs = $stream_jobs->where('talent_stream_category_id', $specialty->id); |
||
| 40 | if ($stream_specialty_jobs->isNotEmpty()) { |
||
| 41 | $levels = []; |
||
| 42 | foreach ($job_skill_levels as $level) { |
||
| 43 | $job = $stream_specialty_jobs->firstWhere('job_skill_level_id', $level->id); |
||
| 44 | if ($job) { |
||
| 45 | $levels[$level->name] = ['title' => $level->name, 'job_id' => $job->id]; |
||
| 46 | $specialties_count += 1; |
||
| 47 | } else { |
||
| 48 | $levels[$level->name] = ['title' => $level->name, 'job_id' => null]; |
||
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 52 | // Push specialty title and associated levels to specialty array. |
||
| 53 | $specialties[$specialty->name] = [ |
||
| 54 | 'title' => $specialty->name, |
||
| 55 | 'levels' => $levels, |
||
| 56 | ]; |
||
| 57 | } |
||
| 58 | } |
||
| 59 | if (!empty($specialties)) { |
||
| 60 | ksort($specialties); |
||
| 61 | |||
| 62 | // Push stream title and specialties to streams array. |
||
| 63 | $streams[$stream->name] = [ |
||
| 64 | 'title' => $stream->name, |
||
| 65 | 'specialties' => $specialties, |
||
| 66 | 'count' => $specialties_count, |
||
| 67 | ]; |
||
| 68 | } |
||
| 69 | } |
||
| 70 | ksort($streams); |
||
| 71 | |||
| 72 | return view('response/index/index', [ |
||
| 73 | 'response' => Lang::get('response/index'), |
||
| 74 | 'streams' => $streams, |
||
| 75 | ]); |
||
| 89 |