Event   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 18
lcom 1
cbo 0
dl 0
loc 103
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
B fromJson() 0 12 6
A fromProperties() 0 17 1
A setId() 0 6 1
A getId() 0 4 1
A setCreationDate() 0 6 1
A getCreationDate() 0 4 1
A setEventType() 0 8 2
A getEventType() 0 4 1
A setExcerpt() 0 6 1
A getExcerpt() 0 4 1
A setLink() 0 6 1
A getLink() 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
 * Class event model class.
26
 *
27
 * @author Beñat Espiña <[email protected]>
28
 */
29
class Event implements Model
30
{
31
    const EVENT_TYPES = ['answer_posted', 'comment_posted', 'post_edited', 'question_posted', 'user_created'];
32
33
    protected $id;
34
    protected $creationDate;
35
    protected $eventType;
36
    protected $excerpt;
37
    protected $link;
38
39
    public static function fromJson(array $data)
40
    {
41
        $instance = new self();
42
        $instance
43
            ->setId(array_key_exists('event_id', $data) ? $data['event_id'] : null)
44
            ->setCreationDate(array_key_exists('creation_date', $data) ? $data['creation_date'] : null)
45
            ->setEventType(array_key_exists('event_type', $data) ? $data['event_type'] : null)
46
            ->setExcerpt(array_key_exists('excerpt', $data) ? $data['excerpt'] : null)
47
            ->setLink(array_key_exists('link', $data) ? $data['link'] : null);
48
49
        return $instance;
50
    }
51
52
    public static function fromProperties(
53
        $id,
54
        \DateTimeInterface $creationDate,
55
        $eventType,
56
        $excerpt = null,
57
        $link = null
58
    ) {
59
        $instance = new self();
60
        $instance
61
            ->setId($id)
62
            ->setCreationDate($creationDate)
63
            ->setEventType($eventType)
64
            ->setExcerpt($excerpt)
65
            ->setLink($link);
66
67
        return $instance;
68
    }
69
70
    public function setId($id)
71
    {
72
        $this->id = $id;
73
74
        return $this;
75
    }
76
77
    public function getId()
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...
78
    {
79
        return $this->id;
80
    }
81
82
    public function setCreationDate(\DateTimeInterface $creationDate = null)
83
    {
84
        $this->creationDate = $creationDate;
85
86
        return $this;
87
    }
88
89
    public function getCreationDate()
90
    {
91
        return $this->creationDate;
92
    }
93
94
    public function setEventType($eventType)
95
    {
96
        if (in_array($eventType, self::EVENT_TYPES, true)) {
97
            $this->eventType = $eventType;
98
        }
99
100
        return $this;
101
    }
102
103
    public function getEventType()
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...
104
    {
105
        return $this->eventType;
106
    }
107
108
    public function setExcerpt($excerpt)
109
    {
110
        $this->excerpt = $excerpt;
111
112
        return $this;
113
    }
114
115
    public function getExcerpt()
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...
116
    {
117
        return $this->excerpt;
118
    }
119
120
    public function setLink($link)
121
    {
122
        $this->link = $link;
123
124
        return $this;
125
    }
126
127
    public function getLink()
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...
128
    {
129
        return $this->link;
130
    }
131
}
132