BarExtensionMenu::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Zikula package.
7
 *
8
 * Copyright Zikula - https://ziku.la/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Zikula\ThemeBundle\Tests\ExtensionMenu\Fixtures;
15
16
use Knp\Menu\FactoryInterface;
0 ignored issues
show
Bug introduced by
The type Knp\Menu\FactoryInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use Knp\Menu\ItemInterface;
0 ignored issues
show
Bug introduced by
The type Knp\Menu\ItemInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use Zikula\ThemeBundle\ExtensionMenu\ExtensionMenuInterface;
19
20
class BarExtensionMenu implements ExtensionMenuInterface
21
{
22
    public function __construct(private readonly FactoryInterface $factory)
23
    {
24
    }
25
26
    public function get(string $type = self::TYPE_ADMIN): ?ItemInterface
0 ignored issues
show
Bug introduced by
The constant Zikula\ThemeBundle\Tests...tensionMenu::TYPE_ADMIN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
27
    {
28
        $method = 'get' . ucfirst($type);
29
        if (method_exists($this, $method)) {
30
            return $this->{$method}();
31
        }
32
33
        return null;
0 ignored issues
show
Bug Best Practice introduced by
The expression return null returns the type null which is incompatible with the return type mandated by Zikula\ThemeBundle\Exten...ionMenuInterface::get() of iterable.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
34
    }
35
36
    private function getUser(): ?ItemInterface
37
    {
38
        $menu = $this->factory->createItem('admin');
39
        $menu->addChild('list', [
40
            'route' => 'list',
41
        ])->setAttribute('icon', 'fas fa-list');
42
        $menu->addChild('new', [
43
            'route' => 'edit',
44
        ]);
45
46
        return $menu;
47
    }
48
49
    private function getBar(): ?ItemInterface
50
    {
51
        $menu = $this->factory->createItem('foo');
52
        $menu->addChild('bar admin', [
53
            'route' => 'bar_admin',
54
        ])->setAttribute('icon', 'fas fa-plus');
55
56
        return $menu;
57
    }
58
59
    private function getAccount(): ?ItemInterface
60
    {
61
        $menu = $this->factory->createItem('account');
62
        $menu->addChild('bar acct', [
63
            'route' => 'bar_acct',
64
        ]);
65
66
        return $menu;
67
    }
68
69
    public function getBundleName(): string
70
    {
71
        return 'ZikulaBarExtension';
72
    }
73
}
74