Completed
Push — v2 ( 12e20b...6101cd )
by Beñat
03:40
created

AccessToken::setAccessToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 2
Metric Value
c 3
b 0
f 2
dl 0
loc 6
rs 9.4286
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Stack Exchange Api Client library.
5
 *
6
 * Copyright (c) 2014-2016 Beñat Espiña <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace BenatEspina\StackExchangeApiClient\Model;
13
14
/**
15
 * The access token model class.
16
 *
17
 * @author Beñat Espiña <[email protected]>
18
 */
19
class AccessToken
20
{
21
    private $accessToken;
22
    private $accountId;
23
    private $expiresOnDate;
24
    private $scope;
25
26
    public static function fromProperties(
27
        $accessToken,
28
        $accountId,
29
        \DateTime $expiresOnDate = null,
30
        array $scope = null
31
    ) {
32
        return new self(
33
            $accessToken,
34
            $accountId,
35
            $expiresOnDate,
36
            $scope
37
        );
38
    }
39
40
    public static function fromJson(array $data)
41
    {
42
        return new self(
43
            array_key_exists('access_token', $data) ? $data['access_token'] : null,
44
            array_key_exists('account_id', $data) ? $data['account_id'] : null,
45
            array_key_exists('expires_on_date', $data) ? new \DateTime('@' . $data['expires_on_date']) : null,
46
            array_key_exists('scope', $data) ? $data['scope'] : null
47
        );
48
    }
49
50
    private function __construct(
51
        $accessToken,
52
        $accountId,
53
        \DateTime $expiresOnDate = null,
54
        array $scope = null
55
    ) {
56
        $this->accessToken = $accessToken;
57
        $this->accountId = $accountId;
58
        $this->expiresOnDate = $expiresOnDate;
59
        $this->scope = $scope;
60
    }
61
62
    public function setAccessToken($accessToken)
63
    {
64
        $this->accessToken = $accessToken;
65
66
        return $this;
67
    }
68
69
    public function getAccessToken()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
70
    {
71
        return $this->accessToken;
72
    }
73
74
    public function setAccountId($accountId)
75
    {
76
        $this->accountId = $accountId;
77
78
        return $this;
79
    }
80
81
    public function getAccountId()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
82
    {
83
        return $this->accountId;
84
    }
85
86
    public function setExpiresOnDate(\DateTime $expiresOnDate)
87
    {
88
        $this->expiresOnDate = $expiresOnDate;
89
90
        return $this;
91
    }
92
93
    public function getExpiresOnDate()
94
    {
95
        return $this->expiresOnDate;
96
    }
97
98
    public function setScope(array $scope)
99
    {
100
        $this->scope = $scope;
101
102
        return $this;
103
    }
104
105
    public function getScope()
106
    {
107
        return $this->scope;
108
    }
109
}
110