Completed
Pull Request — master (#29)
by
unknown
02:39
created

FlipsideAPIUser::__construct()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 19
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 7
nc 6
nop 2
dl 0
loc 19
rs 8.8571
c 0
b 0
f 0
1
<?php
2
namespace Auth;
3
if(!class_exists('Httpful\Request'))
4
{
5
    require(realpath(dirname(__FILE__)).'/../libs/httpful/bootstrap.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
        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...
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