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

KillFileLink   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 81.25%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 38
ccs 13
cts 16
cp 0.8125
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A removeLinkFiles() 0 12 3
A deleteFileLink() 0 8 1
A disableLink() 0 7 1
1
<?php
2
3
namespace App\Domains\FileLinks;
4
5
use Carbon\Carbon;
6
7
use App\FileLinks;
8
use App\FileLinkFiles;
9
10
use App\Domains\FilesDomain;
11
12
class KillFileLink extends FilesDomain
13
{
14
    protected $linkID;
15
16
    //  Only disable the link by adjusting the expire date
17 2
    public function disableLink($linkID)
18
    {
19 2
        FileLinks::findOrFail($linkID)->update([
20 2
            'expire' => Carbon::yesterday()
21
        ]);
22
23 2
        return true;
24
    }
25
26
    //  Delete the file link and all attached files
27 2
    public function deleteFileLink($linkID)
28
    {
29 2
        $linkData = FileLinks::findOrFail($linkID);
30
31 2
        $this->removeLinkFiles();
32 2
        $linkData->delete();
33
34 2
        return true;
35
    }
36
37
    //  Remove all of the files attached to the link
38 2
    protected function removeLinkFiles()
39
    {
40 2
        $fileList = FileLinkFiles::where('link_id', $this->linkID);
41
42 2
        if($fileList)
0 ignored issues
show
introduced by
$fileList is of type Illuminate\Database\Eloquent\Builder, thus it always evaluated to true.
Loading history...
43
        {
44 2
            foreach($fileList as $file)
45
            {
46
                $fileID = $file->file_id;
47
                $file->delete();
48
49
                $this->deleteFile($fileID);
50
            }
51
        }
52 2
    }
53
}
54