Passed
Push — dev5a ( 915c64...c2cba2 )
by Ron
07:58
created

SetUserFavorites   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
dl 0
loc 38
ccs 22
cts 22
cp 1
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toggleCustomerFavorite() 0 17 2
A toggleTechTipFavorite() 0 17 2
1
<?php
2
3
namespace App\Domains\User;
4
5
use App\CustomerFavs;
6
use App\TechTipFavs;
7
use Illuminate\Support\Facades\Log;
8
9
class SetUserFavorites
10
{
11 6
    public function toggleCustomerFavorite($custID, $userID)
12
    {
13 6
        $favData = CustomerFavs::where('cust_id', $custID)->where('user_id', $userID)->first();
14
15 6
        if($favData)
16
        {
17 4
            Log::info('Customer Favorite Removed.  Data - ', ['user_id' => $userID, 'cust_id' => $custID]);
18 4
            $favData->delete();
19 4
            return false;
20
        }
21
22 4
        Log::info('Customer Favorite Added.  Data - ', ['user_id' => $userID, 'cust_id' => $custID]);
23 4
        CustomerFavs::create([
24 4
            'user_id' => $userID,
25 4
            'cust_id' => $custID,
26
        ]);
27 4
        return true;
28
    }
29
30 6
    public function toggleTechTipFavorite($tipID, $userID)
31
    {
32 6
        $favData = TechTipFavs::where('tip_id', $tipID)->where('user_id', $userID)->first();
33
34 6
        if($favData)
35
        {
36 4
            Log::info('Tech Tip Favorite Removed.  Data - ', ['user_id' => $userID, 'tip_id' => $tipID]);
37 4
            $favData->delete();
38 4
            return false;
39
        }
40
41 4
        Log::info('Tech Tip Favorite Added.  Data - ', ['user_id' => $userID, 'tip_id' => $tipID]);
42 4
        TechTipFavs::create([
43 4
            'user_id' => $userID,
44 4
            'tip_id' => $tipID,
45
        ]);
46 4
        return true;
47
    }
48
}
49