1 | <?php |
||
2 | |||
3 | namespace ByTIC\EventDispatcher\Events; |
||
4 | |||
5 | /** |
||
6 | * Class Dispatchable |
||
7 | * @package ByTIC\EventDispatcher\Events |
||
8 | */ |
||
9 | trait Dispatchable |
||
10 | { |
||
11 | /** |
||
12 | * Dispatch the event with the given arguments. |
||
13 | * |
||
14 | * @return EventInterface|object |
||
15 | */ |
||
16 | public static function dispatch() |
||
17 | { |
||
18 | return event(new static(...func_get_args())); /** @phpstan-ignore-line */ |
||
0 ignored issues
–
show
|
|||
19 | } |
||
20 | |||
21 | /** |
||
22 | * Dispatch the event with the given arguments if the given truth test passes. |
||
23 | * |
||
24 | * @param bool $boolean |
||
25 | * @return EventInterface|object|void |
||
26 | */ |
||
27 | public static function dispatchIf($boolean, ...$arguments) |
||
28 | { |
||
29 | if ($boolean) { |
||
30 | return static::dispatch(...$arguments); |
||
31 | } |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * Dispatch the event with the given arguments unless the given truth test passes. |
||
36 | * |
||
37 | * @param bool $boolean |
||
38 | * @return EventInterface|object|void |
||
39 | */ |
||
40 | public static function dispatchUnless($boolean, ...$arguments) |
||
41 | { |
||
42 | if (! $boolean) { |
||
43 | return static::dispatch(...$arguments); |
||
44 | } |
||
45 | } |
||
46 | } |
||
47 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.