Passed
Push — dev5 ( da16e0...6692a0 )
by Ron
08:20
created

GuestLinksController::show()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 29
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
eloc 17
c 0
b 0
f 0
nc 4
nop 1
dl 0
loc 29
ccs 18
cts 18
cp 1
crap 4
rs 9.7
1
<?php
2
3
namespace App\Http\Controllers\FileLinks;
4
5
use App\Http\Controllers\Controller;
6
use Illuminate\Support\Facades\Log;
7
use Illuminate\Support\Facades\Route;
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
        Log::debug('Route '.Route::currentRouteName().' visited by IP Address '.\Request::ip());
22 2
        return view('links.guestIndex');
23
    }
24
25
    //  Show the link details for the user
26 12
    public function show($id)
27
    {
28 12
        Log::debug('Route ' . Route::currentRouteName() . ' visited by IP Address ' . \Request::ip());
29
30 12
        $linkObj = new GetFileLinkDetails;
31 12
        $linkID = $linkObj->getLinkID($id);
32
33
        //  Determine which view should be returned to the guest
34 12
        if(!$linkID)
35
        {
36 2
            Log::warning('Visitor '.\Request::ip().' visited bad link Hash - '.$id);
37 2
            return view('links.guestBadLink');
38
        }
39 10
        else if($linkObj->isLinkExpired())
40
        {
41 2
            Log::warning('Visitor '.\Request::ip().' visited expired link Hash - '.$id);
42 2
            return view('links.guestExpiredLink');
43
        }
44 8
        else if($linkObj->isLinkDead())
45
        {
46 2
            Log::warning('Visitor '.\Request::ip().' visited a link that they cannot do anything with.  Hash - '.$id);
47 2
            return view('links.guestDeadLink');
48
        }
49
50 6
        return view('links.guestDetails', [
51 6
            'hash'         => $id,
52 6
            'instructions' => $linkObj->getLinkInstructions(),
53 6
            'hasFiles'     => $linkObj->hasGuestFiles(),
54 6
            'allowUp'      => $linkObj->canGuestUpload(),
55
        ]);
56
    }
57
58
    //  Get the guest available files for the link
59 6
    public function getFiles($id)
60
    {
61 6
        Log::debug('Route '.Route::currentRouteName().' visited by IP Address '.\Request::ip());
62
63 6
        $linkID = (new GetFileLinkDetails)->getLinkID($id);
64
65 6
        return (new GetFileLinkFiles)->getGuestFiles($linkID);
66
    }
67
68
    //  Upload new file
69 6
    public function update(AddFileLinkGuestFileRequest $request, $id)
70
    {
71 6
        Log::debug('Route '.Route::currentRouteName().' visited by IP Address '.\Request::ip().'. Submitted Data - ', $request->toArray());
72
73 6
        $request->linkID = (new GetFileLinkDetails)->getLinkID($id);
1 ignored issue
show
Bug introduced by
The property linkID does not seem to exist on App\Http\Requests\AddFileLinkGuestFileRequest.
Loading history...
74
        //  Determine if a file is being uploaded still or not
75 6
        if((new SaveFileLinkFile)->execute($request, false))
76
        {
77 6
            Log::info('A Guest has stored a file for file link ID - '.$request->linkID);
0 ignored issues
show
Bug introduced by
Are you sure $request->linkID of type false|mixed can be used in concatenation? ( Ignorable by Annotation )

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

77
            Log::info('A Guest has stored a file for file link ID - './** @scrutinizer ignore-type */ $request->linkID);
Loading history...
78 6
            return response()->json(['success' => true]);
79
        }
80
81
        return response()->json(['success' =>false]);
82
    }
83
84
85
    //  Notify the owner of the link that files were uploaded
86 2
    public function notify(Request $request, $id)
87
    {
88 2
        Log::debug('Route '.Route::currentRouteName().' visited by IP Address '.\Request::ip().'. Submitted Data - ', $request->toArray());
89
90 2
        $linkObj = new GetFileLinkDetails;
91 2
        $linkObj->getLinkID($id);
92 2
        $linkData = $linkObj->execute();
93
94 2
        (new SaveFileLinkFile)->notifyOwnerOfUpload($linkData->user_id, $linkData);
95
96 2
        return response()->json(['success' => true]);
97
    }
98
}
99