Passed
Pull Request — 1.11.x (#5763)
by Angel Fernando Quiroz
13:24
created

AzureCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/* For license terms, see /license.txt */
4
5
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
6
use League\OAuth2\Client\Token\AccessTokenInterface;
7
use TheNetworg\OAuth2\Client\Provider\Azure;
8
9
class AzureCommand
10
{
11
    /**
12
     * @var AzureActiveDirectory
13
     */
14
    protected $plugin;
15
    /**
16
     * @var Azure
17
     */
18
    protected $provider;
19
    /**
20
     * @var AccessTokenInterface
21
     */
22
    private $token;
0 ignored issues
show
introduced by
The private property $token is not used, and could be removed.
Loading history...
23
24
    public function __construct()
25
    {
26
        $this->plugin = AzureActiveDirectory::create();
27
        $this->plugin->get_settings(true);
28
        $this->provider = $this->plugin->getProviderForApiGraph();
29
    }
30
31
    /**
32
     * @throws IdentityProviderException
33
     */
34
    protected function getToken(?AccessTokenInterface $currentToken = null): AccessTokenInterface
35
    {
36
        if (!$currentToken || ($currentToken->getExpires() && !$currentToken->getRefreshToken())) {
37
            return $this->provider->getAccessToken(
38
                'client_credentials',
39
                ['resource' => $this->provider->resource]
40
            );
41
        }
42
43
        return $currentToken;
44
    }
45
}
46