FormValidRequestHandler   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 11
c 1
b 0
f 0
dl 0
loc 30
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getPostSaveEventName() 0 3 1
A getPreSaveEventName() 0 3 1
A handleRequest() 0 13 3
A action() 0 3 1
1
<?php
2
3
/**
4
 * (c) FSi sp. z o.o. <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace FSi\Bundle\AdminBundle\Admin\CRUD\Context\Request;
13
14
use FSi\Bundle\AdminBundle\Admin\Context\Request\AbstractFormValidRequestHandler;
15
use FSi\Bundle\AdminBundle\Event\AdminEvent;
16
use FSi\Bundle\AdminBundle\Event\FormEvent;
17
use FSi\Bundle\AdminBundle\Event\FormEvents;
18
use Symfony\Component\HttpFoundation\Request;
19
use Symfony\Component\HttpFoundation\Response;
20
21
class FormValidRequestHandler extends AbstractFormValidRequestHandler
22
{
23
    protected function action(FormEvent $event, Request $request): void
24
    {
25
        $event->getElement()->save($event->getForm()->getData());
0 ignored issues
show
Bug introduced by
The method save() does not exist on FSi\Bundle\AdminBundle\Admin\Element. It seems like you code against a sub-type of FSi\Bundle\AdminBundle\Admin\Element such as FSi\Bundle\AdminBundle\A...CRUD\GenericCRUDElement or FSi\Bundle\AdminBundle\A...CRUD\GenericFormElement or FSi\Bundle\AdminBundle\A...\GenericResourceElement or FSi\Bundle\AdminBundle\Admin\CRUD\FormElement or FSi\Bundle\AdminBundle\Admin\CRUD\CRUDElement or FSi\Bundle\AdminBundle\Admin\CRUD\CRUDElement or FSi\Bundle\AdminBundle\Admin\CRUD\FormElement or FSi\Bundle\AdminBundle\A...ourceRepository\Element or FSi\Bundle\AdminBundle\Admin\CRUD\CRUDElement or FSi\Bundle\AdminBundle\D...in\DependentFormElement or FSi\Bundle\AdminBundle\A...UD\DependentFormElement or FSi\Bundle\AdminBundle\A...UD\DependentCRUDElement or FSi\Bundle\AdminBundle\D...in\DependentCRUDElement. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
        $event->getElement()->/** @scrutinizer ignore-call */ save($event->getForm()->getData());
Loading history...
26
    }
27
28
    protected function getPreSaveEventName(): string
29
    {
30
        return FormEvents::FORM_DATA_PRE_SAVE;
31
    }
32
33
    protected function getPostSaveEventName(): string
34
    {
35
        return FormEvents::FORM_DATA_POST_SAVE;
36
    }
37
38
    public function handleRequest(AdminEvent $event, Request $request): ?Response
39
    {
40
        $response = parent::handleRequest($event, $request);
41
        if ($response) {
0 ignored issues
show
introduced by
$response is of type Symfony\Component\HttpFoundation\Response, thus it always evaluated to true.
Loading history...
42
            return $response;
43
        }
44
45
        $this->eventDispatcher->dispatch(FormEvents::FORM_RESPONSE_PRE_RENDER, $event);
46
        if ($event->hasResponse()) {
47
            return $event->getResponse();
48
        }
49
50
        return null;
51
    }
52
}
53