Completed
Push — master ( 9628d6...a206dc )
by Derek Stephen
09:38
created

Client::setName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 2
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace OAuth;
4
5
use OAuth\Traits\EncryptableFieldEntity;
6
/**
7
 * OAuthClient
8
 * @entity(repositoryClass="OAuth\Repository\ClientRepository")
9
 * @Table(name="Client",uniqueConstraints={@UniqueConstraint(name="identifier_idx", columns={"clientIdentifier"})})
10
 */
11
class Client
12
{
13
    use EncryptableFieldEntity;
14
15
    /**
16
     * @var integer
17
     * @Id
18
     * @Column(type="integer", length=11)
19
     * @GeneratedValue
20
     */
21
    private $id;
22
23
    /**
24
     * @var string
25
     * @Column(type="string",length=50)
26
     */
27
    private $clientIdentifier;
28
29
    /**
30
     * @var string
31
     * @Column(type="string",length=20)
32
     */
33
    private $clientSecret;
34
35
    /**
36 1
     * @var string
37
     * @Column(type="string")
38 1
     */
39
    private $redirectUri = '';
40
41
    /**
42
     * Get id
43
     *
44 1
     * @return integer
45
     */
46 1
    public function getId()
47 1
    {
48
        return $this->id;
49
    }
50
51
    /**
52
     * Set client_identifier
53
     *
54 3
     * @param string $clientIdentifier
55
     * @return OAuthClient
56 3
     */
57
    public function setClientIdentifier($clientIdentifier)
58
    {
59
        $this->clientIdentifier = $clientIdentifier;
60
        return $this;
61
    }
62
63
    /**
64
     * Get client_identifier
65
     *
66 1
     * @return string
67
     */
68 1
    public function getClientIdentifier()
69
    {
70
        return $this->clientIdentifier;
71
    }
72
73
    /**
74
     * Set client_secret
75 3
     *
76
     * @param string $clientSecret
77 3
     * @return OAuthClient
78 3
     */
79
    public function setClientSecret($clientSecret)
80
    {
81
        $this->clientSecret = $this->encryptField($clientSecret);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->encryptField($clientSecret) can also be of type boolean. However, the property $clientSecret is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
82
        return $this;
83
    }
84
85 1
    /**
86
     * Get client_secret
87 1
     *
88 1
     * @return string
89
     */
90
    public function getClientSecret()
91
    {
92
        return $this->clientSecret;
93
    }
94
95
    /**
96
     * @param $clientSecret
97
     * @return bool
98
     */
99
    public function verifyClientSecret($clientSecret)
100
    {
101
        return $this->verifyEncryptedFieldValue($this->getClientSecret(), $clientSecret);
102
    }
103
104
    /**
105
     * Set redirect_uri
106
     *
107
     * @param string $redirectUri
108
     * @return OAuthClient
109
     */
110
    public function setRedirectUri($redirectUri)
111
    {
112
        $this->redirectUri = $redirectUri;
113
        return $this;
114
    }
115
116
    /**
117
     * Get redirect_uri
118
     *
119
     * @return string
120
     */
121
    public function getRedirectUri()
122
    {
123
        return $this->redirectUri;
124
    }
125
126
    public function toArray()
127
    {
128
        return [
129
            'client_id' => $this->clientIdentifier,
130
            'client_secret' => $this->clientSecret,
131
            'redirect_uri' => $this->redirectUri,
132
        ];
133
    }
134
}