Passed
Push — dev5a ( e86993...328ab1 )
by Ron
10:15 queued 39s
created

getCustomerFiles::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 10
ccs 5
cts 5
cp 1
crap 2
rs 10
1
<?php
2
3
namespace App\Domains\Customers;
4
5
use Illuminate\Support\Facades\Auth;
6
use Illuminate\Support\Facades\Log;
7
use App\CustomerFiles;
8
9
10
class getCustomerFiles extends GetCustomerDetails
11
{
12 6
    public function execute($custID)
13
    {
14 6
        $files = $this->getAllFiles($custID);
15
16 6
        if($parent = $this->getParentID($custID))
17
        {
18 2
            $files = $files->merge($this->getAllFiles($parent, true));
19
        }
20
21 6
        return $files;
22
    }
23
24 6
    protected function getAllFiles($custID, $shared = false)
25
    {
26 6
        return CustomerFiles::where('cust_id', $custID)
27
            ->when($shared, function($q)
28
            {
29 2
                $q->where('shared', 1);
30 6
            })
31 6
            ->with('Files')
32 6
            ->with('CustomerFileTypes')
33 6
            ->with('User')
34 6
            ->get();
35
    }
36
}
37