Issues (36)

src/Events/Traits/HasNameTrait.php (2 issues)

1
<?php
2
3
namespace ByTIC\EventDispatcher\Events\Traits;
4
5
use ByTIC\EventDispatcher\Events\EventInterface;
6
7
/**
8
 * Trait HasNameTrait
9
 * @package ByTIC\EventDispatcher\Events\Traits
10
 */
11
trait HasNameTrait
12
{
13
    protected $name = null;
14
15 6
    public function eventName(): string
16
    {
17 6
        return $this->getName();
18 5
    }
19
20 6
    public function getName()
21
    {
22
        if ($this->name === null) {
23
            $this->name = get_called_class();
24
        }
25
        return $this->name;
26 3
    }
27
28 3
    /**
29 3
     * @param null $name
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $name is correct as it would always require null to be passed?
Loading history...
30
     */
31
    public function setName($name)
32
    {
33
        $this->name = $name;
34
    }
35
36
    /**
37
     * Create a new event instance.
38 3
     *
39
     * @param string $name
40 3
     * @param mixed ...$arguments
41 3
     * @return EventInterface|static
42 3
     */
43
    public static function named($name, ... $arguments)
44
    {
45
        $event = new static(... $arguments);/** @phpstan-ignore-line */
0 ignored issues
show
The call to ByTIC\EventDispatcher\Ev...ameTrait::__construct() has too many arguments starting with $arguments. ( Ignorable by Annotation )

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

45
        $event = /** @scrutinizer ignore-call */ new static(... $arguments);/** @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...
46
        $event->setName($name);
47
        return $event;
48
    }
49
}
50