Test Failed
Pull Request — master (#74)
by
unknown
08:19
created

Entry::getEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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