Passed
Push — dependabot/npm_and_yarn/dev/st... ( 790070...2dbd00 )
by
unknown
17:44 queued 12:22
created

ClaimJobApiController::unclaimJob()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace App\Http\Controllers\Api;
4
5
use App\Http\Controllers\Controller;
6
use App\Models\HrAdvisor;
7
use App\Models\JobPoster;
8
use Illuminate\Http\Request;
9
use Illuminate\Support\Facades\Gate;
10
11
class ClaimJobApiController extends Controller
12
{
13
    /**
14
     * Display a listing of the resource.
15
     *
16
     * @return \Illuminate\Http\Response
17
     */
18
    public function index()
19
    {
20
    }
21
22
    /**
23
     * Store a newly created resource in storage.
24
     *
25
     * @param  \Illuminate\Http\Request $request
26
     * @param  \App\Models\JobPoster  $jobPoster
27
     * @return \Illuminate\Http\Response
28
     */
29
    public function store(Request $request, JobPoster $job)
30
    {
31
        return $this->claimJob($request->user()->hr_advisor, $job);
32
    }
33
34
    /**
35
     * Display the specified resource.
36
     *
37
     * @param  \App\Models\HrAdvisor  $hrAdvisor
38
     * @return \Illuminate\Http\Response
39
     */
40
    public function show(HrAdvisor $hrAdvisor)
41
    {
42
    }
43
44
    /**
45
     * Update the specified resource in storage.
46
     *
47
     * @param  \Illuminate\Http\Request $request
48
     * @param  \App\Models\JobPoster  $jobPoster
49
     * @return \Illuminate\Http\Response
50
     */
51
    public function update(Request $request, JobPoster $job)
52
    {
53
    }
54
55
    /**
56
     * Remove the specified resource from storage.
57
     *
58
     * @param  \Illuminate\Http\Request $request
59
     * @param  \App\Models\JobPoster  $jobPoster
60
     * @return \Illuminate\Http\Response
61
     */
62
    public function destroy(Request $request, JobPoster $job)
63
    {
64
        return $this->unclaimJob($request->user()->hr_advisor, $job);
65
    }
66
67
    /**
68
     * Claim a Job Poster.
69
     *
70
     * @param  \App\Models\HrAdvisor  $hrAdvisor
71
     * @param  \App\Models\JobPoster  $job
72
     * @return \Illuminate\Http\Response
73
     */
74
    public function claimJob(HrAdvisor $hrAdvisor, JobPoster $job)
75
    {
76
        Gate::forUser($hrAdvisor->user)->authorize('claim', $job);
77
        $hrAdvisor->claimed_jobs()->attach($job);
78
        return response()->json(['status' => 'ok']);
0 ignored issues
show
Bug introduced by
The function response was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

78
        return /** @scrutinizer ignore-call */ response()->json(['status' => 'ok']);
Loading history...
79
    }
80
81
    /**
82
     * Unclaim a Job Poster.
83
     *
84
     * @param  \App\Models\HrAdvisor  $hrAdvisor
85
     * @param  \App\Models\JobPoster  $job
86
     * @return \Illuminate\Http\Response
87
     */
88
    public function unclaimJob(HrAdvisor $hrAdvisor, JobPoster $job)
89
    {
90
        Gate::forUser($hrAdvisor->user)->authorize('unClaim', $job);
91
        $hrAdvisor->claimed_jobs()->detach($job);
92
        return response()->json(['status' => 'ok']);
0 ignored issues
show
Bug introduced by
The function response was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

92
        return /** @scrutinizer ignore-call */ response()->json(['status' => 'ok']);
Loading history...
93
    }
94
}
95