Notification   A
last analyzed

Complexity

Total Complexity 21

Size/Duplication

Total Lines 139
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 21
lcom 1
cbo 1
dl 0
loc 139
rs 10
c 0
b 0
f 0

14 Methods

Rating   Name   Duplication   Size   Complexity  
A fromProperties() 0 19 1
B fromJson() 0 17 7
A setBody() 0 6 1
A getBody() 0 4 1
A setCreationDate() 0 6 1
A getCreationDate() 0 4 1
A setUnread() 0 6 1
A isUnread() 0 4 1
A setNotificationType() 0 8 2
A getNotificationType() 0 4 1
A setPostId() 0 6 1
A getPostId() 0 4 1
A setSite() 0 6 1
A getSite() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Stack Exchange Api Client library.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
/*
14
 * This file is part of the Stack Exchange Api Client library.
15
 *
16
 * (c) Beñat Espiña <[email protected]>
17
 *
18
 * For the full copyright and license information, please view the LICENSE
19
 * file that was distributed with this source code.
20
 */
21
22
namespace BenatEspina\StackExchangeApiClient\Model;
23
24
/**
25
 * The notification model class.
26
 *
27
 * @author Beñat Espiña <[email protected]>
28
 */
29
class Notification implements Model
30
{
31
    const NOTIFICATION_TYPES = [
32
        'accounts_associated',
33
        'badge_earned',
34
        'bounty_expired',
35
        'bounty_expires_in_one_day',
36
        'bounty_expires_in_three_days',
37
        'bounty_period_started',
38
        'edit_suggested',
39
        'generic',
40
        'moderator_message',
41
        'new_privileges',
42
        'post_migrated',
43
        'profile_activity',
44
        'registration_reminder',
45
        'reputation_bonus',
46
        'substantive_edit',
47
    ];
48
49
    protected $body;
50
    protected $creationDate;
51
    protected $isUnread;
52
    protected $notificationType;
53
    protected $postId;
54
    protected $site;
55
56
    public static function fromProperties(
57
        $body,
58
        $creationDate,
59
        $isUnread,
60
        $notificationType,
61
        $postId,
62
        Site $site
63
    ) {
64
        $instance = new self();
65
        $instance
66
            ->setBody($body)
67
            ->setCreationDate($creationDate)
68
            ->setUnread($isUnread)
69
            ->setNotificationType($notificationType)
70
            ->setPostId($postId)
71
            ->setSite($site);
72
73
        return $instance;
74
    }
75
76
    public static function fromJson(array $data)
77
    {
78
        $instance = new self();
79
        $instance
80
            ->setBody(array_key_exists('body', $data) ? $data['body'] : null)
81
            ->setCreationDate(
82
                array_key_exists('creation_date', $data)
83
                    ? new \DateTimeImmutable('@' . $data['creation_date'])
84
                    : null
85
            )
86
            ->setUnread(array_key_exists('is_unread', $data) ? $data['is_unread'] : null)
87
            ->setNotificationType(array_key_exists('notification_type', $data) ? $data['notification_type'] : null)
88
            ->setPostId(array_key_exists('post_id', $data) ? $data['post_id'] : null)
89
            ->setSite(array_key_exists('site', $data) ? Site::fromJson($data['site']) : null);
90
91
        return $instance;
92
    }
93
94
    public function setBody($body)
95
    {
96
        $this->body = $body;
97
98
        return $this;
99
    }
100
101
    public function getBody()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
102
    {
103
        return $this->body;
104
    }
105
106
    public function setCreationDate(\DateTimeInterface $creationDate = null)
107
    {
108
        $this->creationDate = $creationDate;
109
110
        return $this;
111
    }
112
113
    public function getCreationDate()
114
    {
115
        return $this->creationDate;
116
    }
117
118
    public function setUnread($isUnread)
119
    {
120
        $this->isUnread = $isUnread;
121
122
        return $this;
123
    }
124
125
    public function isUnread()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
126
    {
127
        return $this->isUnread;
128
    }
129
130
    public function setNotificationType($notificationType)
131
    {
132
        if (in_array($notificationType, self::NOTIFICATION_TYPES, true)) {
133
            $this->notificationType = $notificationType;
134
        }
135
136
        return $this;
137
    }
138
139
    public function getNotificationType()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
140
    {
141
        return $this->notificationType;
142
    }
143
144
    public function setPostId($postId)
145
    {
146
        $this->postId = $postId;
147
148
        return $this;
149
    }
150
151
    public function getPostId()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
152
    {
153
        return $this->postId;
154
    }
155
156
    public function setSite(Site $site = null)
157
    {
158
        $this->site = $site;
159
160
        return $this;
161
    }
162
163
    public function getSite()
164
    {
165
        return $this->site;
166
    }
167
}
168