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

GetFileLinkFiles::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2.004

Importance

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