DefaultAcl::__construct()   B
last analyzed

Complexity

Conditions 7
Paths 16

Size

Total Lines 66

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 66
rs 7.8084
c 0
b 0
f 0
cc 7
nc 16
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * DefaultAcl
5
 * @copyright Copyright (c) 2011 - 2015 Aleksandr Torosh (http://wezoom.com.ua)
6
 * @author Aleksandr Torosh <[email protected]>
7
 */
8
9
namespace Application\Acl;
10
11
class DefaultAcl extends \Phalcon\Acl\Adapter\Memory
12
{
13
14
    public function __construct()
15
    {
16
        parent::__construct();
17
18
        $this->setDefaultAction(\Phalcon\Acl::DENY);
19
20
        /**
21
         * Full list of Roles
22
         */
23
        $roles = [];
24
        $roles['guest'] = new \Phalcon\Acl\Role('guest', 'Guest');
25
        $roles['member'] = new \Phalcon\Acl\Role('member', 'Member');
26
27
        $roles['journalist'] = new \Phalcon\Acl\Role('journalist', 'Journalist');
28
        $roles['editor'] = new \Phalcon\Acl\Role('editor', 'Journalist');
29
        $roles['admin'] = new \Phalcon\Acl\Role('admin', 'Admin');
30
31
        /**
32
         * Frontend roles
33
         */
34
        $this->addRole($roles['guest']);
35
        $this->addRole($roles['member'], $roles['guest']);
36
37
        /**
38
         * Backend roles
39
         */
40
        $this->addRole($roles['journalist'], $roles['guest']);
41
        $this->addRole($roles['editor'], $roles['journalist']);
42
        $this->addRole($roles['admin']);
43
44
        /**
45
         * Include resources permissions list from file /app/config/acl.php
46
         */
47
        $resources = include APPLICATION_PATH . '/config/acl.php';
48
49
        foreach ($resources as $roles_resources) {
50
            foreach ($roles_resources as $resource => $actions) {
51
                $registerActions = '*';
52
                if (is_array($actions)) {
53
                    $registerActions = $actions;
54
                }
55
                $this->addResource(new \Phalcon\Acl\Resource($resource), $registerActions);
56
            }
57
        }
58
59
        /**
60
         * Make unlimited access for admin role
61
         */
62
        $this->allow('admin', '*', '*');
63
64
        /**
65
         * Set roles permissions
66
         */
67
        foreach ($roles as $k => $role) {
68
            $user_resource = $resources[$k];
69
            foreach ($user_resource as $roles_resources => $method) {
70
                if ($method == '*') {
71
                    $this->allow($k, $roles_resources, '*');
72
                } else {
73
                    $this->allow($k, $roles_resources, $method);
74
                }
75
76
            }
77
        }
78
79
    }
80
81
}