FooExtensionMenu   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getUser() 0 8 1
A __construct() 0 2 1
A get() 0 10 3
A getAdmin() 0 14 1
A getBundleName() 0 3 1
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 FooExtensionMenu implements ExtensionMenuInterface
21
{
22
    public function __construct(private readonly FactoryInterface $factory)
23
    {
24
    }
25
26
    public function get(string $type = ExtensionMenuInterface::TYPE_ADMIN): ?ItemInterface
0 ignored issues
show
Bug introduced by
The constant Zikula\ThemeBundle\Exten...nuInterface::TYPE_ADMIN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
27
    {
28
        if (ExtensionMenuInterface::TYPE_ADMIN === $type) {
29
            return $this->getAdmin();
30
        }
31
        if (ExtensionMenuInterface::TYPE_USER === $type) {
0 ignored issues
show
Bug introduced by
The constant Zikula\ThemeBundle\Exten...enuInterface::TYPE_USER was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
32
            return $this->getUser();
33
        }
34
35
        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...
36
    }
37
38
    private function getAdmin(): ?ItemInterface
39
    {
40
        $menu = $this->factory->createItem('foo');
41
        $menu->addChild('list', [
42
            'route' => 'list',
43
        ]);
44
        $menu->addChild('foo', [
45
            'route' => 'foo',
46
        ]);
47
        $menu->addChild('bar', [
48
            'route' => 'bar',
49
        ]);
50
51
        return $menu;
52
    }
53
54
    private function getUser(): ?ItemInterface
55
    {
56
        $menu = $this->factory->createItem('foo');
57
        $menu->addChild('user list', [
58
            'route' => 'user_list',
59
        ]);
60
61
        return $menu;
62
    }
63
64
    public function getBundleName(): string
65
    {
66
        return 'ZikulaFooExtension';
67
    }
68
}
69