Passed
Push — dev5a ( 328ab1...cf3a23 )
by Ron
07:38
created

GetCustomerNotes::getOneNote()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Domains\Customers;
4
5
use App\CustomerNotes;
6
7
use Illuminate\Support\Facades\Log;
8
9
class GetCustomerNotes extends GetCustomerDetails
10
{
11
    //  Get all notes belonging to a customer or shared notes belonging to its parent
12 6
    public function execute($custID)
13
    {
14 6
        $notes = $this->getNotes($custID);
15
16 6
        if($parent = $this->getParentID($custID))
17
        {
18 2
            $notes = $notes->merge($this->getNotes($parent, true));
19
        }
20
21 6
        Log::debug('Customer Notes for Customer ID'.$custID.' gathered.  Data - ', $notes->toArray());
22 6
        return $notes;
23
    }
24
25
    //  Get the details of a single note
26
    public function getOneNote($noteID)
27
    {
28
        $note = CustomerNotes::findOrFail($noteID);
29
        Log::debug('Note ID '.$noteID.' pulled for Customer ID '.$note->cust_id.'.  Data - ', $note->toArray());
30
        return $note;
31
    }
32
33
    //  Get the notes for the specified customer
34 6
    protected function getNotes($custID, $shared = false)
35
    {
36 6
        return CustomerNotes::where('cust_id', $custID)
37
            ->when($shared, function($q)
38
            {
39 2
                $q->where('shared', 1);
40 6
            })
41 6
            ->orderBy('urgent', 'DESC')
42 6
            ->get();
43
    }
44
}
45