Issues (3)

EventHandler/ResourceControllerEventHandler.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\SyliusPaginationPlugin\EventHandler;
6
7
use Pagerfanta\Pagerfanta;
8
use Setono\SyliusPaginationPlugin\Exception\UnexpectedEventException;
9
use Setono\SyliusPaginationPlugin\ParameterBag\PaginationParameterBag;
10
use Sylius\Bundle\ResourceBundle\Event\ResourceControllerEvent;
11
use Sylius\Bundle\ResourceBundle\Grid\View\ResourceGridView;
12
use Symfony\Component\EventDispatcher\Event;
13
14
final class ResourceControllerEventHandler implements EventHandlerInterface
15
{
16
    public function supports(Event $event): bool
17
    {
18
        if (!$event instanceof ResourceControllerEvent) {
19
            return false;
20
        }
21
22
        $resourceGridView = $event->getSubject();
23
        if (!$resourceGridView instanceof ResourceGridView) {
24
            return false;
25
        }
26
27
        $data = $resourceGridView->getData();
28
        if (!$data instanceof Pagerfanta) {
29
            return false;
30
        }
31
32
        return true;
33
    }
34
35
    /**
36
     * @param ResourceControllerEvent $event
37
     *
38
     * @return PaginationParameterBag
39
     */
40
    public function handle(Event $event): PaginationParameterBag
41
    {
42
        if (!$this->supports($event)) {
43
            throw new UnexpectedEventException($event, ResourceControllerEvent::class);
44
        }
45
46
        /** @var ResourceGridView $resourceGridView */
47
        $resourceGridView = $event->getSubject();
0 ignored issues
show
The method getSubject() does not exist on Symfony\Component\EventDispatcher\Event. It seems like you code against a sub-type of Symfony\Component\EventDispatcher\Event such as Symfony\Component\Security\Core\Event\VoteEvent or PhpSpec\Event\MethodCallEvent or PhpSpec\Event\ExpectationEvent or Symfony\Component\EventDispatcher\GenericEvent. ( Ignorable by Annotation )

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

47
        /** @scrutinizer ignore-call */ 
48
        $resourceGridView = $event->getSubject();
Loading history...
48
49
        /** @var Pagerfanta $data */
50
        $data = $resourceGridView->getData();
51
52
        return new PaginationParameterBag($resourceGridView->getRequestConfiguration()->getRequest(), $data->getNbResults(), $data->getMaxPerPage(), $data->getCurrentPage());
53
    }
54
}
55