Completed
Pull Request — 5.1 (#2266)
by
unknown
12:07
created

NodeTabListener   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 22.86 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 7
dl 8
loc 35
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addTabs() 8 8 2
A adaptForm() 0 20 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\Helper\FormWidgets\FormWidget;
6
use Kunstmaan\AdminBundle\Helper\FormWidgets\Tabs\Tab;
7
use Kunstmaan\AdminBundle\Helper\FormWidgets\Tabs\TabPane;
8
use Kunstmaan\NodeBundle\Entity\HasNodeInterface;
9
use Kunstmaan\NodeBundle\Entity\PageTabInterface;
10
use Kunstmaan\NodeBundle\Event\AdaptFormEvent;
11
12
class NodeTabListener
13
{
14 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...
15
    {
16
        foreach ($page->getTabs() as $pageTab) {
17
            $formWidget = new FormWidget();
18
            $formWidget->addType($pageTab->getInternalName(), $pageTab->getFormTypeClass(), $page);
19
            $tabPane->addTab(new Tab($pageTab->getTabTitle(), $formWidget), $pageTab->getPosition());
20
        }
21
    }
22
23
    /**
24
     * @param AdaptFormEvent $event
25
     */
26
    public function adaptForm(AdaptFormEvent $event)
27
    {
28
        $page = $event->getPage();
29
        $tabPane = $event->getTabPane();
30
31
        if ($page instanceof HasNodeInterface === false) {
32
            return;
33
        }
34
35
        if ($page->isStructureNode() === true) {
36
            return;
37
        }
38
39
        /** @var PageTabInterface $page */
40
        if ($page instanceof PageTabInterface === false) {
41
            return;
42
        }
43
44
        $this->addTabs($tabPane, $page);
45
    }
46
}
47