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

GetCustomerEquipment::getLocalEquipment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

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