Passed
Branch master (776013)
by payever
03:51
created

AuthenticationRequest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

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

2 Methods

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