Event   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 29
rs 10
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 18 6
1
<?php
2
/**
3
 * Webino™ (http://webino.sk)
4
 *
5
 * @link        https://github.com/webino/event-emitter
6
 * @copyright   Copyright (c) 2019 Webino, s.r.o. (http://webino.sk)
7
 * @author      Peter Bačinský <[email protected]>
8
 * @license     BSD-3-Clause
9
 */
10
11
namespace Webino;
12
13
/**
14
 * Class Event
15
 * @package event-emitter
16
 */
17
class Event extends \ArrayObject implements EventInterface
18
{
19
    use EventTrait;
20
21
    /**
22
     * Create new event from string or other event object.
23
     *
24
     * @param string|self|null $event Event name or object
25
     * @param EventEmitterInterface|null $target Event target object
26
     * @param array $values Custom event values
27
     */
28
    public function __construct($event = null, $target = null, array $values = [])
29
    {
30
        parent::__construct();
31
32
        // event class as default event name
33
        $event or $event = get_class($this);
34
35
        // init event from string or object
36
        if (is_string($event)) {
37
            $this->setName($event);
38
        } elseif ($event instanceof EventInterface) {
39
            $this->setTarget($event->getTarget());
40
            $this->exchangeArray($event->getArrayCopy());
41
        }
42
43
        // set event target and parameters if any
44
        $target and $this->setTarget($target);
45
        $values and $this->exchangeArray($values);
46
    }
47
}
48