Completed
Push — master ( b739db...92d607 )
by Abdelrahman
02:42
created

UserPolicy::view()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
/*
4
 * NOTICE OF LICENSE
5
 *
6
 * Part of the Rinvex Fort Package.
7
 *
8
 * This source file is subject to The MIT License (MIT)
9
 * that is bundled with this package in the LICENSE file.
10
 *
11
 * Package: Rinvex Fort Package
12
 * License: The MIT License (MIT)
13
 * Link:    https://rinvex.com
14
 */
15
16
namespace Rinvex\Fort\Policies;
17
18
use Rinvex\Fort\Models\User;
19
use Illuminate\Auth\Access\HandlesAuthorization;
20
21
class UserPolicy
22
{
23
    use HandlesAuthorization;
24
25
    /**
26
     * Determine whether the user can view the user.
27
     *
28
     * @param \Rinvex\Fort\Models\User $user
29
     * @param \Rinvex\Fort\Models\User $model
30
     *
31
     * @return bool
32
     */
33
    public function view(User $user, User $model)
0 ignored issues
show
Unused Code introduced by
The parameter $user 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...
Unused Code introduced by
The parameter $model 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...
34
    {
35
        return true;
36
    }
37
38
    /**
39
     * Determine whether the user can create users.
40
     *
41
     * @param \Rinvex\Fort\Models\User $user
42
     *
43
     * @return bool
44
     */
45
    public function create(User $user)
0 ignored issues
show
Unused Code introduced by
The parameter $user 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...
46
    {
47
        return true;
48
    }
49
50
    /**
51
     * Determine whether the user can update the user.
52
     *
53
     * @param \Rinvex\Fort\Models\User $user
54
     * @param \Rinvex\Fort\Models\User $model
55
     *
56
     * @return bool
57
     */
58
    public function update(User $user, User $model)
59
    {
60
        // Super admins & protected users can be controlled by super admins only!
61
        return $model->isProtected() || ($model->isSuperadmin() && ! $user->isSuperadmin()) ? false : true;
62
    }
63
64
    /**
65
     * Determine whether the user can delete the user.
66
     *
67
     * @param \Rinvex\Fort\Models\User $user
68
     * @param \Rinvex\Fort\Models\User $model
69
     *
70
     * @return bool
71
     */
72
    public function delete(User $user, User $model)
73
    {
74
        // Super admins & protected users can be controlled by super admins only! Users can NOT delete themeselves!
75
        return $model->isProtected() || ($model->isSuperadmin() && ! $user->isSuperadmin()) || $model->id === $user->id ? false : true;
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<Rinvex\Fort\Models\User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 135 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
76
    }
77
78
    /**
79
     * Determine whether the user can import the users.
80
     *
81
     * @param \Rinvex\Fort\Models\User $user
82
     *
83
     * @return bool
84
     */
85
    public function import(User $user)
0 ignored issues
show
Unused Code introduced by
The parameter $user 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...
86
    {
87
        return true;
88
    }
89
90
    /**
91
     * Determine whether the user can export the users.
92
     *
93
     * @param \Rinvex\Fort\Models\User $user
94
     *
95
     * @return bool
96
     */
97
    public function export(User $user)
0 ignored issues
show
Unused Code introduced by
The parameter $user 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...
98
    {
99
        return true;
100
    }
101
102
    /**
103
     * Determine whether the user can activate the user.
104
     *
105
     * @param \Rinvex\Fort\Models\User    $user
106
     * @param \Rinvex\Fort\Models\Ability $model
0 ignored issues
show
Documentation introduced by
Should the type for parameter $model not be User?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
107
     *
108
     * @return bool
109
     */
110
    public function activate(User $user, User $model)
111
    {
112
        // Super admins & protected users can be activated by super
113
        // admins only! Users can NOT activate their own accounts!
114
        return $model->isProtected() || ($model->isSuperadmin() && ! $user->isSuperadmin()) || $model->id === $user->id ? false : true;
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<Rinvex\Fort\Models\User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 135 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
115
    }
116
117
    /**
118
     * Determine whether the user can deactivate the user.
119
     *
120
     * @param \Rinvex\Fort\Models\User    $user
121
     * @param \Rinvex\Fort\Models\Ability $model
0 ignored issues
show
Documentation introduced by
Should the type for parameter $model not be User?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
122
     *
123
     * @return bool
124
     */
125
    public function deactivate(User $user, User $model)
126
    {
127
        // Super admins & protected users can be de-activated by super
128
        // admins only! Users can NOT de-activate their own accounts!
129
        return $model->isProtected() || ($model->isSuperadmin() && ! $user->isSuperadmin()) || $model->id === $user->id ? false : true;
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<Rinvex\Fort\Models\User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 135 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
130
    }
131
}
132