Entry::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

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