EntityTabListener   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 14.81 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 7
dl 8
loc 54
ccs 0
cts 30
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A addTabs() 8 8 2
A adaptForm() 0 23 4

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\NodeBundle\EventListener;
4
5
use Kunstmaan\AdminBundle\Event\AdaptSimpleFormEvent;
6
use Kunstmaan\AdminBundle\Helper\FormWidgets\FormWidget;
7
use Kunstmaan\AdminBundle\Helper\FormWidgets\Tabs\Tab;
8
use Kunstmaan\AdminBundle\Helper\FormWidgets\Tabs\TabPane;
9
use Kunstmaan\NodeBundle\Entity\HasNodeInterface;
10
use Kunstmaan\NodeBundle\Entity\PageTabInterface;
11
use Symfony\Component\Form\FormFactoryInterface;
12
use Symfony\Component\HttpFoundation\Request;
13
use Symfony\Component\HttpFoundation\RequestStack;
14
15
class EntityTabListener
16
{
17
    /**
18
     * @var Request
19
     */
20
    private $request;
21
22
    /**
23
     * @var FormFactoryInterface
24
     */
25
    private $formFactory;
26
27
    public function __construct(RequestStack $requestStack, FormFactoryInterface $formFactory)
28
    {
29
        $this->request = $requestStack->getCurrentRequest();
30
        $this->formFactory = $formFactory;
31
    }
32
33 View Code Duplication
    public function addTabs(TabPane $tabPane, PageTabInterface $page)
0 ignored issues
show
Duplication introduced by
This method 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...
34
    {
35
        foreach ($page->getTabs() as $pageTab) {
36
            $formWidget = new FormWidget();
37
            $formWidget->addType($pageTab->getInternalName(), $pageTab->getFormTypeClass(), $page);
38
            $tabPane->addTab(new Tab($pageTab->getTabTitle(), $formWidget), $pageTab->getPosition());
39
        }
40
    }
41
42
    /**
43
     * @param AdaptSimpleFormEvent $event
44
     */
45
    public function adaptForm(AdaptSimpleFormEvent $event)
46
    {
47
        $entity = $event->getData();
48
        $tabPane = $event->getTabPane();
49
50
        if ($entity instanceof HasNodeInterface) {
51
            return;
52
        }
53
54
        if ($entity instanceof PageTabInterface === false) {
55
            return;
56
        }
57
58
        if ($tabPane instanceof TabPane === false) {
59
            $tabPane = new TabPane('id', $this->request, $this->formFactory);
60
        }
61
62
        $this->addTabs($tabPane, $entity);
63
64
        $tabPane->buildForm();
65
66
        $event->setTabPane($tabPane);
67
    }
68
}
69