EventArgs::getEmptyInstance()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 3
b 0
f 0
nc 2
nop 0
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Common;
6
7
/**
8
 * EventArgs is the base class for classes containing event data.
9
 *
10
 * This class contains no event data. It is used by events that do not pass state
11
 * information to an event handler when an event is raised. The single empty EventArgs
12
 * instance can be obtained through {@link getEmptyInstance}.
13
 */
14
class EventArgs
15
{
16
    /**
17
     * Single instance of EventArgs.
18
     *
19
     * @var EventArgs
20
     */
21
    private static $_emptyEventArgsInstance;
22
23
    /**
24
     * Gets the single, empty and immutable EventArgs instance.
25
     *
26
     * This instance will be used when events are dispatched without any parameter,
27
     * like this: EventManager::dispatchEvent('eventname');
28
     *
29
     * The benefit from this is that only one empty instance is instantiated and shared
30
     * (otherwise there would be instances for every dispatched in the abovementioned form).
31
     *
32
     * @link https://msdn.microsoft.com/en-us/library/system.eventargs.aspx
33
     * @see EventManager::dispatchEvent
34
     *
35
     * @return EventArgs
36
     */
37 1
    public static function getEmptyInstance()
38
    {
39 1
        if (! self::$_emptyEventArgsInstance) {
40 1
            self::$_emptyEventArgsInstance = new EventArgs();
41
        }
42
43 1
        return self::$_emptyEventArgsInstance;
44
    }
45
}
46