Completed
Push — master ( beec8b...68ede3 )
by Robbert
02:32
created

Event::__get()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 5
Bugs 1 Features 1
Metric Value
cc 3
eloc 8
c 5
b 1
f 1
nc 3
nop 1
dl 0
loc 11
ccs 5
cts 6
cp 0.8333
crap 3.0416
rs 9.4285
1
<?php
2
3
/*
4
 * This file is part of the Ariadne Component Library.
5
 *
6
 * (c) Muze <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace arc\events;
13
14
/**
15
 *	The event object that is passed to each listener. May contain extra information in the 'data' property.
16
 */
17
final class Event
18
{
19
    /**
20
     *	May contain extra information for the event listeners, may be any type.
21
     */
22
    public $data = null;
23
24
    /**
25
     *	The name of the event. Can be accessed through __get() but not changed.
26
     */
27
    private $name = '';
28
29
    /**
30
     *	If set to true will make fire() return false. Cannot be changed once set to true
31
     *	but can be read through __get().
32
     */
33
    private $preventDefault = false;
34
35
    /**
36
     *	@param string $name The name of the event fired.
37
     *	@param mixed $data Optional. Extra information for this event.
38
     */
39 6
    public function __construct($name, $data = null)
40
    {
41 6
        $this->name = $name;
42 6
        $this->data = $data;
43 6
    }
44
45
    /**
46
     *	Sets the flag which will make \arc\events::fire() return false. Once set it cannot be unset.
47
     *	@returns false
48
     */
49 1
    public function preventDefault()
50
    {
51 1
        $this->preventDefault = true;
52
53 1
        return false;
54
    }
55
56 6
    public function __get($name)
57
    {
58
        switch ($name) {
59 6
            case 'preventDefault':
60 6
                return $this->preventDefault;
61
                break;
62 6
            case 'name':
63 6
                return $this->name;
64
                break;
65
        }
66
    }
67
}
68