Passed
Push — dev5a ( c9bcfe...7155d2 )
by Ron
07:44
created

SetCustomerDetails::createCustomer()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 10
ccs 5
cts 5
cp 1
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace App\Domains\Customers;
4
5
use App\Customers;
6
use Illuminate\Support\Facades\Auth;
7
use Illuminate\Support\Facades\Log;
8
9
10
class SetCustomerDetails
11
{
12 6
    public function createCustomer($request)
13
    {
14 6
        if($request->parent_id != null)
15
        {
16 2
            $request->parent_id = $this->validateParentID($request->parent_id);
17
        }
18
19 6
        $newCust = Customers::create($request->toArray());
20
21 6
        return $newCust->cust_id;
22
    }
23
24
    //  Determine if the assigned parent has a partent of its own
25 2
    protected function validateParentID($parentID)
26
    {
27 2
        $parent = Customers::find($parentID);
28
29 2
        return $parent->parent_id ? $parent->parent_id : $parentID;
30
    }
31
}
32