Completed
Push — master ( ae5e03...0447ee )
by Jeroen
10:35 queued 04:37
created

TranslatorMenuAdaptor   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 67.27 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 3
dl 37
loc 55
ccs 0
cts 42
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B adaptChildren() 37 44 7

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\TranslatorBundle\Service\Menu;
4
5
use Kunstmaan\AdminBundle\Helper\Menu\MenuAdaptorInterface;
6
use Kunstmaan\AdminBundle\Helper\Menu\MenuBuilder;
7
use Kunstmaan\AdminBundle\Helper\Menu\MenuItem;
8
use Symfony\Component\HttpFoundation\Request;
9
10
class TranslatorMenuAdaptor 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
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
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
    public function adaptChildren(MenuBuilder $menu, array &$children, MenuItem $parent = null, Request $request = null)
21
    {
22
        if (\is_null($parent)) {
23
            return;
24
        }
25
26 View Code Duplication
        if ('KunstmaanAdminBundle_settings' == $parent->getRoute()) {
0 ignored issues
show
Duplication introduced by
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...
27
            $menuItem = new MenuItem($menu);
28
            $menuItem
29
                ->setRoute('KunstmaanTranslatorBundle_settings_translations')
30
                ->setLabel('translator.translator.title')
31
                ->setUniqueId('Translations')
32
                ->setParent($parent);
33
            if (stripos($request->attributes->get('_route'), $menuItem->getRoute()) === 0) {
34
                $menuItem->setActive(true);
35
                $parent->setActive(true);
36
            }
37
            $children[] = $menuItem;
38
        } elseif ('KunstmaanTranslatorBundle_settings_translations' == $parent->getRoute()) {
39
            $menuItem = new MenuItem($menu);
40
            $menuItem
41
                ->setRoute('KunstmaanTranslatorBundle_settings_translations_add')
42
                ->setUniqueId('Add translation')
43
                ->setLabel('Add translation')
44
                ->setParent($parent)
45
                ->setAppearInNavigation(false);
46
            if (stripos($request->attributes->get('_route'), $menuItem->getRoute()) === 0) {
47
                $menuItem->setActive(true);
48
            }
49
            $children[] = $menuItem;
50
51
            $menuItem = new MenuItem($menu);
52
            $menuItem
53
                ->setRoute('KunstmaanTranslatorBundle_settings_translations_edit')
54
                ->setUniqueId('Edit translation')
55
                ->setLabel('Edit translation')
56
                ->setParent($parent)
57
                ->setAppearInNavigation(false);
58
            if (stripos($request->attributes->get('_route'), $menuItem->getRoute()) === 0) {
59
                $menuItem->setActive(true);
60
            }
61
            $children[] = $menuItem;
62
        }
63
    }
64
}
65