Event::toArray()   A
last analyzed

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
2
/**
3
 * This file is part of the fnayou/instapush-php project.
4
 *
5
 * Copyright (c) 2017. Aymen FNAYOU <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Fnayou\InstapushPHP\Model;
12
13
/**
14
 * Model Event.
15
 */
16
class Event implements FromArrayInterface
17
{
18
    /** @var string */
19
    private $title;
20
21
    /** @var string */
22
    private $message;
23
24
    /** @var array */
25
    private $trackers;
26
27
    /**
28
     * @param string $title
29
     * @param string $message
30
     * @param array  $trackers
31
     */
32
    public function __construct(string $title, string $message, array $trackers)
33
    {
34
        $this
35
            ->setTitle($title)
36
            ->setMessage($message)
37
            ->setTrackers($trackers);
38
    }
39
40
    /**
41
     * @return string
42
     */
43
    public function getTitle()
44
    {
45
        return $this->title;
46
    }
47
48
    /**
49
     * @param string $title
50
     *
51
     * @return $this
52
     */
53
    public function setTitle(string $title)
54
    {
55
        $this->title = $title;
56
57
        return $this;
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    public function getMessage()
64
    {
65
        return $this->message;
66
    }
67
68
    /**
69
     * @param string $message
70
     *
71
     * @return $this
72
     */
73
    public function setMessage(string $message)
74
    {
75
        $this->message = $message;
76
77
        return $this;
78
    }
79
80
    /**
81
     * @return array
82
     */
83
    public function getTrackers()
84
    {
85
        return $this->trackers;
86
    }
87
88
    /**
89
     * @param array $trackers
90
     *
91
     * @return $this
92
     */
93
    public function setTrackers(array $trackers)
94
    {
95
        $this->trackers = $trackers;
96
97
        return $this;
98
    }
99
100
    /**
101
     * {@inheritdoc}
102
     */
103
    public static function fromArray(array $data)
104
    {
105
        return new static($data['title'], $data['message'], $data['trackers']);
106
    }
107
108
    /**
109
     * @return array
110
     */
111
    public function toArray()
112
    {
113
        return [
114
            'title' => $this->getTitle(),
115
            'message' => $this->getMessage(),
116
            'trackers' => $this->getTrackers(),
117
        ];
118
    }
119
}
120