Passed
Push — master ( 1d6d9a...2a90e7 )
by Ron
02:47 queued 12s
created

UserFavs   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 54.84%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 31
c 1
b 0
f 0
dl 0
loc 61
ccs 17
cts 31
cp 0.5484
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 2
A updateTechTipFav() 0 25 2
A updateCustomerFav() 0 25 2
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)
21
    {
22
        $favData = TechTipFavs::where('tip_id', $tipID)->where('user_id', $this->userID)->first();
23
24
        if($favData)
25
        {
26
            Log::info('Tech Tip Bookmark removed.  Detais', [
27
                'user_id' => $this->userID,
28
                'tip_id' => $tipID,
29
            ]);
30
            $favData->delete();
31
        }
32
        else
33
        {
34
            TechTipFavs::create([
35
                'user_id' => $this->userID,
36
                'tip_id' => $tipID,
37
            ]);
38
            Log::info('Tech Tip Bookmark added.  Detais', [
39
                'user_id' => $this->userID,
40
                'tip_id' => $tipID,
41
            ]);
42
        }
43
44
        return true;
45
    }
46
47 4
    public function updateCustomerFav($custID)
48
    {
49 4
        $favData = CustomerFavs::where('cust_id', $custID)->where('user_id', $this->userID)->first();
50
51 4
        if($favData)
52
        {
53 2
            Log::info('Customer Bookmark removed.  Detais', [
54 2
                'user_id' => $this->userID,
55 2
                'cust_id' => $custID,
56
            ]);
57 2
            $favData->delete();
58
        }
59
        else
60
        {
61 4
            CustomerFavs::create([
62 4
                'user_id' => $this->userID,
63 4
                'cust_id' => $custID,
64
            ]);
65 4
            Log::info('Customer Bookmark added.  Detais', [
66 4
                'user_id' => $this->userID,
67 4
                'cust_id' => $custID,
68
            ]);
69
        }
70
71 4
        return true;
72
    }
73
}
74