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

FlipsideAPIUser   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 62
Duplicated Lines 19.35 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 12
loc 62
rs 10
c 1
b 0
f 0
wmc 13
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
B isInGroupNamed() 0 21 5
A __get() 0 9 2
A __set() 0 3 1
B __construct() 12 19 5

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
if(!class_exists('Httpful\Request'))
4
{
5
    require(realpath(dirname(__FILE__)).'/../vendor/autoload.php');
6
}
7
8
class FlipsideAPIUser extends User
9
{
10
    private $userData;
11
    private $groupData = null;
12
    private $apiUrl = 'https://profiles.burningflipside.com/api/v1';
13
14
    public function __construct($data = false, $apiUrl = false)
15
    {
16 View Code Duplication
        if(($data !== false) && !isset($data['extended']))
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
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...
17
        {
18
            //Generic user object
19
            //TODO get from API
20
        }
21
        else
22
        {
23
            if(isset($data['extended']))
24
            {
25
                $this->userData = $data['extended'];
26
            }
27
        }
28
        if($apiUrl !== false)
29
        {
30
            $this->apiUrl = $apiUrl;
0 ignored issues
show
Documentation Bug introduced by
The property $apiUrl was declared of type string, but $apiUrl is of type boolean. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
31
        }
32
    }
33
34
    public function isInGroupNamed($name)
35
    {
36
        if($this->groupData === null)
37
        {
38
            $resp = \Httpful\Request::get($this->apiUrl.'/users/me/groups')->authenticateWith($this->userData->uid, $this->userData->userPassword)->send();
39
            if($resp->hasErrors())
40
            {
41
                return false;
42
            }
43
            $this->groupData = $resp->body;
44
        }
45
        $count = count($this->groupData);
46
        for($i = 0; $i < $count; $i++)
47
        {
48
            if($this->groupData[$i]->cn === $name)
49
            {
50
                return true;
51
            }
52
        }
53
        return false;
54
    }
55
56
    public function __get($propName)
57
    {
58
        if($this->userData === null)
59
        {
60
            return parent::__get($propName);
61
        }
62
        $propName = strtolower($propName);
63
        return $this->userData->{$propName};
64
    }
65
66
    public function __set($propName, $value)
67
    {
68
    }
69
}
70
71