VerifySignature   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 27
rs 10
c 1
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 18 3
1
<?php
2
3
namespace Meema\MediaConverter\Http\Middleware;
4
5
use Aws\Sns\Message;
6
use Aws\Sns\MessageValidator;
7
use Closure;
8
use Illuminate\Http\Request;
9
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
10
11
class VerifySignature
12
{
13
    /**
14
     * Handle an incoming request.
15
     *
16
     * @param  Request  $request
17
     * @param  \Closure  $next
18
     * @return mixed
19
     */
20
    public function handle(Request $request, Closure $next)
21
    {
22
        try {
23
            // Create a message from the post data and validate its signature
24
            $message = Message::fromRawPostData();
25
26
            // Validate the message
27
            $validator = new MessageValidator();
28
29
            if ($validator->isValid($message)) {
30
                return $next($request);
31
            }
32
        } catch (\Exception $e) {
33
            throw new NotFoundHttpException($e->getMessage());
34
        }
35
36
        // If you get this far it means the request is not found
37
        throw new NotFoundHttpException();
38
    }
39
}
40