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

Auth/class.FlipsideAPIUser.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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;
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