Conditions | 10 |
Paths | 13 |
Total Lines | 40 |
Lines | 3 |
Ratio | 7.5 % |
Tests | 0 |
CRAP Score | 110 |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
50 | public function onKernelException($event) |
||
51 | { |
||
52 | View Code Duplication | if (!$event instanceof GetResponseForExceptionEvent && !$event instanceof ExceptionEvent) { |
|
53 | throw new \InvalidArgumentException(\sprintf('Expected instance of type %s, %s given', \class_exists(ExceptionEvent::class) ? ExceptionEvent::class : GetResponseForExceptionEvent::class, \is_object($event) ? \get_class($event) : \gettype($event))); |
||
54 | } |
||
55 | |||
56 | $request = $event->getRequest(); |
||
57 | $exception = \method_exists($event, 'getThrowable') ? $event->getThrowable() : $event->getException(); |
||
58 | |||
59 | if ($exception instanceof HttpExceptionInterface) { |
||
60 | $uri = $request->getUri(); |
||
61 | |||
62 | if (count($this->excludes) > 0) { |
||
63 | $excludes = array_filter($this->excludes, function ($pattern) use ($uri) { |
||
64 | return preg_match($pattern, $uri); |
||
65 | }); |
||
66 | |||
67 | if (count($excludes) > 0) { |
||
68 | return; |
||
69 | } |
||
70 | } |
||
71 | |||
72 | $hash = md5( |
||
73 | $exception->getStatusCode().$uri.$request->headers->get('referer') |
||
74 | ); |
||
75 | |||
76 | if ($model = $this->em->getRepository(Exception::class)->findOneBy(['hash' => $hash])) { |
||
77 | $model->increaseEvents(); |
||
78 | $model->setResolved(false); |
||
79 | } else { |
||
80 | $model = new Exception(); |
||
81 | $model->setCode($exception->getStatusCode()); |
||
82 | $model->setUrl($uri); |
||
83 | $model->setUrlReferer($request->headers->get('referer')); |
||
84 | $model->setHash($hash); |
||
85 | } |
||
86 | $this->em->persist($model); |
||
87 | $this->em->flush(); |
||
88 | } |
||
89 | } |
||
90 | } |
||
91 |
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.