These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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
|
|||
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 | /** |
||
24 | * @param AdaptFormEvent $event |
||
25 | */ |
||
26 | 1 | public function adaptForm(AdaptFormEvent $event) |
|
27 | { |
||
28 | 1 | $page = $event->getPage(); |
|
29 | 1 | $tabPane = $event->getTabPane(); |
|
30 | |||
31 | 1 | if ($page instanceof HasNodeInterface === false) { |
|
32 | return; |
||
33 | } |
||
34 | |||
35 | 1 | if ($page->isStructureNode() === true) { |
|
36 | return; |
||
37 | } |
||
38 | |||
39 | /** @var PageTabInterface $page */ |
||
40 | 1 | if ($page instanceof PageTabInterface === false) { |
|
41 | return; |
||
42 | } |
||
43 | |||
44 | 1 | $this->addTabs($tabPane, $page); |
|
45 | 1 | } |
|
46 | } |
||
47 |
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.