Completed
Push — master ( 1ddfef...8de58a )
by Guilh
05:31
created

ExceptionListener   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 92.86%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
c 2
b 0
f 1
lcom 1
cbo 4
dl 0
loc 32
ccs 13
cts 14
cp 0.9286
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A onKernelException() 0 10 2
A duplicateRequest() 0 12 2
1
<?php
2
3
/*
4
 * This file is part of the FOSRestBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
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 FOS\RestBundle\EventListener;
13
14
use FOS\RestBundle\FOSRestBundle;
15
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
16
use Symfony\Component\HttpKernel\EventListener\ExceptionListener as HttpKernelExceptionListener;
17
use Symfony\Component\HttpFoundation\Request;
18
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
19
20
/**
21
 * ExceptionListener.
22
 *
23
 * @author Ener-Getick <[email protected]>
24
 *
25
 * @internal
26
 */
27
class ExceptionListener extends HttpKernelExceptionListener
28
{
29
    /**
30
     * {@inheritdoc}
31
     */
32 8
    public function onKernelException(GetResponseForExceptionEvent $event)
33
    {
34 8
        $request = $event->getRequest();
35
36 8
        if (!$request->attributes->get(FOSRestBundle::ZONE_ATTRIBUTE, true)) {
37
            return;
38
        }
39
40 8
        parent::onKernelException($event);
41 8
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 8
    protected function duplicateRequest(\Exception $exception, Request $request)
47
    {
48
        $attributes = array(
49 8
            '_controller' => $this->controller,
50 8
            'exception' => $exception,
51 8
            'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null,
52 8
        );
53 8
        $request = $request->duplicate(null, null, $attributes);
54 8
        $request->setMethod('GET');
55
56 8
        return $request;
57
    }
58
}
59