Passed
Push — master ( 1d6d9a...2a90e7 )
by Ron
02:47 queued 12s
created

GuestLinksController::show()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 27
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 16
c 0
b 0
f 0
nc 4
nop 1
dl 0
loc 27
ccs 17
cts 17
cp 1
crap 4
rs 9.7333
1
<?php
2
3
namespace App\Http\Controllers\FileLinks;
4
5
use App\Http\Controllers\Controller;
6
7
use Illuminate\Support\Facades\Log;
8
9
use App\Domains\FileLinks\GetFileLinkFiles;
10
use App\Domains\FileLinks\SaveFileLinkFile;
11
use App\Domains\FileLinks\GetFileLinkDetails;
12
13
use Illuminate\Http\Request;
14
use App\Http\Requests\AddFileLinkGuestFileRequest;
15
16
class GuestLinksController extends Controller
17
{
18
    //  Landing page if no link is sent
19 2
    public function index()
20
    {
21 2
        return view('links.guestIndex');
22
    }
23
24
    //  Show the link details for the user
25 12
    public function show($id)
26
    {
27 12
        $linkObj = new GetFileLinkDetails;
28 12
        $linkID = $linkObj->getLinkID($id);
29
30
        //  Determine which view should be returned to the guest
31 12
        if(!$linkID)
32
        {
33 2
            Log::warning('Visitor '.\Request::ip().' visited bad link Hash - '.$id);
34 2
            return view('links.guestBadLink');
35
        }
36 10
        else if($linkObj->isLinkExpired())
37
        {
38 2
            Log::warning('Visitor '.\Request::ip().' visited expired link Hash - '.$id);
39 2
            return view('links.guestExpiredLink');
40
        }
41 8
        else if($linkObj->isLinkDead())
42
        {
43 2
            Log::warning('Visitor '.\Request::ip().' visited a link that they cannot do anything with.  Hash - '.$id);
44 2
            return view('links.guestDeadLink');
45
        }
46
47 6
        return view('links.guestDetails', [
48 6
            'hash'         => $id,
49 6
            'instructions' => $linkObj->getLinkInstructions(),
50 6
            'hasFiles'     => $linkObj->hasGuestFiles(),
51 6
            'allowUp'      => $linkObj->canGuestUpload(),
52
        ]);
53
    }
54
55
    //  Get the guest available files for the link
56 6
    public function getFiles($id)
57
    {
58 6
        $linkID = (new GetFileLinkDetails)->getLinkID($id);
59 6
        return (new GetFileLinkFiles)->getGuestFiles($linkID);
60
    }
61
62
    //  Upload new file
63 6
    public function update(AddFileLinkGuestFileRequest $request, $id)
64
    {
65 6
        $request->linkID = (new GetFileLinkDetails)->getLinkID($id);
66
        //  Determine if a file is being uploaded still or not
67 6
        if((new SaveFileLinkFile)->execute($request, false))
68
        {
69 6
            return response()->json(['success' => true]);
70
        }
71
72
        return response()->json(['success' =>false]);
73
    }
74
75
76
    //  Notify the owner of the link that files were uploaded
77 2
    public function notify(Request $request, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

77
    public function notify(/** @scrutinizer ignore-unused */ Request $request, $id)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
78
    {
79 2
        $linkObj = new GetFileLinkDetails;
80 2
        $linkObj->getLinkID($id);
81 2
        $linkData = $linkObj->execute();
82
83 2
        (new SaveFileLinkFile)->notifyOwnerOfUpload($linkData->user_id, $linkData);
84 2
        return response()->json(['success' => true]);
85
    }
86
}
87