Event::raw()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * Incus
4
 * 
5
 * @copyright   Copyright (c) 2014 Warrick Bayman.
6
 * @author		Warrick Bayman <[email protected]>
7
 * @license     MIT License http://opensource.org/licenses/MIT
8
 * 
9
 */
10
11
namespace Incus;
12
13
14
use Carbon\Carbon;
15
use Incus\Contracts\EventInterface;
16
17
/**
18
 * Class Event
19
 *
20
 * @package Incus
21
 */
22
class Event implements EventInterface
23
{
24
    /**
25
     * @var string
26
     */
27
    private $raw;
28
    /**
29
     * @var mixed
30
     */
31
    private $decoded;
32
33
    /**
34
     * @param $mandrillEventJson
35
     */
36
    public function __construct($mandrillEventJson)
37
    {
38
        $this->raw = $mandrillEventJson;
39
        $this->decoded = json_decode($this->raw());
40
    }
41
42
    /**
43
     * RAW json encoded event object
44
     *
45
     * @return string
46
     */
47
    public function raw()
48
    {
49
        return $this->raw;
50
    }
51
52
53
    /**
54
     * Time of the event
55
     *
56
     * @return Carbon
57
     */
58
    public function at()
59
    {
60
        return Carbon::createFromTimestamp($this->decoded->ts);
61
    }
62
63
64
    /**
65
     * The event type
66
     *
67
     * @return mixed
68
     */
69
    public function type()
70
    {
71
        return $this->decoded->event;
72
    }
73
74
75
    /**
76
     * Has the event been indexed?
77
     *
78
     * @return bool
79
     */
80
    public function indexed()
81
    {
82
        if (property_exists($this->decoded, 'msg') && isset($this->decoded->msg)) {
83
            return true;
84
        }
85
        return false;
86
    }
87
88
89
    /**
90
     * Message
91
     *
92
     * @return Message|null
93
     */
94
    public function message()
95
    {
96
        if ($this->indexed()) {
97
            return new Message($this);
98
        }
99
        return null;
100
    }
101
}
102