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

FlipsideAPIUser::__set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
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