Completed
Push — master ( 1bbe3a...a1970e )
by Oleg
08:32
created

Acl   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 18.37 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 9
loc 49
wmc 3
lcom 0
cbo 2
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 18 3
rolePerms() 0 1 ?

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php /** MicroACL */
2
3
namespace Micro\Auth\Drivers;
4
5
use Micro\Auth\Adapter;
6
use Micro\Db\Drivers\IDriver;
7
use Micro\Db\IConnection;
8
9
/**
10
 * Abstract ACL class file.
11
 *
12
 * Base logic for a ACL security
13
 *
14
 * @author Oleg Lunegov <[email protected]>
15
 * @link https://github.com/linpax/microphp-framework
16
 * @copyright Copyright (c) 2013 Oleg Lunegov
17
 * @license https://github.com/linpax/microphp-framework/blob/master/LICENSE
18
 * @package Micro
19
 * @subpackage Auth\Drivers
20
 * @version 1.0
21
 * @since 1.0
22
 * @abstract
23
 */
24
abstract class Acl implements Adapter
25
{
26
    /** @var IDriver $db */
27
    protected $db;
28
    /** @var string $groupTable name of group table */
29
    protected $groupTable;
30
31
32
    /**
33
     * Base constructor for ACL, make acl_user table if exists
34
     *
35
     * @access public
36
     *
37
     * @param IConnection $db
38
     * @param array $params config array
39
     *
40
     * @result void
41
     */
42
    public function __construct(IConnection $db, array $params = [])
43
    {
44
        $this->db = $db->getDriver();
45
46
        if (!empty($params['groupTable'])) {
47
            $this->groupTable = $params['groupTable'];
48
        }
49
50 View Code Duplication
        if (!$this->db->tableExists('acl_user')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
            $this->db->createTable('acl_user', [
52
                '`id` int(10) unsigned NOT NULL AUTO_INCREMENT',
53
                '`user` int(11) unsigned NOT NULL',
54
                '`role` int(11) unsigned DEFAULT NULL',
55
                '`perm` int(11) unsigned DEFAULT NULL',
56
                'PRIMARY KEY (`id`)'
57
            ], 'ENGINE=MyISAM DEFAULT CHARSET=utf8');
58
        }
59
    }
60
61
    /**
62
     * Get permissions in role
63
     *
64
     * @access protected
65
     *
66
     * @param string $role role name
67
     *
68
     * @return array
69
     * @abstract
70
     */
71
    abstract protected function rolePerms($role);
72
}
73