Event::getSource()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Caridea
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
7
 * use this file except in compliance with the License. You may obtain a copy of
8
 * the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
 * License for the specific language governing permissions and limitations under
16
 * the License.
17
 *
18
 * @copyright 2015-2018 LibreWorks contributors
19
 * @license   Apache-2.0
20
 */
21
namespace Caridea\Event;
22
23
/**
24
 * Abstract event that can be broadcast to listeners.
25
 *
26
 * @copyright 2015-2018 LibreWorks contributors
27
 * @license   Apache-2.0
28
 */
29
abstract class Event
30
{
31
    /**
32
     * @var object The source of the event
33
     */
34
    private $source;
35
    /**
36
     * @var float The microtime when the event kicked off
37
     */
38
    private $when;
39
    
40
    /**
41
     * Creates a new event
42
     *
43
     * @param object $source The source of the event. Cannot be null.
44
     */
45 3
    public function __construct($source)
46
    {
47 3
        if (!is_object($source)) {
48 1
            throw new \InvalidArgumentException("Event source must be an object");
49
        }
50 2
        $this->source = $source;
51 2
        $this->when = microtime(true);
52 2
    }
53
54
    /**
55
     * Gets the source of the event.
56
     *
57
     * @return object The source of the event
58
     */
59 1
    public function getSource()
60
    {
61 1
        return $this->source;
62
    }
63
64
    /**
65
     * Gets the time in microseconds when the event kicked off.
66
     *
67
     * @return float The time of the event
68
     */
69 1
    public function getWhen(): float
70
    {
71 1
        return $this->when;
72
    }
73
}
74