AuthenticationRequest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 17
c 1
b 0
f 0
dl 0
loc 44
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 5 3
A getRequired() 0 14 2
1
<?php
2
3
/**
4
 * PHP version 5.4 and 8
5
 *
6
 * @category  RequestEntity
7
 * @package   Payever\Core
8
 * @author    payever GmbH <[email protected]>
9
 * @copyright 2017-2021 payever GmbH
10
 * @license   MIT <https://opensource.org/licenses/MIT>
11
 * @link      https://docs.payever.org/shopsystems/api/getting-started
12
 */
13
14
namespace Payever\ExternalIntegration\Core\Http\RequestEntity;
15
16
use Payever\ExternalIntegration\Core\Authorization\OauthToken;
17
use Payever\ExternalIntegration\Core\Http\RequestEntity;
18
19
/**
20
 * This class represents Authentication RequestInterface Entity
21
 *
22
 * @method string getScope()
23
 * @method string getClientId()
24
 * @method string getClientSecret()
25
 * @method string getGrantType()
26
 * @method string getRefreshToken()
27
 * @method self   setScope(string $scope)
28
 * @method self   setClientId(string $id)
29
 * @method self   setClientSecret(string $secret)
30
 * @method self   setGrantType(string $type)
31
 * @method self   setRefreshToken(string $scope)
32
 *
33
 * @SuppressWarnings(PHPMD.StaticAccess)
34
 */
35
class AuthenticationRequest extends RequestEntity
36
{
37
    /** @var string $scope */
38
    protected $scope = OauthToken::SCOPE_PAYMENT_ACTIONS;
39
40
    /** @var string $clientId */
41
    protected $clientId;
42
43
    /** @var string $clientSecret */
44
    protected $clientSecret;
45
46
    /** @var string $grantType */
47
    protected $grantType = OauthToken::GRAND_TYPE_OBTAIN_TOKEN;
48
49
    /** @var string $refreshToken */
50
    protected $refreshToken;
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function getRequired()
56
    {
57
        $required = [
58
            'scope',
59
            'client_id',
60
            'client_secret',
61
            'grant_type',
62
        ];
63
64
        if ($this->grantType == OauthToken::GRAND_TYPE_REFRESH_TOKEN) {
65
            $required[] = 'refresh_token';
66
        }
67
68
        return $required;
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function isValid()
75
    {
76
        return parent::isValid() &&
77
            in_array($this->scope, OauthToken::getScopes()) &&
78
            in_array($this->grantType, OauthToken::getGrandTypes())
79
        ;
80
    }
81
}
82