Completed
Pull Request — master (#311)
by Łukasz
03:20
created

DataSourceBindParametersHandler::handleRequest()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 8.9197
c 0
b 0
f 0
cc 4
eloc 12
nc 4
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * (c) FSi sp. z o.o. <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FSi\Bundle\AdminBundle\Admin\CRUD\Context\Request;
13
14
use FSi\Bundle\AdminBundle\Admin\Context\Request\AbstractHandler;
15
use FSi\Bundle\AdminBundle\Event\AdminEvent;
16
use FSi\Bundle\AdminBundle\Event\ListEvent;
17
use FSi\Bundle\AdminBundle\Event\ListEvents;
18
use FSi\Bundle\AdminBundle\Exception\RequestHandlerException;
19
use Symfony\Component\HttpFoundation\Request;
20
use Symfony\Component\HttpFoundation\Response;
21
22
class DataSourceBindParametersHandler extends AbstractHandler
23
{
24
    public function handleRequest(AdminEvent $event, Request $request): ?Response
25
    {
26
        $event = $this->validateEvent($event);
27
28
        if ($event->hasResponse()) {
29
            return $event->getResponse();
30
        }
31
32
        $this->eventDispatcher->dispatch(ListEvents::LIST_DATASOURCE_REQUEST_PRE_BIND, $event);
33
        if ($event->hasResponse()) {
34
            return $event->getResponse();
35
        }
36
37
        $event->getDataSource()->bindParameters($request);
0 ignored issues
show
Documentation introduced by
$request is of type object<Symfony\Component\HttpFoundation\Request>, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
38
39
        $this->eventDispatcher->dispatch(ListEvents::LIST_DATASOURCE_REQUEST_POST_BIND, $event);
40
        if ($event->hasResponse()) {
41
            return $event->getResponse();
42
        }
43
44
        return null;
45
    }
46
47
    private function validateEvent(AdminEvent $event): ListEvent
48
    {
49
        if (!$event instanceof ListEvent) {
50
            throw new RequestHandlerException(sprintf('%s require ListEvent', get_class($this)));
51
        }
52
53
        return $event;
54
    }
55
}
56