Test Failed
Push — dev5a ( 7155d2...8099d5 )
by Ron
07:36
created

SetUserFavorites::toggleCustomerFavorite()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 10
nc 2
nop 2
dl 0
loc 17
rs 9.9332
c 1
b 0
f 0
1
<?php
2
3
namespace App\Domains\User;
4
5
use App\CustomerFavs;
6
use Illuminate\Support\Facades\Auth;
7
use Illuminate\Support\Facades\Log;
8
9
10
class SetUserFavorites
11
{
12
    public function toggleCustomerFavorite($custID, $userID)
13
    {
14
        $favData = CustomerFavs::where('cust_id', $custID)->where('user_id', $userID)->first();
15
16
        if($favData)
17
        {
18
            Log::info('Customer Favorite Removed.  Data - ', ['user_id' => $userID, 'cust_id' => $custID]);
19
            $favData->delete();
20
            return false;
21
        }
22
23
        Log::info('Customer Favorite Addes.  Data - ', ['user_id' => $userID, 'cust_id' => $custID]);
24
        CustomerFavs::create([
25
            'user_id' => $userID,
26
            'cust_id' => $custID,
27
        ]);
28
        return true;
29
    }
30
}
31