Passed
Push — master ( e140d0...d9458c )
by Gabriel
12:38
created

Dispatchable   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A dispatch() 0 3 1
A dispatchUnless() 0 4 2
A dispatchIf() 0 4 2
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
    /**
13
     * Dispatch the event with the given arguments.
14
     *
15
     * @return EventInterface|object
16
     */
17
    public static function dispatch()
18
    {
19
        return event(new static(...func_get_args())); /** @phpstan-ignore-line */
0 ignored issues
show
Unused Code introduced by
The call to ByTIC\EventDispatcher\Ev...atchable::__construct() has too many arguments starting with func_get_args(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

19
        return event(/** @scrutinizer ignore-call */ new static(...func_get_args())); /** @phpstan-ignore-line */

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.

Loading history...
20
    }
21
22
    /**
23
     * Dispatch the event with the given arguments if the given truth test passes.
24
     *
25
     * @param  bool  $boolean
26
     * @return EventInterface|object|void
27
     */
28
    public static function dispatchIf($boolean, ...$arguments)
29
    {
30
        if ($boolean) {
31
            return static::dispatch(...$arguments);
32
        }
33
    }
34
35
    /**
36
     * Dispatch the event with the given arguments unless the given truth test passes.
37
     *
38
     * @param  bool  $boolean
39
     * @return EventInterface|object|void
40
     */
41
    public static function dispatchUnless($boolean, ...$arguments)
42
    {
43
        if (! $boolean) {
44
            return static::dispatch(...$arguments);
45
        }
46
    }
47
}