Completed
Push — develop ( 6b358f...19e70a )
by Patrick
08:59 queued 05:47
created

SQLUser   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 56
Duplicated Lines 14.29 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 8
loc 56
rs 10
wmc 10
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __set() 0 3 1
A isInGroupNamed() 0 17 4
A __get() 0 8 2
A __construct() 8 13 3

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
2
namespace Auth;
3
4
class SQLUser extends User
5
{
6
    private $data;
7
    private $auth;
8
9
    /**
10
     * Initialize a SQLUser object
11
     *
12
     * @param boolean|array $data The data to initialize the SQLUser with or false for an empty User
13
     * @param boolean|\Auth\SQLAuthenticator The SQLAuthenticator instance that produced this user
14
     */
15
    public function __construct($data = false, $auth = false)
16
    {
17
        $this->data = array();
18
        $this->auth = $auth;
19 View Code Duplication
        if($data !== false)
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...
20
        {
21
            $this->data = $data;
22
            if(isset($data['extended']))
23
            {
24
                $this->data = $data['extended'];
25
            }
26
        }
27
    }
28
29
    public function isInGroupNamed($name)
30
    {
31
        if($this->auth === false)
32
        {
33
            return false;
34
        }
35
        $auth_data_set = $this->auth->dataSet;
36
        $group_data_table = $auth_data_set['group'];
37
        $uid = $this->uid;
38
        $filter = new \Data\Filter("uid eq '$uid' and gid eq '$name'");
39
        $groups = $group_data_table->read($filter);
40
        if($groups === false || !isset($groups[0]))
41
        {
42
            return false;
43
        }
44
        return true;
45
    }
46
47
    public function __get($propName)
48
    {
49
        if(isset($this->data[$propName]))
50
        {
51
            return $this->data[$propName];
52
        }
53
        return false;
54
    }
55
56
    public function __set($propName, $value)
57
    {
58
    }
59
}
60
/* vim: set tabstop=4 shiftwidth=4 expandtab: */
61