Passed
Push — dev5 ( 9ca56e...5adb95 )
by Ron
08:24
created

GetFileLinkFiles::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2.003

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 10
cts 11
cp 0.9091
crap 2.003
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 2
    public function execute($linkID, $collection = false)
15
    {
16 2
        $files = FileLinkFiles::where('link_id', $linkID)
17 2
                    ->orderBy('user_id', 'ASC')
18 2
                    ->orderBy('created_at', 'ASC')
19 2
                    ->with('Files')
20 2
                    ->with('User')
21 2
                    ->get();
22
23 2
        Log::debug('Retrieved files attached to File Link ID '.$linkID.'.  Data Gathered - ', array($files));
24 2
        if($collection)
25
        {
26 2
            return new FileLinkFilesCollection($files);
27
        }
28
29
        return $files;
30
    }
31
32
    //  Only retrieve the files that the guest can download
33 6
    public function getGuestFiles($linkID)
34
    {
35 6
        $files = new FileLinkFilesCollection(
36 6
            FileLinkFiles::where('link_id', $linkID)
37 6
                ->where('upload', 0)
38 6
                ->orderBy('created_at', 'ASC')
39 6
                ->with('Files')
40 6
                ->get()
41
        );
42
43 6
        Log::debug('Retrieved guest files attached to File Link ID '.$linkID.'.  Data Gathered - ', array($files));
44 6
        return $files;
45
    }
46
}
47