Passed
Push — dev5 ( fbf860...67c7cf )
by Ron
28:05
created

GetFileLinkFiles::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 10
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 16
ccs 11
cts 11
cp 1
crap 2
rs 9.9332
1
<?php
2
3
namespace App\Domains\FileLinks;
4
5
use Illuminate\Support\Facades\Log;
6
7
use App\FileLinkFiles;
8
9
use App\Http\Resources\FileLinkFilesCollection;
10
11
class GetFileLinkFiles
12
{
13
    //  Execute will process an uploading file
14 4
    public function execute($linkID, $collection = false)
15
    {
16 4
        $files = FileLinkFiles::where('link_id', $linkID)
17 4
                    ->orderBy('user_id', 'ASC')
18 4
                    ->orderBy('created_at', 'ASC')
19 4
                    ->with('Files')
20 4
                    ->with('User')
21 4
                    ->get();
22
23 4
        Log::debug('Retrieved files attached to File Link ID '.$linkID.'.  Data Gathered - ', array($files));
24 4
        if($collection)
25
        {
26 2
            return new FileLinkFilesCollection($files);
27
        }
28
29 2
        return $files;
30
    }
31
32
    //  Only retrieve the files that the guest can download
33 8
    public function getGuestFiles($linkID)
34
    {
35 8
        $files = new FileLinkFilesCollection(
36 8
            FileLinkFiles::where('link_id', $linkID)
37 8
                ->where('upload', 0)
38 8
                ->orderBy('created_at', 'ASC')
39 8
                ->with('Files')
40 8
                ->get()
41
        );
42
43 8
        Log::debug('Retrieved guest files attached to File Link ID '.$linkID.'.  Data Gathered - ', array($files));
44 8
        return $files;
45
    }
46
}
47