Failed Conditions
Pull Request — master (#1861)
by k-yamamura
36:53
created

EccubeMonologListener::onKernelException()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 12
nc 2
nop 1
crap 3
1
<?php
2
3
namespace Eccube\Monolog\Listener;
4
5
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
6
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
7
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
8
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
9
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
10
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
11
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
12
use Symfony\Component\HttpKernel\KernelEvents;
13
14
/**
15
 * EccubeMonologListener
16
 *
17
 * @package Eccube\Monolog\Listener
18
 */
19
class EccubeMonologListener implements EventSubscriberInterface
20
{
21
    /**
22
     * @param GetResponseEvent $event
23
     */
24
    public function onKernelRequestEarly(GetResponseEvent $event)
25
    {
26
        if (!$event->isMasterRequest()) {
27 462
            return;
28
        }
29 462
30 72
        \EccubeLog::info('INIT');
31
    }
32
33 462
    /**
34 462
     * @param GetResponseEvent $event
35
     */
36 View Code Duplication
    public function onKernelRequest(GetResponseEvent $event)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
    {
38
        if (!$event->isMasterRequest()) {
39
            return;
40
        }
41 459
42
        $route = $this->getRoute($event->getRequest());
43 459
        \EccubeLog::info('PROCESS START', array($route));
44 72
    }
45
46
    /**
47 457
     * @param FilterControllerEvent $event
48 457
     */
49 View Code Duplication
    public function onKernelController(FilterControllerEvent $event)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50 450
    {
51
        if (!$event->isMasterRequest()) {
52 450
            return;
53 72
        }
54
55
        $route = $this->getRoute($event->getRequest());
56 450
        \EccubeLog::info('LOGIC START', array($route));
57 450
    }
58
59
    /**
60
     * @param FilterResponseEvent $event
61
     */
62 View Code Duplication
    public function onKernelResponse(FilterResponseEvent $event)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
    {
64 447
        if (!$event->isMasterRequest()) {
65
            return;
66 447
        }
67 447
68
        $route = $this->getRoute($event->getRequest());
69
        \EccubeLog::info('LOGIC END', array($route));
70
    }
71
72
    /**
73
     * @param PostResponseEvent $event
74 17
     */
75
    public function onKernelTerminate(PostResponseEvent $event)
76 17
    {
77 17
        $route = $this->getRoute($event->getRequest());
78
        \EccubeLog::info('PROCESS END', array($route));
79
    }
80
81
    /**
82
     * @param GetResponseForExceptionEvent $event
83
     */
84 462
    public function onKernelException(GetResponseForExceptionEvent $event)
85
    {
86
        $e = $event->getException();
87 462
        if ($e instanceof HttpExceptionInterface && $e->getStatusCode() < 500) {
88 462
            \EccubeLog::info($e->getMessage(), array($e->getStatusCode()));
89
0 ignored issues
show
Coding Style introduced by
Blank line found at end of control structure
Loading history...
90
        } else {
91
            $message = sprintf(
92
                '%s: %s (uncaught exception) at %s line %s',
93
                get_class($e),
94
                $e->getMessage(),
95 457
                $e->getFile(),
96
                $e->getLine()
97 457
            );
98 457
            \EccubeLog::error($message, array('exception' => $e));
99 457
        }
100
    }
101
102
    /**
103
     * {@inheritdoc}
104
     */
105
    public static function getSubscribedEvents()
106 450
    {
107
        return array(
108 450
109 450
            KernelEvents::REQUEST => array(
110 450
                // Application::initRenderingで、フロント/管理画面の判定が行われた後に実行
111
                array('onKernelRequestEarly', 500),
112 447
                // SecurityServiceProviderで、認証処理が完了した後に実行.
113
                array('onKernelRequest', 6),
114 447
            ),
115 447
            KernelEvents::RESPONSE => array('onKernelResponse', 0),
116 447
            KernelEvents::CONTROLLER => array('onKernelController', 0),
117
            KernelEvents::TERMINATE => array('onKernelTerminate', 0),
118
            /*
119
             * Priority -4 is used to come after those from SecurityServiceProvider (0)
120
             * but before the error handlers added with Silex\Application::error (defaults to -8)
121
             */
122
            KernelEvents::EXCEPTION => array('onKernelException', -4),
123 17
        );
124
    }
125 17
126 13
    /**
127
     * ルーティング名を取得する.
128 13
     *
129 4
     * @param $request
130 4
     * @return string
131 4
     */
132 4
    private function getRoute($request)
133 4
    {
134 4
        return $request->attributes->get('_route');
135 4
    }
136
}
137