Completed
Pull Request — 3.x (#6276)
by
unknown
03:07
created

GroupMenuProvider::canGenerateMenuItem()   C

Complexity

Conditions 12
Paths 35

Size

Total Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 41
rs 6.9666
c 0
b 0
f 0
cc 12
nc 35
nop 2

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
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 Sonata\AdminBundle\Menu\Provider;
15
16
use Knp\Menu\ItemInterface;
17
use Knp\Menu\Matcher\Matcher;
18
19
// NEXT_MAJOR: Remove the else part when dropping support of knplabs/knp-menu 2.x
20
if (!method_exists(Matcher::class, 'addVoter')) {
21
    /**
22
     * Menu provider based on group options.
23
     *
24
     * @final since sonata-project/admin-bundle 3.52
25
     *
26
     * @author Alexandru Furculita <[email protected]>
27
     */
28
    class GroupMenuProvider extends BaseGroupMenuProvider
29
    {
30
        /**
31
         * Retrieves the menu based on the group options.
32
         *
33
         * @throws \InvalidArgumentException if the menu does not exists
34
         */
35
        public function get(string $name, array $options = []): ItemInterface
36
        {
37
            return $this->doGet($name, $options);
38
        }
39
40
        public function has(string $name, array $options = []): bool
41
        {
42
            return $this->doHas($name, $options);
43
        }
44
    }
45
} else {
46
    /**
47
     * Menu provider based on group options.
48
     *
49
     * @final since sonata-project/admin-bundle 3.52
50
     *
51
     * @author Alexandru Furculita <[email protected]>
52
     */
53
    class GroupMenuProvider extends BaseGroupMenuProvider
0 ignored issues
show
Comprehensibility Best Practice introduced by
The type Sonata\AdminBundle\Menu\Provider\GroupMenuProvider has been defined more than once; this definition is ignored, only the first definition in this file (L28-44) is considered.

This check looks for classes that have been defined more than once in the same file.

If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.

This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.

Loading history...
54
    {
55
        /**
56
         * Retrieves the menu based on the group options.
57
         *
58
         * @param string $name
59
         *
60
         * @throws \InvalidArgumentException if the menu does not exists
61
         *
62
         * @return \Knp\Menu\ItemInterface
63
         */
64
        public function get($name, array $options = [])
65
        {
66
            return $this->doGet($name, $options);
67
        }
68
69
        /**
70
         * Checks whether a menu exists in this provider.
71
         *
72
         * @param string $name
73
         *
74
         * @return bool
75
         */
76
        public function has($name, array $options = [])
77
        {
78
            return $this->doHas($name, $options);
79
        }
80
    }
81
}
82