Client::__construct()   B
last analyzed

Complexity

Conditions 6
Paths 32

Size

Total Lines 26
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 4
Bugs 0 Features 1
Metric Value
c 4
b 0
f 1
dl 0
loc 26
ccs 0
cts 19
cp 0
rs 8.439
cc 6
eloc 13
nc 32
nop 6
crap 42
1
<?php
2
/**
3
 * @author Stefano Torresi (http://stefanotorresi.it)
4
 * @license See the file LICENSE.txt for copying permission.
5
 * ************************************************
6
 */
7
8
namespace Thorr\OAuth2\Entity;
9
10
use Thorr\Persistence\Entity\AbstractEntity;
11
12
class Client extends AbstractEntity implements ScopesProviderInterface
13
{
14
    use RedirectUriProviderTrait;
15
    use ScopesProviderTrait;
16
17
    /**
18
     * @var string
19
     */
20
    protected $secret;
21
22
    /**
23
     * @var UserInterface
24
     */
25
    protected $user;
26
27
    /**
28
     * @var array
29
     */
30
    protected $grantTypes = [];
31
32
    /**
33
     * @var string
34
     */
35
    protected $description;
36
37
    /**
38
     * {@inheritdoc}
39
     *
40
     * @param string        $secret
41
     * @param UserInterface $user
42
     * @param string[]      $grantTypes
43
     * @param string        $redirectUri
44
     * @param string        $description
45
     */
46
    public function __construct($uuid = null, $secret = null, $user = null, $grantTypes = null, $redirectUri = null, $description = null)
47
    {
48
        parent::__construct($uuid);
49
50
        if ($secret) {
51
            $this->setSecret($secret);
52
        }
53
54
        if ($user) {
55
            $this->setUser($user);
56
        }
57
58
        if ($grantTypes) {
59
            $this->setGrantTypes($grantTypes);
60
        }
61
62
        if ($redirectUri) {
63
            $this->setRedirectUri($redirectUri);
64
        }
65
66
        if ($description) {
67
            $this->setDescription($description);
68
        }
69
70
        $this->initScopes();
71
    }
72
73
    /**
74
     * @return string
75
     */
76
    public function getSecret()
77
    {
78
        return $this->secret;
79
    }
80
81
    /**
82
     * @param string $secret
83
     */
84
    public function setSecret($secret)
85
    {
86
        $this->secret = (string) $secret;
87
    }
88
89
    /**
90
     * @return bool
91
     */
92
    public function isPublic()
93
    {
94
        return empty($this->secret);
95
    }
96
97
    /**
98
     * @return UserInterface
99
     */
100
    public function getUser()
101
    {
102
        return $this->user;
103
    }
104
105
    /**
106
     * @param UserInterface $user
107
     */
108
    public function setUser(UserInterface $user = null)
109
    {
110
        $this->user = $user;
111
    }
112
113
    /**
114
     * @return array
115
     */
116
    public function getGrantTypes()
117
    {
118
        return $this->grantTypes;
119
    }
120
121
    /**
122
     * @param string[] $grantTypes
123
     */
124
    public function setGrantTypes(array $grantTypes)
125
    {
126
        $this->grantTypes = $grantTypes;
127
    }
128
129
    /**
130
     * @return string
131
     */
132
    public function getDescription()
133
    {
134
        return $this->description;
135
    }
136
137
    /**
138
     * @param string $description
139
     */
140
    public function setDescription($description)
141
    {
142
        $this->description = (string) $description;
143
    }
144
}
145