Completed
Push — v2 ( e6c7b3...40717e )
by Beñat
06:35
created

Event::getExcerpt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 2
Metric Value
c 3
b 0
f 2
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Stack Exchange Api Client library.
5
 *
6
 * Copyright (c) 2014-2016 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
namespace BenatEspina\StackExchangeApiClient\Model;
13
14
/**
15
 * Class event model class.
16
 *
17
 * @author Beñat Espiña <[email protected]>
18
 */
19
class Event implements Model
20
{
21
    const EVENT_TYPES = ['answer_posted', 'comment_posted', 'post_edited', 'question_posted', 'user_created'];
22
23
    protected $id;
24
    protected $creationDate;
25
    protected $eventType;
26
    protected $excerpt;
27
    protected $link;
28
29
    public static function fromJson(array $data)
30
    {
31
        $instance = new self();
32
        $instance
33
            ->setId(array_key_exists('event_id', $data) ? $data['event_id'] : null)
34
            ->setCreationDate(array_key_exists('creation_date', $data) ? $data['creation_date'] : null)
35
            ->setEventType(array_key_exists('event_type', $data) ? $data['event_type'] : null)
36
            ->setExcerpt(array_key_exists('excerpt', $data) ? $data['excerpt'] : null)
37
            ->setLink(array_key_exists('link', $data) ? $data['link'] : null);
38
39
        return $instance;
40
    }
41
42
    public static function fromProperties(
43
        $id,
44
        \DateTimeInterface $creationDate,
45
        $eventType,
46
        $excerpt = null,
47
        $link = null
48
    ) {
49
        $instance = new self();
50
        $instance
51
            ->setId($id)
52
            ->setCreationDate($creationDate)
53
            ->setEventType($eventType)
54
            ->setExcerpt($excerpt)
55
            ->setLink($link);
56
57
        return $instance;
58
    }
59
60
    public function setId($id)
61
    {
62
        $this->id = $id;
63
64
        return $this;
65
    }
66
67
    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...
68
    {
69
        return $this->id;
70
    }
71
72
    public function setCreationDate(\DateTimeInterface $creationDate = null)
73
    {
74
        $this->creationDate = $creationDate;
75
76
        return $this;
77
    }
78
79
    public function getCreationDate()
80
    {
81
        return $this->creationDate;
82
    }
83
84
    public function setEventType($eventType)
85
    {
86
        if (in_array($eventType, self::EVENT_TYPES, true)) {
87
            $this->eventType = $eventType;
88
        }
89
90
        return $this;
91
    }
92
93
    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...
94
    {
95
        return $this->eventType;
96
    }
97
98
    public function setExcerpt($excerpt)
99
    {
100
        $this->excerpt = $excerpt;
101
102
        return $this;
103
    }
104
105
    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...
106
    {
107
        return $this->excerpt;
108
    }
109
110
    public function setLink($link)
111
    {
112
        $this->link = $link;
113
114
        return $this;
115
    }
116
117
    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...
118
    {
119
        return $this->link;
120
    }
121
}
122