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

Entry   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 1
dl 0
loc 80
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getId() 0 4 1
A getTime() 0 4 1
A getEvents() 0 4 1
A create() 0 14 4
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