Passed
Push — feature/screening-plan ( d3f64c...59054f )
by Tristan
08:31 queued 02:39
created

ScreeningPlanController::destroy()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 11
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 6
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
        if ($request->input('criteria')) {
52
            foreach ($request->input('criteria') as $criteriaId => $assessments) {
53
                foreach ($assessments['assessment'] as $assessmentData) {
54
                    $assessment = new Assessment();
55
                    $assessment->screening_plan_id = $plan->id;
56
                    $assessment->criterion_id = $criteriaId;
57
                    $assessment->assessment_type_id = $assessmentData['assessment_type'];
58
                    $assessment->save();
59
                }
60
            }
61
        }
62
63
        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

63
        return redirect(route('manager.jobs.screening_plan', /** @scrutinizer ignore-type */ $jobPoster));
Loading history...
64
    }
65
66
    /**
67
     * Delete the particular skill declaration in storage.
68
     *
69
     * @param \Illuminate\Http\Request  $request       The request object.
0 ignored issues
show
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
70
     * @param \App\Models\ScreeningPlan $screeningPlan The screening plan to delete.
0 ignored issues
show
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
71
     * @return \Illuminate\Http\Response
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
72
     */
73
    public function destroy(Request $request, ScreeningPlan $screeningPlan): \Illuminate\Http\Response
74
    {
75
        $this->authorize('delete', $screeningPlan);
76
        $skillDeclaration->delete();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $skillDeclaration seems to be never defined.
Loading history...
77
78
        if ($request->ajax()) {
79
            $content = ['message' => 'Screening Plan deleted'];
80
            return $this->formatAjaxResponse($content);
81
        }
82
83
        return redirect()->back();
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->back() returns the type Illuminate\Http\RedirectResponse which is incompatible with the type-hinted return Illuminate\Http\Response.
Loading history...
84
    }
85
}
86