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

KillFileLink::disableLink()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 1
rs 10
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