Passed
Pull Request — master (#262)
by Arnaud
03:22
created

MenuProvider::has()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 1
c 3
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LAG\AdminBundle\Menu\Provider;
6
7
use Knp\Menu\ItemInterface;
8
use Knp\Menu\Provider\MenuProviderInterface;
9
use LAG\AdminBundle\Menu\Factory\MenuFactoryInterface;
10
11
/**
12
 * Create a new KNP menu using the MenuConfiguration class to validate provided options.
13
 */
14
class MenuProvider implements MenuProviderInterface
15
{
16
    private array $menuConfigurations;
17
    private MenuFactoryInterface $menuFactory;
18
19 1
    public function __construct(
20
        array $menuConfigurations,
21
        MenuFactoryInterface $menuFactory
22
    ) {
23 1
        $this->menuConfigurations = $menuConfigurations;
24 1
        $this->menuFactory = $menuFactory;
25 1
    }
26
27 1
    public function get(string $name, array $options = []): ItemInterface
28
    {
29 1
        $options = array_merge($this->menuConfigurations[$name] ?? [], $options);
30
31 1
        return $this->menuFactory->create($name, $options);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->menuFactor...create($name, $options) could return the type null which is incompatible with the type-hinted return Knp\Menu\ItemInterface. Consider adding an additional type-check to rule them out.
Loading history...
32
    }
33
34
    public function has(string $name, array $options = []): bool
35
    {
36
        return \array_key_exists($name, $this->menuConfigurations);
37
    }
38
}
39