Completed
Push — master ( a85fa0...9473ea )
by Michał
03:56
created

Client::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php namespace nyx\auth\id\credentials;
2
3
// Internal dependencies
4
use nyx\auth;
5
6
/**
7
 * Client Credentials
8
 *
9
 * A special set of Credentials useful in, for example, an oAuth context where the client application's callback URI
10
 * can be treated equally important in the authentication process as its ID and secret.
11
 *
12
 * @package     Nyx\Auth
13
 * @version     0.1.0
14
 * @author      Michal Chojnacki <[email protected]>
15
 * @copyright   2012-2017 Nyx Dev Team
16
 * @link        https://github.com/unyx/nyx
17
 */
18
class Client extends auth\Credentials
19
{
20
    /**
21
     * @var string  The redirect (callback) URI associated with the application.
22
     */
23
    protected $redirectUri;
24
25
    /**
26
     * {@inheritDoc}
27
     *
28
     * @param   string  $redirectUri    The redirect (callback) URI associated with the application.
29
     */
30
    public function __construct(string $id, $secret, string $redirectUri)
31
    {
32
        parent::__construct($id, $secret);
33
34
        $this->redirectUri = $redirectUri;
35
    }
36
37
    /**
38
     * Returns the redirect (callback) URI associated with the application.
39
     *
40
     * @return  string
41
     */
42
    public function getRedirectUri() : string
43
    {
44
        return $this->redirectUri;
45
    }
46
47
    /**
48
     * {@inheritDoc}
49
     */
50
    public function matches(auth\interfaces\Token $that) : bool
51
    {
52
        if (!$that instanceof static) {
53
            return false;
54
        }
55
56
        if ($this->redirectUri !== $that->getRedirectUri()) {
57
            return false;
58
        }
59
60
        return parent::matches($that);
61
    }
62
63
    /**
64
     * {@inheritDoc}
65
     */
66 View Code Duplication
    public function unserialize($data)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
    {
68
        $data = unserialize($data);
69
70
        $this->id          = $data['id'];
71
        $this->secret      = $data['secret'];
72
        $this->redirectUri = $data['redirectUri'];
73
    }
74
75
    /**
76
     * {@inheritDoc}
77
     */
78
    public function toArray() : array
79
    {
80
        return [
81
            'id'          => $this->id,
82
            'secret'      => $this->secret,
83
            'redirectUri' => $this->redirectUri
84
        ];
85
    }
86
}
87