AuthorizationServer::addPasswordGrant()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Eole\Sandstone\OAuth2;
4
5
use League\OAuth2\Server\Storage;
6
use League\OAuth2\Server\AuthorizationServer as BaseAuthorizationServer;
7
8
class AuthorizationServer extends BaseAuthorizationServer
9
{
10
    /**
11
     * @var Grant\Password
12
     */
13
    private $passwordGrant;
14
15
    /**
16
     * @var Grant\RefreshToken
17
     */
18
    private $refreshTokenGrant;
19
20
    /**
21
     * @param Storage\SessionInterface $sessionStorage
22
     * @param Storage\AccessTokenInterface $accessTokenStorage
23
     * @param Storage\ClientInterface $clientStorage
24
     * @param Storage\ScopeInterface $scopeStorage
25
     * @param Storage\RefreshTokenInterface $refreshTokenStorage
26
     * @param Grant\Password $passwordGrant
27
     * @param Grant\RefreshToken $refreshTokenGrant
28
     */
29
    public function __construct(
30
        Storage\SessionInterface $sessionStorage,
31
        Storage\AccessTokenInterface $accessTokenStorage,
32
        Storage\ClientInterface $clientStorage,
33
        Storage\ScopeInterface $scopeStorage,
34
        Storage\RefreshTokenInterface $refreshTokenStorage,
35
        Grant\Password $passwordGrant,
36
        Grant\RefreshToken $refreshTokenGrant
37
    ) {
38
        parent::__construct();
0 ignored issues
show
Bug introduced by
The call to AuthorizationServer::__construct() misses some required arguments starting with $clientRepository.
Loading history...
39
40
        $this->sessionStorage = $sessionStorage;
0 ignored issues
show
Bug introduced by
The property sessionStorage does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
41
        $this->accessTokenStorage = $accessTokenStorage;
0 ignored issues
show
Bug introduced by
The property accessTokenStorage does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
42
        $this->clientStorage = $clientStorage;
0 ignored issues
show
Bug introduced by
The property clientStorage does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
43
        $this->scopeStorage = $scopeStorage;
0 ignored issues
show
Bug introduced by
The property scopeStorage does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
44
        $this->refreshTokenStorage = $refreshTokenStorage;
0 ignored issues
show
Bug introduced by
The property refreshTokenStorage does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
45
        $this->passwordGrant = $passwordGrant;
46
        $this->refreshTokenGrant = $refreshTokenGrant;
47
48
        $this->initServer();
49
        $this->addPasswordGrant();
50
        $this->addRefreshTokenGrant();
51
    }
52
53
    /**
54
     * Init authorization server.
55
     */
56
    private function initServer()
57
    {
58
        $this
0 ignored issues
show
Bug introduced by
The method setSessionStorage() does not seem to exist on object<Eole\Sandstone\OAuth2\AuthorizationServer>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
59
            ->setSessionStorage($this->sessionStorage)
60
            ->setAccessTokenStorage($this->accessTokenStorage)
61
            ->setClientStorage($this->clientStorage)
62
            ->setScopeStorage($this->scopeStorage)
63
        ;
64
    }
65
66
    /**
67
     * Allows authorization server to deliver an access token with username/password.
68
     */
69
    private function addPasswordGrant()
70
    {
71
        $this->addGrantType($this->passwordGrant);
0 ignored issues
show
Bug introduced by
The method addGrantType() does not seem to exist on object<Eole\Sandstone\OAuth2\AuthorizationServer>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
72
    }
73
74
    /**
75
     * Allows authorization server to deliver a fresh access token with an old one.
76
     */
77
    private function addRefreshTokenGrant()
78
    {
79
        $this
0 ignored issues
show
Bug introduced by
The method setRefreshTokenStorage() does not seem to exist on object<Eole\Sandstone\OAuth2\AuthorizationServer>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
80
            ->setRefreshTokenStorage($this->refreshTokenStorage)
81
            ->addGrantType($this->refreshTokenGrant)
82
        ;
83
    }
84
}
85