Passed
Push — develop ( 2a02d4...7461cb )
by Nikita
05:45
created

ServerPolicy::control()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
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
    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
        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
20
    /**
21
     * Determine whether the user can view the server.
22
     *
23
     * @param  \Gameap\Models\User  $user
24
     * @param  \Gameap\Models\Server  $server
25
     * @return mixed
26
     */
27
    public function control(?User $user, Server $server)
28
    {
29
        $count = $user->servers()
30
            ->where('id', $server->id)
31
            ->count();
32
33
        return $count > 0;
34
    }
35
}
36