DOMEvent   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 105
rs 10
c 0
b 0
f 0
wmc 5
lcom 2
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 3
A preventDefault() 0 4 1
A stopPropagation() 0 4 1
1
<?php
2
namespace PhpQuery\Dom;
3
4
/**
5
 * DOMEvent class.
6
 *
7
 * Based on
8
 * @link    http://developer.mozilla.org/En/DOM:event
9
 * @author  Tobiasz Cudnik <tobiasz.cudnik/gmail.com>
10
 * @package PhpQuery
11
 * @todo    implement ArrayAccess ?
12
 */
13
class DOMEvent
14
{
15
    /**
16
     * Returns a boolean indicating whether the event bubbles up through the DOM or not.
17
     *
18
     * @var bool
19
     */
20
    public $bubbles = true;
21
    /**
22
     * Returns a boolean indicating whether the event is cancelable.
23
     *
24
     * @var bool
25
     */
26
    public $cancelable = true;
27
    /**
28
     * Returns a reference to the currently registered target for the event.
29
     *
30
     * @var bool
31
     */
32
    public $currentTarget;
33
    /**
34
     * Returns detail about the event, depending on the type of event.
35
     *
36
     * @var string
37
     * @link http://developer.mozilla.org/en/DOM/event.detail
38
     */
39
    public $detail; // ???
40
    /**
41
     * Used to indicate which phase of the event flow is currently being evaluated.
42
     *
43
     * NOT IMPLEMENTED
44
     *
45
     * @var string
46
     * @link http://developer.mozilla.org/en/DOM/event.eventPhase
47
     */
48
    public $eventPhase; // ???
49
    /**
50
     * The explicit original target of the event (Mozilla-specific).
51
     *
52
     * NOT IMPLEMENTED
53
     *
54
     * @var string
55
     */
56
    public $explicitOriginalTarget; // moz only
57
    /**
58
     * The original target of the event, before any retargetings (Mozilla-specific).
59
     *
60
     * NOT IMPLEMENTED
61
     *
62
     * @var string
63
     */
64
    public $originalTarget; // moz only
65
    /**
66
     * Identifies a secondary target for the event.
67
     *
68
     * @var string
69
     */
70
    public $relatedTarget;
71
    /**
72
     * Returns a reference to the target to which the event was originally dispatched.
73
     *
74
     * @var string
75
     */
76
    public $target;
77
    /**
78
     * Returns the time that the event was created.
79
     *
80
     * @var string
81
     */
82
    public $timeStamp;
83
    /**
84
     * Returns the name of the event (case-insensitive).
85
     */
86
    public $type;
87
    public $runDefault = true;
88
    public $data = null;
89
90
    public function __construct($data)
91
    {
92
        foreach ($data as $k => $v) {
93
            $this->$k = $v;
94
        }
95
        if (!$this->timeStamp) {
96
            $this->timeStamp = time();
0 ignored issues
show
Documentation Bug introduced by
The property $timeStamp was declared of type string, but time() is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
97
        }
98
    }
99
100
    /**
101
     * Cancels the event (if it is cancelable).
102
     *
103
     */
104
    public function preventDefault()
105
    {
106
        $this->runDefault = false;
107
    }
108
109
    /**
110
     * Stops the propagation of events further along in the DOM.
111
     *
112
     */
113
    public function stopPropagation()
114
    {
115
        $this->bubbles = false;
116
    }
117
}
118