ConvertNotValidCurrentPageToNotFoundListener   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 35
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A onException() 0 19 4
A getSubscribedEvents() 0 6 1
1
<?php
2
namespace  WhiteOctober\PagerfantaBundle\EventListener;
3
4
use Pagerfanta\Exception\NotValidCurrentPageException;
5
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
6
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
7
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
8
use Symfony\Component\HttpKernel\KernelEvents;
9
10
class ConvertNotValidCurrentPageToNotFoundListener implements EventSubscriberInterface
11
{
12
    /**
13
     * @param GetResponseForExceptionEvent $event
14
     */
15
    public function onException(GetResponseForExceptionEvent $event)
16
    {
17
        if (method_exists($event, 'getThrowable')) {
18
            $throwable = $event->getThrowable();
19
        } else {
20
            // Support for Symfony 4.3 and before
21
            $throwable = $event->getException();
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Component\HttpKe...onEvent::getException() has been deprecated with message: since Symfony 4.4, use getThrowable instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
22
        }
23
24
        if ($throwable instanceof NotValidCurrentPageException) {
25
            $notFoundHttpException = new NotFoundHttpException('Page Not Found', $throwable);
26
            if (method_exists($event, 'setThrowable')) {
27
                $event->setThrowable($notFoundHttpException);
28
            } else {
29
                // Support for Symfony 4.3 and before
30
                $event->setException($notFoundHttpException);
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Component\HttpKe...onEvent::setException() has been deprecated with message: since Symfony 4.4, use setThrowable instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
31
            }
32
        }
33
    }
34
35
    /**
36
     * {@inheritDoc}
37
     */
38
    public static function getSubscribedEvents()
39
    {
40
        return array(
41
            KernelEvents::EXCEPTION => array('onException', 512)
42
        );
43
    }
44
}
45