GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

AddLinkToRequest::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
4
namespace Linkeys\UrlSigner\Middleware;
5
6
7
use Closure;
8
use Illuminate\Database\Eloquent\ModelNotFoundException;
9
use Linkeys\UrlSigner\Contracts\Models\Link;
10
use Linkeys\UrlSigner\Exceptions\LinkNotFoundException;
11
use Linkeys\UrlSigner\Support\LinkRepository\LinkRepository;
12
use Linkeys\UrlSigner\Support\UrlManipulator\UrlManipulator;
13
use Symfony\Component\HttpFoundation\Request;
14
15
class AddLinkToRequest
16
{
17
18
    /**
19
     * @var LinkRepository
20
     */
21
    private $linkRepository;
22
23 3
    public function __construct(LinkRepository $linkRepository)
24
    {
25
26 3
        $this->linkRepository = $linkRepository;
27 3
    }
28
29 2
    public function handle(Request $request, Closure $next)
30
    {
31
32
        try {
33 2
            $link = $this->link($request);
34 1
        } catch (ModelNotFoundException $e) {
35 1
            throw new LinkNotFoundException;
36
        }
37
38 1
        $request->attributes->add([\Linkeys\UrlSigner\Models\Link::class => $link]);
39
40 1
        return $next($request);
41
    }
42
43
    /**
44
     * Find the link from the request
45
     *
46
     * @param Request $request
47
     *
48
     * @throws ModelNotFoundException
49
     *
50
     * @return Link
51
     */
52 3
    public function link(Request $request)
53
    {
54 3
        $uuid = $request->get(config('links.query_key'));
55
56 3
        return $this->linkRepository->findByUuid($uuid);
57
58
    }
59
}