Completed
Push — master ( 88b001...24ab37 )
by Derek Stephen
10:51
created

Client   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 124
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 21.74%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
lcom 1
cbo 1
dl 0
loc 124
ccs 5
cts 23
cp 0.2174
rs 10
c 2
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 4 1
A setClientIdentifier() 0 5 1
A getClientIdentifier() 0 4 1
A setClientSecret() 0 5 1
A getClientSecret() 0 4 1
A verifyClientSecret() 0 4 1
A setRedirectUri() 0 5 1
A getRedirectUri() 0 4 1
A toArray() 0 8 1
1
<?php
2
3
namespace OAuth;
4
5
use OAuth\Traits\EncryptableFieldEntity;
6
/**
7
 * Client
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=100)
32
     */
33
    private $clientSecret;
34
35
    /**
36
     * @var string
37
     * @Column(type="string")
38
     */
39
    private $redirectUri = '';
40
41
    /**
42
     * Get id
43
     *
44
     * @return integer
45
     */
46
    public function getId()
47
    {
48
        return $this->id;
49
    }
50
51
    /**
52
     * Set client_identifier
53
     *
54
     * @param string $clientIdentifier
55
     * @return Client
56
     */
57
    public function setClientIdentifier($clientIdentifier)
58
    {
59
        $this->clientIdentifier = $clientIdentifier;
60
        return $this;
61
    }
62
63
    /**
64
     * Get client_identifier
65
     *
66
     * @return string
67
     */
68
    public function getClientIdentifier()
69
    {
70
        return $this->clientIdentifier;
71
    }
72
73
    /**
74
     * Set client_secret
75
     *
76
     * @param string $clientSecret
77
     * @return Client
78
     */
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
    /**
86
     * Get client_secret
87
     *
88
     * @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 Client
109
     */
110 1
    public function setRedirectUri($redirectUri)
111
    {
112 1
        $this->redirectUri = $redirectUri;
113 1
        return $this;
114
    }
115
116
    /**
117
     * Get redirect_uri
118
     *
119
     * @return string
120
     */
121 1
    public function getRedirectUri()
122
    {
123 1
        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
}