Issues (480)

src/Event/EventModel.php (1 issue)

Checks if used constants are declared or listed as dependencies.

Bug Major
1
<?php
2
/**
3
 *
4
 */
5
6
namespace Mvc5\Event;
7
8
use Mvc5\Signal;
9
10
use function is_string;
11
use function key;
12
13
use const Mvc5\EVENT;
0 ignored issues
show
The constant Mvc5\EVENT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
14
15
trait EventModel
16
{
17
    /**
18
     *
19
     */
20
    use Model;
21
22
    /**
23
     * @return array
24
     */
25 3
    protected function args() : array
26
    {
27
        return [
28 3
            EVENT => $this
29
        ];
30
    }
31
32
    /**
33
     * @param callable $callable
34
     * @param array $args
35
     * @param callable|null $callback
36
     * @return mixed
37
     * @throws \Throwable
38
     */
39 24
    protected function signal(callable $callable, array $args = [], callable $callback = null)
40
    {
41 24
        return Signal::emit($callable, $args, $callback);
42
    }
43
44
    /**
45
     * @param callable $callable
46
     * @param array $args
47
     * @param callable|null $callback
48
     * @return mixed
49
     * @throws \Throwable
50
     */
51 3
    function __invoke(callable $callable, array $args = [], callable $callback = null)
52
    {
53 3
        return $this->signal(
54 3
            $callable, !$args ? $this->args() : (!is_string(key($args)) ? $args : $this->args() + $args), $callback
55
        );
56
    }
57
}
58