Event::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
3
namespace Da\Mailer\Event;
4
5
use Da\Mailer\Exception\InvalidCallbackArgumentException;
6
7
class Event
8
{
9
    /**
10
     * @var object the class firing the event.
11
     */
12
    public $owner;
13
/**
14
     * @var array the collected arguments passed to the event
15
     */
16
    private $data;
17
/**
18
     * @var callable
19
     */
20
    private $handler;
21
/**
22
     * Callback constructor.
23
     *
24
     * @param callable $handler
25
     */
26 5
    public function __construct($handler)
27
    {
28 5
        if (!is_callable($handler)) {
29 1
            throw new InvalidCallbackArgumentException('Argument is not callable!');
30
        }
31 4
        $this->handler = $handler;
32 4
    }
33
34
    /**
35
     * @return mixed
36
     */
37 4
    public function __invoke()
38
    {
39 4
        $this->data = func_get_args();
40
        return call_user_func($this->handler, $this);
41 4
    }
42
43
    /**
44
     * @return array the collected arguments passed to the event
45
     */
46
    public function getData()
47 4
    {
48
        return $this->data;
49 4
    }
50
}
51