Passed
Push — develop ( 9523f4...6fbaf9 )
by Nikita
07:23
created

ServerPolicy::restart()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Gameap\Policies;
4
5
use Gameap\Models\User;
6
use Gameap\Models\Server;
7
use Illuminate\Auth\Access\HandlesAuthorization;
8
9
class ServerPolicy
10
{
11
    use HandlesAuthorization;
12
13 27
    public function before(?User $user, $ability)
0 ignored issues
show
Unused Code introduced by
The parameter $ability 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

13
    public function before(?User $user, /** @scrutinizer ignore-unused */ $ability)

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...
14
    {
15 27
        if ($user->can('admin roles & permissions')) {
0 ignored issues
show
Bug introduced by
The method can() does not exist on null. ( Ignorable by Annotation )

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

15
        if ($user->/** @scrutinizer ignore-call */ can('admin roles & permissions')) {

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...
16
            return true;
17
        }
18
19 27
        return null;
20
    }
21
22
    /**
23
     * Determine whether the user can view the server.
24
     *
25
     * @param User $user
26
     * @param Server $server
27
     * @return mixed
28
     */
29 21
    public function control(?User $user, Server $server)
30
    {
31 21
        $exists = $user->servers()
32 21
            ->where('id', $server->id)
33 21
            ->exists();
34 21
        $can = $user->can('game-server-common', $server);
0 ignored issues
show
Unused Code introduced by
The assignment to $can is dead and can be removed.
Loading history...
35 21
        return $exists && $user->can('game-server-common', $server);
36
    }
37
38
    /**
39
     * @param User $user
40
     * @param Server $server
41
     * @return bool
42
     */
43 1
    public function start(User $user, Server $server)
44
    {
45 1
        return $user->can('game-server-start', $server);
46
    }
47
48
    /**
49
     * @param User $user
50
     * @param Server $server
51
     * @return bool
52
     */
53 1
    public function stop(User $user, Server $server)
54
    {
55 1
        return $user->can('game-server-stop', $server);
56
    }
57
58
    /**
59
     * @param User $user
60
     * @param Server $server
61
     * @return bool
62
     */
63 1
    public function restart(User $user, Server $server)
64
    {
65 1
        return $user->can('game-server-restart', $server);
66
    }
67
68
    /**
69
     * @param User $user
70
     * @param Server $server
71
     * @return bool
72
     */
73
    public function pause(User $user, Server $server)
74
    {
75
        return $user->can('game-server-pause', $server);
76
    }
77
78
    /**
79
     * @param User $user
80
     * @param Server $server
81
     * @return bool
82
     */
83
    public function update(User $user, Server $server)
84
    {
85
        return $user->can('game-server-update', $server);
86
    }
87
88
    /**
89
     * @param User $user
90
     * @param Server $server
91
     * @return bool
92
     */
93
    public function consoleView(User $user, Server $server)
94
    {
95
        return $user->can('game-server-console-view', $server);
96
    }
97
98
    /**
99
     * @param User $user
100
     * @param Server $server
101
     * @return bool
102
     */
103
    public function consoleSend(User $user, Server $server)
104
    {
105
        return $user->can('game-server-console-send', $server);
106
    }
107
108
    /**
109
     * @param User $user
110
     * @param Server $server
111
     * @return bool
112
     */
113 7
    public function files(User $user, Server $server)
114
    {
115 7
        return $user->can('game-server-files', $server);
116
    }
117
118
    /**
119
     * @param User $user
120
     * @param Server $server
121
     * @return bool
122
     */
123 7
    public function settings(User $user, Server $server)
124
    {
125 7
        return $user->can('game-server-settings', $server);
126
    }
127
}
128