Passed
Push — feature/screening-plan ( e45b1a...83bc54 )
by Tristan
05:22
created

ScreeningPlanController::store()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 22
ccs 0
cts 13
cp 0
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 12
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use App\Models\JobPoster;
7
use Illuminate\Support\Facades\Lang;
8
use Illuminate\View\View;
9
use App\Models\Skill;
10
use App\Models\Lookup\SkillLevel;
11
use App\Models\Lookup\AssessmentType;
12
use App\Models\ScreeningPlan;
13
use App\Models\Assessment;
14
15
class ScreeningPlanController extends Controller
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class ScreeningPlanController
Loading history...
16
{
17
18
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $jobPoster should have a doc-comment as per coding-style.
Loading history...
19
     * Show the form for creating a new resource.
20
     *
21
     * @param  JobPoster $job The job to create a screen plan for.
0 ignored issues
show
Coding Style introduced by
Doc comment for parameter $job does not match actual variable name $jobPoster
Loading history...
22
     * @return View
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
23
     */
24
    public function createForJob(JobPoster $jobPoster): View
25
    {
26
        $jobPoster->load('criteria');
27
        $skills = Skill::all();
0 ignored issues
show
Unused Code introduced by
The assignment to $skills is dead and can be removed.
Loading history...
28
        debugbar()->debug($jobPoster->toArray());
29
        return view(
30
            'manager/screening-plan',
31
            [
32
                'screening' => Lang::get('manager/screening-plan'),
33
                'job' => $jobPoster,
34
                'skill_template' => Lang::get('common/skills'),
35
                'assessment_types' => AssessmentType::all(),
36
            ]
37
        );
38
    }
39
40
    public function store(Request $request, JobPoster $jobPoster)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function store()
Loading history...
41
    {
42
        //TODO: Validate every job criteria is represented
43
        //TODO: Validate every job criteria has at least one assessment (?)
44
        //TODO: Validate every assessment is correct and complete
45
46
        $plan = new ScreeningPlan();
47
        $plan->job_poster_id = $jobPoster->id;
48
        $plan->version = ScreeningPlan::max('version') + 1;
49
        $plan->save();
50
51
        foreach ($request->input('criteria') as $criteriaId => $assessments) {
52
            foreach ($assessments['assessment'] as $assessmentData) {
53
                $assessment = new Assessment();
54
                $assessment->screening_plan_id = $plan->id;
55
                $assessment->criterion_id = $criteriaId;
56
                $assessment->assessment_type_id = $assessmentData['assessment_type'];
57
                $assessment->save();
58
            }
59
        }
60
61
        return redirect(route('manager.jobs.screening_plan', $jobPoster));
0 ignored issues
show
Bug introduced by
$jobPoster of type App\Models\JobPoster is incompatible with the type array expected by parameter $parameters of route(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

61
        return redirect(route('manager.jobs.screening_plan', /** @scrutinizer ignore-type */ $jobPoster));
Loading history...
62
    }
63
}
64