Passed
Push — dev5 ( 03a57e...c2dc0b )
by Ron
09:22
created

GetCustomerFiles   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
c 1
b 0
f 0
dl 0
loc 48
ccs 27
cts 27
cp 1
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getParentFiles() 0 11 1
A execute() 0 11 2
A getLocalFiles() 0 10 1
1
<?php
2
3
namespace App\Domains\Customers;
4
5
use Illuminate\Support\Facades\Log;
6
7
use App\Customers;
8
use App\CustomerFiles;
9
10
class GetCustomerFiles
11
{
12
    protected $custID;
13
14 4
    public function __construct($custID)
15
    {
16 4
        $this->custID = $custID;
17 4
    }
18
19
    //  Get all notes that are assigned to the customer
20 4
    public function execute()
21
    {
22 4
        $hasParent = Customers::findOrFail($this->custID)->parent_id;
23 4
        $files = $this->getLocalFiles();
24
25 4
        if($hasParent)
26
        {
27 2
            $parentFiles = $this->getParentFiles($hasParent);
28 2
            return $files->merge($parentFiles);
29
        }
30 2
        return $files;
31
    }
32
33
    //  Retrieve any notes attached to the customer
34 4
    protected function getLocalFiles()
35
    {
36 4
        $files = CustomerFiles::where('cust_id', $this->custID)
37 4
                    ->with('Files')
38 4
                    ->with('CustomerFileTypes')
39 4
                    ->with('User')
40 4
                    ->get();
41
42 4
        Log::debug('Customer Notes Query completed for customer ID '.$this->custID.'.  Results - ', array($files));
43 4
        return $files;
44
    }
45
46
    //  Retrieve any notes attached to the parent customer
47 2
    protected function getParentFiles($parentID)
48
    {
49 2
        $parentFiles = Customerfiles::where('cust_id', $parentID)
50 2
                            ->where('shared', 1)
51 2
                            ->with('Files')
52 2
                            ->with('CustomerFileTypes')
53 2
                            ->with('User')
54 2
                            ->get();
55
56 2
        Log::debug('Customer Parent Notes Query completed for Customer ID '.$this->custID.'.  Results - ', array($parentFiles));
57 2
        return $parentFiles;
58
    }
59
}
60