GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Authenticator   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 1
dl 0
loc 74
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A login() 0 7 1
A getUser() 0 7 2
A runCallback() 0 6 3
A updateUser() 0 5 1
A getExistingUser() 0 5 1
A storeProviderIdentity() 0 8 2
A updateProviderIdentity() 0 6 1
A addProviderIdentity() 0 9 1
1
<?php namespace AdamWathan\EloquentOAuth;
2
3
class Authenticator
4
{
5
    protected $auth;
6
    protected $users;
7
    protected $identities;
8
9
    public function __construct($auth, $users, $identities)
10
    {
11
        $this->auth = $auth;
12
        $this->users = $users;
13
        $this->identities = $identities;
14
    }
15
16
    public function login($providerAlias, $userDetails, $callback = null, $remember = false)
17
    {
18
        $user = $this->getUser($providerAlias, $userDetails);
19
        $user = $this->runCallback($callback, $user, $userDetails);
20
        $this->updateUser($user, $providerAlias, $userDetails);
21
        $this->auth->login($user, $remember);
22
    }
23
24
    protected function getUser($providerAlias, $details)
25
    {
26
        if ($this->identities->userExists($providerAlias, $details)) {
27
            return $this->getExistingUser($providerAlias, $details);
28
        }
29
        return $this->users->create();
30
    }
31
32
    protected function runCallback($callback, $user, $userDetails)
33
    {
34
        $callback = $callback ?: function () {};
35
        $callbackUser = $callback($user, $userDetails);
36
        return $callbackUser ?: $user;
37
    }
38
39
    protected function updateUser($user, $providerAlias, $details)
40
    {
41
        $this->users->store($user);
42
        $this->storeProviderIdentity($user, $providerAlias, $details);
43
    }
44
45
    protected function getExistingUser($providerAlias, $details)
46
    {
47
        $identity = $this->identities->getByProvider($providerAlias, $details);
48
        return $this->users->findByIdentity($identity);
49
    }
50
51
    protected function storeProviderIdentity($user, $providerAlias, $details)
52
    {
53
        if ($this->identities->userExists($providerAlias, $details)) {
54
            $this->updateProviderIdentity($providerAlias, $details);
55
        } else {
56
            $this->addProviderIdentity($user, $providerAlias, $details);
57
        }
58
    }
59
60
    protected function updateProviderIdentity($providerAlias, $details)
61
    {
62
        $identity = $this->identities->getByProvider($providerAlias, $details);
63
        $identity->access_token = $details->access_token;
64
        $this->identities->store($identity);
65
    }
66
67
    protected function addProviderIdentity($user, $providerAlias, $details)
68
    {
69
        $identity = new OAuthIdentity;
70
        $identity->user_id = $user->getKey();
0 ignored issues
show
Documentation introduced by
The property user_id does not exist on object<AdamWathan\EloquentOAuth\OAuthIdentity>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
71
        $identity->provider = $providerAlias;
0 ignored issues
show
Documentation introduced by
The property provider does not exist on object<AdamWathan\EloquentOAuth\OAuthIdentity>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
72
        $identity->provider_user_id = $details->id;
0 ignored issues
show
Documentation introduced by
The property provider_user_id does not exist on object<AdamWathan\EloquentOAuth\OAuthIdentity>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
73
        $identity->access_token = $details->access_token;
0 ignored issues
show
Documentation introduced by
The property access_token does not exist on object<AdamWathan\EloquentOAuth\OAuthIdentity>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
74
        $this->identities->store($identity);
75
    }
76
}
77