MenuBuilder   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 8
dl 0
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A buildMenu() 0 7 1
1
<?php
2
3
/**
4
 * (c) FSi sp. z o.o. <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace FSi\Bundle\AdminBundle\Menu\Builder;
13
14
use FSi\Bundle\AdminBundle\Event\MenuEvent;
15
use FSi\Bundle\AdminBundle\Menu\Item\Item;
16
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
17
18
class MenuBuilder implements Builder
19
{
20
    /**
21
     * @var EventDispatcherInterface
22
     */
23
    private $eventDispatcher;
24
25
    /**
26
     * @var string
27
     */
28
    private $eventName;
29
30
    public function __construct(EventDispatcherInterface $eventDispatcher, string $eventName)
31
    {
32
        $this->eventName = $eventName;
33
        $this->eventDispatcher = $eventDispatcher;
34
    }
35
36
    public function buildMenu(): Item
37
    {
38
        $menu = new Item();
39
40
        $this->eventDispatcher->dispatch($this->eventName, new MenuEvent($menu));
0 ignored issues
show
Unused Code introduced by
The call to Symfony\Contracts\EventD...erInterface::dispatch() has too many arguments starting with new FSi\Bundle\AdminBundle\Event\MenuEvent($menu). ( Ignorable by Annotation )

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

40
        $this->eventDispatcher->/** @scrutinizer ignore-call */ 
41
                                dispatch($this->eventName, new MenuEvent($menu));

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...
Bug introduced by
$this->eventName of type string is incompatible with the type object expected by parameter $event of Symfony\Contracts\EventD...erInterface::dispatch(). ( Ignorable by Annotation )

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

40
        $this->eventDispatcher->dispatch(/** @scrutinizer ignore-type */ $this->eventName, new MenuEvent($menu));
Loading history...
41
42
        return $menu;
43
    }
44
}
45