Completed
Push — master ( a1a6bb...2ea3ba )
by Bukashk0zzz
05:13
created

FilterListener::onPreSubmit()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php declare(strict_types = 1);
2
3
namespace Bukashk0zzz\FilterBundle\Form\EventListener;
4
5
use Bukashk0zzz\FilterBundle\Service\Filter;
6
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
7
use Symfony\Component\Form\FormEvent;
8
use Symfony\Component\Form\FormEvents;
9
10
/**
11
 * Class FilterListener
12
 */
13
class FilterListener implements EventSubscriberInterface
14
{
15
    /**
16
     * @var Filter
17
     */
18
    protected $filterService;
19
20
    /**
21
     * FilterListener constructor.
22
     *
23
     * @param Filter $filterService
24
     */
25
    public function __construct(Filter $filterService)
26
    {
27
        $this->filterService = $filterService;
28
    }
29
30
    /**
31
     * @return array<string>
32
     */
33
    public static function getSubscribedEvents(): array
34
    {
35
        return [
36
            FormEvents::POST_SUBMIT => 'onPostSubmit',
37
            FormEvents::PRE_SUBMIT => 'onPreSubmit',
38
        ];
39
    }
40
41
    /**
42
     * @param FormEvent $event
43
     *
44
     * @return void
45
     */
46 View Code Duplication
    public function onPostSubmit(FormEvent $event): void
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...
47
    {
48
        $clientData = $event->getData();
49
50
        if (!\is_object($clientData)) {
51
            return;
52
        }
53
54
        $this->filterService->filterEntity($clientData);
55
    }
56
57
    /**
58
     * @param FormEvent $event
59
     *
60
     * @return void
61
     */
62 View Code Duplication
    public function onPreSubmit(FormEvent $event): void
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...
63
    {
64
        $clientData = $event->getData();
65
66
        if (!\is_object($clientData)) {
67
            return;
68
        }
69
70
        $this->filterService->filterEntity($clientData);
71
    }
72
}
73