Passed
Push — develop ( cc9ef0...90d515 )
by Nikita
06:50
created

ServerPolicy::stop()   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
        return $exists && $user->can('game-server-common', $server);
35
    }
36
37
    /**
38
     * @param User $user
39
     * @param Server $server
40
     * @return bool
41
     */
42 1
    public function start(User $user, Server $server)
43
    {
44 1
        return $user->can(['game-server-common', 'game-server-start'], $server);
45
    }
46
47
    /**
48
     * @param User $user
49
     * @param Server $server
50
     * @return bool
51
     */
52 1
    public function stop(User $user, Server $server)
53
    {
54 1
        return $user->can(['game-server-common', 'game-server-stop'], $server);
55
    }
56
57
    /**
58
     * @param User $user
59
     * @param Server $server
60
     * @return bool
61
     */
62 1
    public function restart(User $user, Server $server)
63
    {
64 1
        return $user->can(['game-server-common', 'game-server-restart'], $server);
65
    }
66
67
    /**
68
     * @param User $user
69
     * @param Server $server
70
     * @return bool
71
     */
72
    public function pause(User $user, Server $server)
73
    {
74
        return $user->can(['game-server-common', 'game-server-pause'], $server);
75
    }
76
77
    /**
78
     * @param User $user
79
     * @param Server $server
80
     * @return bool
81
     */
82 1
    public function update(User $user, Server $server)
83
    {
84 1
        return $user->can(['game-server-common', 'game-server-update'], $server);
85
    }
86
87
    /**
88
     * @param User $user
89
     * @param Server $server
90
     * @return bool
91
     */
92 1
    public function consoleView(User $user, Server $server)
93
    {
94 1
        return $user->can(['game-server-common', 'game-server-console-view'], $server);
95
    }
96
97
    /**
98
     * @param User $user
99
     * @param Server $server
100
     * @return bool
101
     */
102
    public function consoleSend(User $user, Server $server)
103
    {
104
        return $user->can(['game-server-common', 'game-server-console-send'], $server);
105
    }
106
107
    /**
108
     * @param User $user
109
     * @param Server $server
110
     * @return bool
111
     */
112 7
    public function files(User $user, Server $server)
113
    {
114 7
        return $user->can(['game-server-common', 'game-server-files'], $server);
115
    }
116
117
    /**
118
     * @param User $user
119
     * @param Server $server
120
     * @return bool
121
     */
122 7
    public function settings(User $user, Server $server)
123
    {
124 7
        return $user->can(['game-server-common', 'game-server-settings'], $server);
125
    }
126
}
127