Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Passed
Push — columns-link-to ( bd8a41...d52cfc )
by Pedro
22:21 queued 11:43
created

Access::getAccessCondition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
cc 1
eloc 1
c 2
b 1
f 1
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Backpack\CRUD\app\Library\CrudPanel\Traits;
4
5
use Backpack\CRUD\app\Exceptions\AccessDeniedException;
6
7
trait Access
8
{
9
    /**
10
     * Set an operation as having access using the Settings API.
11
     *
12
     * @param  string|array  $operation
13
     * @return bool
14
     */
15
    public function allowAccess($operation)
16
    {
17
        foreach ((array) $operation as $op) {
18
            $this->set($op.'.access', true);
0 ignored issues
show
Bug introduced by
It seems like set() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

18
            $this->/** @scrutinizer ignore-call */ 
19
                   set($op.'.access', true);
Loading history...
19
        }
20
21
        return $this->hasAccessToAll($operation);
22
    }
23
24
    /**
25
     * Disable the access to a certain operation, or the current one.
26
     *
27
     * @param  string|array  $operation  [description]
28
     * @return [type] [description]
0 ignored issues
show
Documentation Bug introduced by
The doc comment [type] at position 0 could not be parsed: Unknown type name '[' at position 0 in [type].
Loading history...
29
     */
30
    public function denyAccess($operation)
31
    {
32
        foreach ((array) $operation as $op) {
33
            $this->set($op.'.access', false);
34
        }
35
36
        return ! $this->hasAccessToAny($operation);
37
    }
38
39
    /**
40
     * Check if a operation is allowed for a Crud Panel. Return false if not.
41
     *
42
     * @param  string  $operation
43
     * @return bool
44
     */
45
    public function hasAccess($operation)
46
    {
47
        return $this->get($operation.'.access') ?? false;
0 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
        return $this->/** @scrutinizer ignore-call */ get($operation.'.access') ?? false;
Loading history...
48
    }
49
50
    /**
51
     * Check if any operations are allowed for a Crud Panel. Return false if not.
52
     *
53
     * @param  string|array  $operation_array
54
     * @return bool
55
     */
56
    public function hasAccessToAny($operation_array)
57
    {
58
        foreach ((array) $operation_array as $key => $operation) {
59
            if ($this->get($operation.'.access') == true) {
60
                return true;
61
            }
62
        }
63
64
        return false;
65
    }
66
67
    /**
68
     * Check if all operations are allowed for a Crud Panel. Return false if not.
69
     *
70
     * @param  array  $operation_array  Permissions.
71
     * @return bool
72
     */
73
    public function hasAccessToAll($operation_array)
74
    {
75
        foreach ((array) $operation_array as $key => $operation) {
76
            if (! $this->get($operation.'.access')) {
77
                return false;
78
            }
79
        }
80
81
        return true;
82
    }
83
84
    /**
85
     * Check if a operation is allowed for a Crud Panel. Fail if not.
86
     *
87
     * @param  string  $operation
88
     * @return bool
89
     *
90
     * @throws \Backpack\CRUD\Exception\AccessDeniedException in case the operation is not enabled
91
     */
92
    public function hasAccessOrFail($operation)
93
    {
94
        if (! $this->get($operation.'.access')) {
95
            throw new AccessDeniedException(trans('backpack::crud.unauthorized_access', ['access' => $operation]));
96
        }
97
98
        return true;
99
    }
100
}
101