Passed
Push — master ( 1d6d9a...2a90e7 )
by Ron
02:47 queued 12s
created

GetCustomerEquipment::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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