Completed
Push — v2 ( e6c7b3...40717e )
by Beñat
06:35
created

AccessToken::getExpiresOnDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 2
Metric Value
c 3
b 0
f 2
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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 implements Model
20
{
21
    protected $accessToken;
22
    protected $accountId;
23
    protected $expiresOnDate;
24
    protected $scope;
25
26
    public static function fromProperties(
27
        $accessToken,
28
        $accountId,
29
        \DateTimeInterface $expiresOnDate = null,
30
        array $scope = null
31
    ) {
32
        $instance = new self();
33
        $instance
34
            ->setAccessToken($accessToken)
35
            ->setAccountId($accountId)
36
            ->setExpiresOnDate($expiresOnDate)
37
            ->setScope($scope);
38
39
        return $instance;
40
    }
41
42
    public static function fromJson(array $data)
43
    {
44
        $instance = new self();
45
        $instance
46
            ->setAccessToken(array_key_exists('access_token', $data) ? $data['access_token'] : null)
47
            ->setAccountId(array_key_exists('account_id', $data) ? $data['account_id'] : null)
48
            ->setExpiresOnDate(
49
                array_key_exists('expires_on_date', $data)
50
                    ? new \DateTimeImmutable('@' . $data['expires_on_date'])
51
                    : null
52
            )
53
            ->setScope(array_key_exists('scope', $data) ? $data['scope'] : null);
54
55
        return $instance;
56
    }
57
58
    public function setAccessToken($accessToken)
59
    {
60
        $this->accessToken = $accessToken;
61
62
        return $this;
63
    }
64
65
    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...
66
    {
67
        return $this->accessToken;
68
    }
69
70
    public function setAccountId($accountId)
71
    {
72
        $this->accountId = $accountId;
73
74
        return $this;
75
    }
76
77
    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...
78
    {
79
        return $this->accountId;
80
    }
81
82
    public function setExpiresOnDate(\DateTimeInterface $expiresOnDate = null)
83
    {
84
        $this->expiresOnDate = $expiresOnDate;
85
86
        return $this;
87
    }
88
89
    public function getExpiresOnDate()
90
    {
91
        return $this->expiresOnDate;
92
    }
93
94
    public function setScope(array $scope = null)
95
    {
96
        $this->scope = $scope;
97
98
        return $this;
99
    }
100
101
    public function getScope()
102
    {
103
        return $this->scope;
104
    }
105
}
106