VarnishMenuAdaptor::adaptChildren()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 17

Duplication

Lines 17
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 17
loc 17
ccs 0
cts 16
cp 0
rs 9.7
c 0
b 0
f 0
cc 4
nc 3
nop 4
crap 20
1
<?php
2
3
namespace Kunstmaan\CacheBundle\Helper\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 View Code Duplication
class VarnishMenuAdaptor implements MenuAdaptorInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
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) && 'KunstmaanAdminBundle_settings' == $parent->getRoute()) {
23
            $menuItem = new MenuItem($menu);
24
            $menuItem
25
                ->setRoute('kunstmaancachebundle_varnish_settings_ban')
26
                ->setLabel('Varnish ban')
27
                ->setUniqueId('varnish_ban')
28
                ->setParent($parent);
29
30
            if (stripos($request->attributes->get('_route'), $menuItem->getRoute()) === 0) {
31
                $menuItem->setActive(true);
32
                $parent->setActive(true);
33
            }
34
            $children[] = $menuItem;
35
        }
36
    }
37
}
38