Completed
Pull Request — 5.6 (#2830)
by Jeroen
14:14
created

NodeTabListener::adaptForm()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4.3244

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 8
cts 11
cp 0.7272
rs 9.6
c 0
b 0
f 0
cc 4
nc 4
nop 1
crap 4.3244
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 1 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 1
        foreach ($page->getTabs() as $pageTab) {
17 1
            $formWidget = new FormWidget();
18 1
            $formWidget->addType($pageTab->getInternalName(), $pageTab->getFormTypeClass(), $page);
19 1
            $tabPane->addTab(new Tab($pageTab->getTabTitle(), $formWidget), $pageTab->getPosition());
20
        }
21 1
    }
22
23 1
    public function adaptForm(AdaptFormEvent $event)
24
    {
25 1
        $page = $event->getPage();
26 1
        $tabPane = $event->getTabPane();
27
28 1
        if ($page instanceof HasNodeInterface === false) {
29
            return;
30
        }
31
32 1
        if ($page->isStructureNode() === true) {
33
            return;
34
        }
35
36
        /** @var PageTabInterface $page */
37 1
        if ($page instanceof PageTabInterface === false) {
38
            return;
39
        }
40
41 1
        $this->addTabs($tabPane, $page);
42 1
    }
43
}
44