Passed
Push — dev5 ( a24f56...eeca7a )
by Ron
08:23
created

GetCustomerEquipment   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 43
ccs 22
cts 22
cp 1
rs 10
wmc 5

4 Methods

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