SetResetButtonSubscriber   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 38
loc 38
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 4 4 1
A preSetData() 6 6 1
A addResetButton() 8 8 1

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 Black\Common\Application\Form\EventListener;
4
5
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
6
use Symfony\Component\Form\FormEvents;
7
use Symfony\Component\Form\FormEvent;
8
use Symfony\Component\Form\FormInterface;
9
10
/**
11
 * Class SetResetButtonSubscriber
12
 *
13
 * SetResetButtonSubscriber add "reset" button for your FormType
14
 */
15 View Code Duplication
class SetResetButtonSubscriber implements EventSubscriberInterface
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...
16
{
17
    /**
18
     * List events for this subscriber
19
     *
20
     * @return array
21
     */
22
    public static function getSubscribedEvents()
23
    {
24
        return [FormEvents::PRE_SET_DATA => 'preSetData'];
25
    }
26
27
    /**
28
     * Pre set Data form the subscriber and add button
29
     *
30
     * @param FormEvent $event
31
     */
32
    public function preSetData(FormEvent $event)
33
    {
34
        $form = $event->getForm();
35
36
        $this->addResetButton($form);
37
    }
38
39
    /**
40
     * Add the button
41
     *
42
     * @param FormInterface $form
43
     */
44
    private function addResetButton(FormInterface $form)
45
    {
46
        $form
47
            ->add('reset', 'reset', [
48
                    'label' => 'black.bundle.common.eventListener.setButtonsSubscriber.button.reset.label'
49
                ]
50
            );
51
    }
52
}
53