AclAuthComponent   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 36
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B allow() 0 18 5
1
<?php
2
namespace App\Controller\Component;
3
4
use Cake\Controller\Component\AuthComponent;
5
use Cake\Utility\Inflector;
6
7
class AclAuthComponent extends AuthComponent
8
{
9
10
    /**
11
     * Takes a list of actions in the current controller for which authentication is not required, or
12
     * no parameters to allow all actions.
13
     *
14
     * You can use allow with either an array or a simple string.
15
     *
16
     * `$this->Auth->allow('view');`
17
     * `$this->Auth->allow(['edit', 'add']);`
18
     * `$this->Auth->allow();` to allow all actions
19
     *
20
     * @param string|array $actions Controller action name or array of actions.
21
     *
22
     * @return void
23
     */
24
    public function allow($actions = null)
25
    {
26
        if ($actions === null) {
27
            $controller = $this->_registry->getController();
28
            $this->allowedActions = get_class_methods($controller);
29
30
            return;
31
        }
32
33
        $controller = Inflector::camelize($this->request['controller']);
34
        $action = Inflector::underscore($this->request['action']);
35
        if (!$this->session->read('Auth.User') ||
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->session->read('Auth.User') of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
Deprecated Code introduced by
The property Cake\Controller\Component\AuthComponent::$session has been deprecated with message: 3.1.0 Will be removed in 4.0

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
36
            (isset($this->config('allowedActionsForBanned')[$controller]) &&
0 ignored issues
show
Deprecated Code introduced by
The method Cake\Core\InstanceConfigTrait::config() has been deprecated with message: 3.4.0 use setConfig()/getConfig() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
37
            in_array($action, array_map('strtolower', $this->config('allowedActionsForBanned')[$controller])))
0 ignored issues
show
Deprecated Code introduced by
The method Cake\Core\InstanceConfigTrait::config() has been deprecated with message: 3.4.0 use setConfig()/getConfig() instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
38
        ) {
39
            $this->allowedActions = array_merge($this->allowedActions, (array)$actions);
40
        }
41
    }
42
}
43