Passed
Branch dev5a (8099d5)
by Ron
07:27
created

GetUserStats   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 49
ccs 21
cts 21
cp 1
rs 10
c 1
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getUserCustomerFavs() 0 6 1
A checkCustomerForFav() 0 3 1
A getUserTipFavs() 0 6 1
A getUserTotalLinks() 0 6 1
A getUserActiveLinks() 0 6 1
1
<?php
2
3
namespace App\Domains\User;
4
5
use Illuminate\Support\Facades\Log;
6
7
use Carbon\Carbon;
8
9
use App\FileLInks;
10
use App\TechTipFavs;
11
use App\CustomerFavs;
12
13
class GetUserStats
14
{
15
    protected $userID;
16
17 16
    public function __construct($userID)
18
    {
19 16
        $this->userID = $userID;
20 16
    }
21
22
    //  Get all Customer Favorites assigned to the user
23 4
    public function getUserCustomerFavs()
24
    {
25 4
        $favs = CustomerFavs::where('user_id', $this->userID)->get();
26 4
        Log::debug('Customer Favorites for User ID '.$this->userID.' gathered.  Data - ', $favs->toArray());
27
28 4
        return $favs->makeHidden('Customers');
29
    }
30
31
    //  Check if a customer is listed as a favorite for the user
32 6
    public function checkCustomerForFav($custID)
33
    {
34 6
        return CustomerFavs::where('user_id', $this->userID)->where('cust_id', $custID)->first();
35
    }
36
37
    //  Get all Tech Tip Favorites assigned to the user
38 4
    public function getUserTipFavs()
39
    {
40 4
        $favs = TechTipFavs::where('user_id', $this->userID)->get();
41 4
        Log::debug('Tech Tip Favorites for User ID '.$this->userID.' gathered.  Data - ', $favs->toArray());
42
43 4
        return $favs->makeHidden('TechTips');
44
    }
45
46
    //  Get a count of acctive file links the user has
47 4
    public function getUserActiveLinks()
48
    {
49 4
        $activeLinks = FileLinks::where('user_id', $this->userID)->where('expire', '>', Carbon::now())->count();
50 4
        Log::debug('Retrieved count of active File Links for User ID'.$this->userID.'. Data - ', ['Active Links' => $activeLinks]);
51
52 4
        return $activeLinks;
53
    }
54
55
    //  Get the total count of file links the user has
56 4
    public function getUserTotalLinks()
57
    {
58 4
        $totalLinks  = FileLinks::where('user_id', $this->userID)->count();
59 4
        Log::debug('Retrieved count of total File Links for User ID'.$this->userID.'. Data - ', ['Total Links' => $totalLinks]);
60
61 4
        return $totalLinks;
62
    }
63
}
64