Completed
Push — master ( 707115...75abcf )
by Mahmoud
03:15
created

UserPolicy::delete()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 2
eloc 2
nc 2
nop 2
1
<?php
2
3
namespace App\Containers\User\UI\API\Policies;
4
5
use App\Port\Policy\Abstracts\Policy;
6
use Illuminate\Auth\Access\HandlesAuthorization;
7
use App\Containers\User\Models\User;
8
9
/**
10
 * Class UserPolicy.
11
 *
12
 * @author Mahmoud Zalt <[email protected]>
13
 */
14
class UserPolicy extends Policy
15
{
16
    use HandlesAuthorization;
17
18
    /**
19
     * Determine if the user is updating himself and not another user.
20
     *
21
     * @param \App\Containers\User\Models\User $user
22
     * @param                                $inputUserId
23
     *
24
     * @return bool
25
     */
26
    public function update(User $user, $inputUserId)
27
    {
28
        // authorize only if a user is updating it's own records
29
        return ($user->id == $inputUserId) ? true : false;
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<App\Containers\User\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...
30
    }
31
32
    /**
33
     * Determine if the user is deleting himself and not another user.
34
     *
35
     * @param \App\Containers\User\Models\User $user
36
     * @param                                $inputUserId
37
     *
38
     * @return bool
39
     */
40
    public function delete(User $user, $inputUserId)
41
    {
42
        // authorize only if a user is deleting it's own records
43
        return ($user->id == $inputUserId) ? true : false;
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<App\Containers\User\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...
44
    }
45
}
46