Completed
Push — v3 ( d12fea )
by Beñat
05:39
created

AnemicAccessToken   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 91
wmc 15
lcom 0
cbo 0
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A fromProperties() 0 13 1
B fromJson() 0 9 5
A __construct() 0 11 1
A setAccessToken() 0 6 1
A getAccessToken() 0 4 1
A setAccountId() 0 6 1
A getAccountId() 0 4 1
A setExpiresOnDate() 0 6 1
A getExpiresOnDate() 0 4 1
A setScope() 0 6 1
A getScope() 0 4 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
use BenatEspina\StackExchangeApiClient\Domain\Model\AccessToken;
15
16
/**
17
 * The anemic implementation of access token domain class.
18
 *
19
 * @author Beñat Espiña <[email protected]>
20
 */
21
class AnemicAccessToken implements AccessToken
22
{
23
    private $accessToken;
24
    private $accountId;
25
    private $expiresOnDate;
26
    private $scope;
27
28
    public static function fromProperties(
29
        $accessToken,
30
        $accountId,
31
        \DateTimeInterface $expiresOnDate = null,
32
        array $scope = null
33
    ) {
34
        return new self(
35
            $accessToken,
36
            $accountId,
37
            $expiresOnDate,
38
            $scope
39
        );
40
    }
41
42
    public static function fromJson($data)
43
    {
44
        return new self(
45
            array_key_exists('access_token', $data) ? $data['access_token'] : null,
46
            array_key_exists('account_id', $data) ? $data['account_id'] : null,
47
            array_key_exists('expires_on_date', $data) ? new \DateTimeImmutable('@' . $data['expires_on_date']) : null,
48
            array_key_exists('scope', $data) ? $data['scope'] : null
49
        );
50
    }
51
52
    private function __construct(
53
        $accessToken,
54
        $accountId,
55
        \DateTimeInterface $expiresOnDate = null,
56
        array $scope = null
57
    ) {
58
        $this->accessToken = $accessToken;
59
        $this->accountId = $accountId;
60
        $this->expiresOnDate = $expiresOnDate;
61
        $this->scope = $scope;
62
    }
63
64
    public function setAccessToken($accessToken)
65
    {
66
        $this->accessToken = $accessToken;
67
68
        return $this;
69
    }
70
71
    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...
72
    {
73
        return $this->accessToken;
74
    }
75
76
    public function setAccountId($accountId)
77
    {
78
        $this->accountId = $accountId;
79
80
        return $this;
81
    }
82
83
    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...
84
    {
85
        return $this->accountId;
86
    }
87
88
    public function setExpiresOnDate(\DateTimeInterface $expiresOnDate)
89
    {
90
        $this->expiresOnDate = $expiresOnDate;
91
92
        return $this;
93
    }
94
95
    public function getExpiresOnDate()
96
    {
97
        return $this->expiresOnDate;
98
    }
99
100
    public function setScope(array $scope)
101
    {
102
        $this->scope = $scope;
103
104
        return $this;
105
    }
106
107
    public function getScope()
108
    {
109
        return $this->scope;
110
    }
111
}
112