CandidatePolicy::delete()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 7
rs 10
1
<?php
2
3
namespace App\Policies;
4
5
use App\Models\Candidate;
6
use App\Models\User;
7
use Illuminate\Auth\Access\HandlesAuthorization;
8
9
class CandidatePolicy
10
{
11
    use HandlesAuthorization;
12
13
    public function view(User $user, Candidate $candidate)
14
    {
15
        if ($user->can('read all recruitments')) {
16
            return true;
17
        }
18
19
        if ($user->grantedRecruitments->contains($candidate->recruitment->id)) {
20
            return true;
21
        }
22
23
        return false;
24
    }
25
26
    public function delete(User $user, Candidate $candidate)
0 ignored issues
show
Unused Code introduced by
The parameter $candidate is not used and could be removed. ( Ignorable by Annotation )

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

26
    public function delete(User $user, /** @scrutinizer ignore-unused */ Candidate $candidate)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
27
    {
28
        if ($user->can('update any recruitment')) {
29
            return true;
30
        }
31
32
        return false;
33
    }
34
35
    public function create(User $user)
36
    {
37
        if ($user->can('create candidates')) {
38
            return true;
39
        }
40
41
        return false;
42
    }
43
44
    public function update(User $user, Candidate $candidate)
45
    {
46
        if ($user->can('update any recruitment')) {
47
            return true;
48
        }
49
50
        if ($user->grantedRecruitments->contains($candidate->recruitment->id)) {
51
            return true;
52
        }
53
54
        return false;
55
    }
56
57
    public function changeStage(User $user)
58
    {
59
        if ($user->can('update any recruitment')) {
60
            return true;
61
        }
62
63
        $candidate = Candidate::findOrFail(request()->get('candidate_id'));
0 ignored issues
show
Bug introduced by
The method get() does not exist on Illuminate\Http\Request. ( Ignorable by Annotation )

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

63
        $candidate = Candidate::findOrFail(request()->/** @scrutinizer ignore-call */ get('candidate_id'));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
64
        if ($user->grantedRecruitments->contains($candidate->recruitment->id)) {
0 ignored issues
show
Bug introduced by
The property id does not seem to exist on Illuminate\Database\Eloquent\Relations\Relation.
Loading history...
65
            return true;
66
        }
67
68
        return false;
69
    }
70
}
71