Passed
Push — dev5 ( 5844c4...03a57e )
by Ron
10:02
created

GetCustomerNotes   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 39
ccs 18
cts 18
cp 1
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 11 2
A getParentNotes() 0 6 1
A __construct() 0 3 1
A getLocalNotes() 0 6 1
1
<?php
2
3
namespace App\Domains\Customers;
4
5
use Illuminate\Support\Facades\Log;
6
7
use App\Customers;
8
use App\CustomerNotes;
9
10
class GetCustomerNotes
11
{
12
    protected $custID;
13
14 4
    public function __construct($custID)
15
    {
16 4
        $this->custID = $custID;
17 4
    }
18
19
    //  Get all notes that are assigned to the customer
20 4
    public function execute()
21
    {
22 4
        $hasParent = Customers::findOrFail($this->custID)->parent_id;
23 4
        $notes = $this->getLocalNotes();
24
25 4
        if($hasParent)
26
        {
27 2
            $parentNotes = $this->getParentNotes($hasParent);
28 2
            return $notes->merge($parentNotes);
29
        }
30 2
        return $notes;
31
    }
32
33
    //  Retrieve any notes attached to the customer
34 4
    protected function getLocalNotes()
35
    {
36 4
        $notes = CustomerNotes::where('cust_id', $this->custID)->orderBy('urgent', 'desc')->get();
37
38 4
        Log::debug('Customer Notes Query completed for customer ID '.$this->custID.'.  Results - ', array($notes));
39 4
        return $notes;
40
    }
41
42
    //  Retrieve any notes attached to the parent customer
43 2
    protected function getParentNotes($parentID)
44
    {
45 2
        $parentNotes = CustomerNotes::where('cust_id', $parentID)->where('shared', 1)->orderBy('urgent', 'desc')->get();
46
47 2
        Log::debug('Customer Parent Notes Query completed for Customer ID '.$this->custID.'.  Results - ', array($parentNotes));
48 2
        return $parentNotes;
49
    }
50
}
51