Completed
Push — develop ( 120cb2...7bb86a )
by Wisoot
03:14
created

Claim::toArray()   B

Complexity

Conditions 6
Paths 32

Size

Total Lines 26
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 26
rs 8.439
cc 6
eloc 13
nc 32
nop 0
1
<?php
2
3
namespace WWON\JwtGuard;
4
5
class Claim
6
{
7
8
    /**
9
     * @var mixed
10
     */
11
    public $sub;
12
13
    /**
14
     * @var string
15
     */
16
    public $iss;
17
18
    /**
19
     * @var int
20
     */
21
    public $iat;
22
23
    /**
24
     * @var int
25
     */
26
    public $exp;
27
28
    /**
29
     * @var string
30
     */
31
    public $jti;
32
33
    /**
34
     * Claim constructor
35
     *
36
     * @param array $data
37
     */
38
    public function __construct(array $data = [])
39
    {
40
        foreach ($data as $key => $value) {
41
            $attribute = camel_case($key);
42
43
            if (property_exists($this, $attribute)) {
44
                $this->{$attribute} = $value;
45
            }
46
        }
47
    }
48
49
    /**
50
     * toArray method
51
     *
52
     * @return array
53
     */
54
    public function toArray()
55
    {
56
        $data = [];
57
58
        if (!empty($this->sub)) {
59
            $data['sub'] = $this->sub;
60
        }
61
62
        if (!empty($this->iss)) {
63
            $data['iss'] = $this->iss;
64
        }
65
66
        if (!empty($this->iat)) {
67
            $data['iat'] = $this->iat;
68
        }
69
70
        if (!empty($this->exp)) {
71
            $data['exp'] = $this->exp;
72
        }
73
74
        if (!empty($this->jti)) {
75
            $data['jti'] = $this->jti;
76
        }
77
78
        return $data;
79
    }
80
81
}