Passed
Push — dev5a ( 8099d5...bf034e )
by Ron
07:35
created

GetCustomerEquipment   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 10
c 2
b 0
f 0
dl 0
loc 24
ccs 11
cts 11
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getEquipment() 0 9 1
A execute() 0 11 2
1
<?php
2
3
namespace App\Domains\Customers;
4
5
use App\Customers;
6
use App\CustomerSystems;
7
use Illuminate\Support\Facades\Auth;
8
use Illuminate\Support\Facades\Log;
9
10
11
class GetCustomerEquipment extends GetCustomerDetails
12
{
13 5
    public function execute($custID)
14
    {
15 5
        $equip = $this->getEquipment($custID);
16
17
        //  Get any equipment that is shared between sites
18 5
        if($parent = $this->getParentID($custID))
19
        {
20 2
            $equip = $equip->merge($this->getEquipment($parent, true));
21
        }
22
23 5
        return $equip;
24
    }
25
26 5
    protected function getEquipment($custID, $shared = false)
27
    {
28 5
        return CustomerSystems::where('cust_id', $custID)
29
            ->when($shared, function($q)
30
            {
31 2
                $q->where('shared', 1);
32 5
            })
33 5
            ->with('CustomerSystemData')
34 5
            ->get();
35
    }
36
}
37