SetResetButtonSubscriber::preSetData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Importance

Changes 0
Metric Value
dl 6
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
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