Completed
Push — develop ( f6f4f1...44c5cc )
by Abdelrahman
08:42
created

PagePolicy::createMedia()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Pages\Policies;
6
7
use Rinvex\Fort\Models\User;
8
use Rinvex\Pages\Models\Page;
9
use Illuminate\Auth\Access\HandlesAuthorization;
10
11
class PagePolicy
12
{
13
    use HandlesAuthorization;
14
15
    /**
16
     * Determine whether the user can list pages.
17
     *
18
     * @param string                   $ability
19
     * @param \Rinvex\Fort\Models\User $user
20
     *
21
     * @return bool
22
     */
23
    public function list($ability, User $user): bool
24
    {
25
        return $user->allAbilities->pluck('slug')->contains($ability);
26
    }
27
28
    /**
29
     * Determine whether the user can create pages.
30
     *
31
     * @param string                   $ability
32
     * @param \Rinvex\Fort\Models\User $user
33
     *
34
     * @return bool
35
     */
36
    public function create($ability, User $user): bool
37
    {
38
        return $user->allAbilities->pluck('slug')->contains($ability);
39
    }
40
41
    /**
42
     * Determine whether the user can update the page.
43
     *
44
     * @param string                    $ability
45
     * @param \Rinvex\Fort\Models\User  $user
46
     * @param \Rinvex\Pages\Models\Page $resource
47
     *
48
     * @return bool
49
     */
50
    public function update($ability, User $user, Page $resource): bool
0 ignored issues
show
Unused Code introduced by
The parameter $resource is not used and could be removed.

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

Loading history...
51
    {
52
        return $user->allAbilities->pluck('slug')->contains($ability);   // User can update pages
53
    }
54
55
    /**
56
     * Determine whether the user can delete the page.
57
     *
58
     * @param string                    $ability
59
     * @param \Rinvex\Fort\Models\User  $user
60
     * @param \Rinvex\Pages\Models\Page $resource
61
     *
62
     * @return bool
63
     */
64
    public function delete($ability, User $user, Page $resource): bool
0 ignored issues
show
Unused Code introduced by
The parameter $resource is not used and could be removed.

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

Loading history...
65
    {
66
        return $user->allAbilities->pluck('slug')->contains($ability);   // User can delete pages
67
    }
68
69
    /**
70
     * Determine whether the user can list page media.
71
     *
72
     * @param string                   $ability
73
     * @param \Rinvex\Fort\Models\User $user
74
     *
75
     * @return bool
76
     */
77
    public function listMedia($ability, User $user): bool
78
    {
79
        return $user->allAbilities->pluck('slug')->contains($ability);
80
    }
81
82
    /**
83
     * Determine whether the user can create page media.
84
     *
85
     * @param string                   $ability
86
     * @param \Rinvex\Fort\Models\User $user
87
     *
88
     * @return bool
89
     */
90
    public function createMedia($ability, User $user): bool
91
    {
92
        return $user->allAbilities->pluck('slug')->contains($ability);
93
    }
94
95
    /**
96
     * Determine whether the user can delete the page media.
97
     *
98
     * @param string                        $ability
99
     * @param \Rinvex\Fort\Models\User      $user
100
     * @param \Rinvex\Pages\Models\Page $resource
101
     *
102
     * @return bool
103
     */
104
    public function deleteMedia($ability, User $user, Page $resource): bool
0 ignored issues
show
Unused Code introduced by
The parameter $resource is not used and could be removed.

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

Loading history...
105
    {
106
        return $user->allAbilities->pluck('slug')->contains($ability);   // User can delete page media
107
    }
108
}
109