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

Ability::isSuperadmin()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 0
dl 0
loc 4
rs 10
c 0
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\Models;
17
18
use Illuminate\Database\Eloquent\Model;
19
use Illuminate\Database\Eloquent\SoftDeletes;
20
21
class Ability extends Model
22
{
23
    use SoftDeletes;
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    protected $dates = ['deleted_at'];
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    protected $fillable = [
34
        'action',
35
        'policy',
36
        'title',
37
        'description',
38
    ];
39
40
    /**
41
     * Create a new Eloquent model instance.
42
     *
43
     * @param array $attributes
44
     *
45
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
46
     */
47
    public function __construct(array $attributes = [])
48
    {
49
        parent::__construct($attributes);
50
51
        $this->setTable(config('rinvex.fort.tables.abilities'));
52
    }
53
54
    /**
55
     * An ability can be applied to roles.
56
     *
57
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
58
     */
59
    public function roles()
60
    {
61
        return $this->belongsToMany(config('rinvex.fort.models.role'), config('rinvex.fort.tables.ability_role'))
62
                    ->withTimestamps();
63
    }
64
65
    /**
66
     * An ability can be applied to users.
67
     *
68
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
69
     */
70
    public function users()
71
    {
72
        return $this->belongsToMany(config('rinvex.fort.models.user'), config('rinvex.fort.tables.ability_user'))
73
                    ->withTimestamps();
74
    }
75
76
    /**
77
     * Determine if the ability is super admin.
78
     *
79
     * @return bool
80
     */
81
    public function isSuperadmin()
82
    {
83
        return ! $this->policy && $this->action === 'superadmin';
0 ignored issues
show
Documentation introduced by
The property policy does not exist on object<Rinvex\Fort\Models\Ability>. 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...
Documentation introduced by
The property action does not exist on object<Rinvex\Fort\Models\Ability>. 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...
84
    }
85
86
    /**
87
     * Determine if the ability is protected.
88
     *
89
     * @return bool
90
     */
91
    public function isProtected()
92
    {
93
        return in_array($this->id, config('rinvex.fort.protected.abilities'));
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<Rinvex\Fort\Models\Ability>. 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...
94
    }
95
}
96