Passed
Branch master (a0cc06)
by Dāvis
17:06
created

Draugiem::getClientSecret()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Sludio\HelperBundle\Oauth\Client\Provider\Draugiem;
4
5
use League\OAuth2\Client\Provider\AbstractProvider;
6
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
7
use League\OAuth2\Client\Token\AccessToken;
8
use Psr\Http\Message\ResponseInterface;
9
10
class Draugiem extends AbstractProvider
11
{
12
    /**
13
     * Draugiem.lv API URL
14
     */
15
    const API_URL = 'http://api.draugiem.lv/json/';
16
17
    /**
18
     * Draugiem.lv passport login URL
19
     */
20
    const LOGIN_URL = 'https://api.draugiem.lv/authorize/';
21
22
    /**
23
     * Timeout in seconds for session_check requests
24
     */
25
    const SESSION_CHECK_TIMEOUT = 180;
26
27
    /**
28
     * @param array $options
29
     * @param array $collaborators
30
     *
31
     * @throws \InvalidArgumentException
32
     */
33
    public function __construct($options = [], array $collaborators = [])
34
    {
35
        parent::__construct($options, $collaborators);
36
    }
37
38
    public function getBaseAuthorizationUrl()
39
    {
40
        return static::LOGIN_URL;
41
    }
42
43
    public function getBaseAccessTokenUrl(array $params = [])
44
    {
45
        return static::API_URL;
46
    }
47
48
    public function getDefaultScopes()
49
    {
50
        return [];
51
    }
52
53
    protected function createResourceOwner(array $response, AccessToken $token = null)
54
    {
55
        return new DraugiemUser($response);
56
    }
57
58
    protected function checkResponse(ResponseInterface $response, $data)
59
    {
60 View Code Duplication
        if (!empty($data['error'])) {
0 ignored issues
show
Duplication introduced by
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...
61
            $message = $data['error']['description'];
0 ignored issues
show
Unused Code introduced by
The assignment to $message is dead and can be removed.
Loading history...
62
            throw new IdentityProviderException('error_draugiem_bad_response', $data['error']['code'], $response);
0 ignored issues
show
Bug introduced by
$response of type Psr\Http\Message\ResponseInterface is incompatible with the type string|array expected by parameter $response of League\OAuth2\Client\Pro...xception::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

62
            throw new IdentityProviderException('error_draugiem_bad_response', $data['error']['code'], /** @scrutinizer ignore-type */ $response);
Loading history...
63
        }
64
    }
65
66
    public function getClientSecret()
67
    {
68
        return $this->clientSecret;
69
    }
70
71
    public function getClientId()
72
    {
73
        return $this->clientId;
74
    }
75
76
    public function getRedirectUri()
77
    {
78
        return $this->redirectUri;
79
    }
80
81
    public function getResourceOwnerDetailsUrl(AccessToken $token)
82
    {
83
    }
84
}
85