Passed
Push — master ( 2a90e7...a622eb )
by Ron
02:27 queued 14s
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
7
use App\Customers;
8
use App\CustomerSystems;
9
10
class GetCustomerEquipment
11
{
12
    protected $custID;
13
14 6
    public function __construct($custID)
15
    {
16 6
        $this->custID = $custID;
17 6
    }
18
19
    //  Get all equipment types that are assigned to the customer
20 6
    public function execute()
21
    {
22 6
        $hasParent = Customers::findOrFail($this->custID)->parent_id;
23 4
        $localEquip = $this->getLocalEquipment();
24
25 4
        if($hasParent)
26
        {
27 2
            $parentEquip = $this->getParentEquipment($hasParent);
28 2
            return $localEquip->merge($parentEquip);
29
        }
30 2
        return $localEquip;
31
    }
32
33
    //  Retrieve any equipment attached to the customer
34 4
    protected function getLocalEquipment()
35
    {
36 4
        $equipList = CustomerSystems::where('cust_id', $this->custID)
37 4
                        ->with('CustomerSystemData')
38 4
                        ->get();
39
40 4
        Log::debug('Customer Equipment Query completed for customer ID '.$this->custID.'.  Results - ', array($equipList));
41 4
        return $equipList;
42
    }
43
44
    //  Retrieve any equipment attached to the parent customer
45 2
    protected function getParentEquipment($parentID)
46
    {
47 2
        $parentList = CustomerSystems::where('cust_id', $parentID)
48 2
                        ->with('CustomerSystemData')
49 2
                        ->get();
50
51 2
        Log::debug('Customer Parent Equipment Query completed for Customer ID '.$this->custID.'.  Results - ', array($parentList));
52 2
        return $parentList;
53
    }
54
}
55