Yandex::getTitle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\AuthClient\Client;
6
7
use Psr\Http\Message\RequestInterface;
8
use Yiisoft\Yii\AuthClient\OAuth2;
9
use Yiisoft\Yii\AuthClient\OAuthToken;
10
use Yiisoft\Yii\AuthClient\RequestUtil;
11
12
/**
13
 * Yandex allows authentication via Yandex OAuth.
14
 *
15
 * In order to use Yandex OAuth you must register your application at <https://oauth.yandex.ru/client/new>.
16
 *
17
 * @link https://oauth.yandex.ru/client/new
18
 * @link https://api.yandex.ru/login/doc/dg/reference/response.xml
19
 */
20
final class Yandex extends OAuth2
21
{
22
    protected string $authUrl = 'https://oauth.yandex.ru/authorize';
23
    protected string $tokenUrl = 'https://oauth.yandex.ru/token';
24
    protected string $endpoint = 'https://login.yandex.ru';
25
26
    public function applyAccessTokenToRequest(RequestInterface $request, OAuthToken $accessToken): RequestInterface
27
    {
28
        $params = RequestUtil::getParams($request);
29
30
        $paramsToAdd = [];
31
        if (!isset($params['format'])) {
32
            $paramsToAdd['format'] = 'json';
33
        }
34
        $paramsToAdd['oauth_token'] = $accessToken->getToken();
35
        return RequestUtil::addParams($request, $paramsToAdd);
36
    }
37
38
    /**
39
     * @return string service name.
40
     */
41
    public function getName(): string
42
    {
43
        return 'yandex';
44
    }
45
46
    /**
47
     * @return string service title.
48
     */
49
    public function getTitle(): string
50
    {
51
        return 'Yandex';
52
    }
53
54
    protected function initUserAttributes(): array
55
    {
56
        return $this->api('info');
57
    }
58
}
59