Completed
Pull Request — master (#3)
by Romain
01:47
created

Entry::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace Kerox\Messenger\Model\Callback;
3
4
use Kerox\Messenger\Callback\CallbackEventFactory;
5
6
class Entry
7
{
8
9
    /**
10
     * @var string
11
     */
12
    protected $id;
13
14
    /**
15
     * @var int
16
     */
17
    protected $time;
18
19
    /**
20
     * @var array
21
     */
22
    protected $events;
23
24
    /**
25
     * Entry constructor.
26
     *
27
     * @param string $id
28
     * @param int $time
29
     * @param array $events
30
     */
31
    public function __construct(string $id, int $time, array $events)
32
    {
33
        $this->id = $id;
34
        $this->time = $time;
35
        $this->events = $events;
36
    }
37
38
    /**
39
     * @return string
40
     */
41
    public function getId(): string
42
    {
43
        return $this->id;
44
    }
45
46
    /**
47
     * @return int
48
     */
49
    public function getTime(): int
50
    {
51
        return $this->time;
52
    }
53
54
    /**
55
     * @return array
56
     */
57
    public function getEvents(): array
58
    {
59
        return $this->events;
60
    }
61
62
    /**
63
     * @param array $entry
64
     * @return static
65
     */
66
    public static function create(array $entry)
67
    {
68
        $events = [];
69
        foreach ($entry['messaging'] as $event) {
70
            $events[] = CallbackEventFactory::create($event);
71
        }
72
73
        return new static($entry['id'], $entry['time'], $events);
74
    }
75
}
76