Passed
Push — dev5 ( c3531a...a24f56 )
by Ron
08:14
created

UserFavs::updateCustomerFav()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 14
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 25
ccs 14
cts 14
cp 1
crap 2
rs 9.7998
1
<?php
2
3
namespace App\Domains\Users;
4
5
use Illuminate\Support\Facades\Log;
6
use Illuminate\Support\Facades\Auth;
7
8
use App\TechTipFavs;
9
use App\CustomerFavs;
10
11
class UserFavs
12
{
13
    protected $userID;
14
15 4
    public function __construct($userID = null)
16
    {
17 4
        $this->userID = isset($userID) ? $userID : Auth::user()->user_id;
18 4
    }
19
20
    public function updateTechTipFav($tipID)
0 ignored issues
show
Unused Code introduced by
The parameter $tipID is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

20
    public function updateTechTipFav(/** @scrutinizer ignore-unused */ $tipID)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
21
    {
22
        //
23
    }
24
25 4
    public function updateCustomerFav($custID)
26
    {
27 4
        $favData = CustomerFavs::where('cust_id', $custID)->where('user_id', $this->userID)->first();
28
29 4
        if($favData)
30
        {
31 2
            Log::info('Customer Bookmark removed.  Detais', [
32 2
                'user_id' => $this->userID,
33 2
                'cust_id' => $custID,
34
            ]);
35 2
            $favData->delete();
36
        }
37
        else
38
        {
39 4
            CustomerFavs::create([
40 4
                'user_id' => $this->userID,
41 4
                'cust_id' => $custID,
42
            ]);
43 4
            Log::info('Customer Bookmark added.  Detais', [
44 4
                'user_id' => $this->userID,
45 4
                'cust_id' => $custID,
46
            ]);
47
        }
48
49 4
        return true;
50
    }
51
}
52