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

GetCustomerEquipment::execute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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