Completed
Push — master ( ba8ed9...770316 )
by Jeroen
06:11
created

ModulesMenuAdaptor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 46.15 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 12
loc 26
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A adaptChildren() 12 15 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Kunstmaan\AdminBundle\Helper\Menu;
4
5
use Symfony\Component\HttpFoundation\Request;
6
7
/**
8
 * MenuAdaptor to add the Modules MenuItem to the top menu
9
 */
10
class ModulesMenuAdaptor implements MenuAdaptorInterface
11
{
12
    /**
13
     * In this method you can add children for a specific parent, but also remove and change the already created children
14
     *
15
     * @param MenuBuilder $menu      The MenuBuilder
16
     * @param MenuItem[]  &$children The current children
17
     * @param MenuItem    $parent    The parent Menu item
0 ignored issues
show
Documentation introduced by Kris Pypen
Should the type for parameter $parent not be null|MenuItem?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
18
     * @param Request     $request   The Request
0 ignored issues
show
Documentation introduced by Kris Pypen
Should the type for parameter $request not be null|Request?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
19
     */
20 1
    public function adaptChildren(MenuBuilder $menu, array &$children, MenuItem $parent = null, Request $request = null)
21
    {
22 1 View Code Duplication
        if (is_null($parent)) {
0 ignored issues
show
Duplication introduced by Wim Vandersmissen
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23 1
            $menuItem = new TopMenuItem($menu);
24
            $menuItem
25 1
                ->setRoute('KunstmaanAdminBundle_modules')
26 1
                ->setLabel('modules.title')
27 1
                ->setUniqueId('modules')
28 1
                ->setParent($parent);
29 1
            if (stripos($request->attributes->get('_route'), $menuItem->getRoute()) === 0) {
30 1
                $menuItem->setActive(true);
31
            }
32 1
            $children[] = $menuItem;
33
        }
34 1
    }
35
}
36