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

GetUserStats::checkForCustomerFav()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 2
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 2
rs 10
1
<?php
2
3
namespace App\Domains\Users;
4
5
use Illuminate\Support\Facades\Auth;
6
use Illuminate\Support\Facades\Log;
7
8
use Carbon\Carbon;
9
10
use App\FileLinks;
11
use App\TechTipFavs;
12
use App\CustomerFavs;
13
14
class GetUserStats
15
{
16
    protected $userID;
17
18 4
    public function __construct($userID = null)
19
    {
20 4
        $userID ? $this->userID = $userID : $this->userID = Auth::user()->user_id;
21 4
    }
22
23 2
    public function getUserCustomerFavs()
24
    {
25 2
        $custFavs    = CustomerFavs::where('user_id', $this->userID)
26
            ->with(array('Customers' => function($query){
27
                $query->select('cust_id', 'name');
28 2
            }))
29 2
            ->get();
30
31 2
        Log::debug('Retrieved Customer favorites for User ID'.$this->userID.'. Data - ', array($custFavs));
32 2
        return $custFavs;
33
    }
34
35 2
    public function checkForCustomerFav($custID)
36
    {
37 2
        $isFav = CustomerFavs::where('user_id', $this->userID)->where('cust_id', $custID)->first();
38
39 2
        return $isFav ? true : false;
40
    }
41
42 2
    public function getUserTechTipFavs()
43
    {
44 2
        $tipFavs     = TechTipFavs::where('user_id', $this->userID)
45
            ->with(array('TechTips' => function($query){
46
                $query->select('tip_id', 'subject');
47 2
            }))
48 2
            ->get();
49
50 2
        Log::debug('Retrieved Tech Tip favorites for User ID'.$this->userID.'. Data - ', array($tipFavs));
51 2
        return $tipFavs;
52
    }
53
54 2
    public function getUserActiveFileLinks()
55
    {
56 2
        $activeLinks = FileLinks::where('user_id', $this->userID)->where('expire', '>', Carbon::now())->count();
57
58 2
        Log::debug('Retrieved count of active File Links for User ID'.$this->userID.'. Data - '.$activeLinks.' found');
0 ignored issues
show
Bug introduced by
Are you sure $activeLinks of type Illuminate\Database\Eloquent\Builder|integer|mixed can be used in concatenation? ( Ignorable by Annotation )

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

58
        Log::debug('Retrieved count of active File Links for User ID'.$this->userID.'. Data - './** @scrutinizer ignore-type */ $activeLinks.' found');
Loading history...
59 2
        return $activeLinks;
60
    }
61
62 2
    public function getUserTotalLinks()
63
    {
64 2
        $totalLinks  = FileLinks::where('user_id', $this->userID)->count();
65
66 2
        Log::debug('Retrieved count of total File Links for User ID'.$this->userID.'. Data - '.$totalLinks.' found');
0 ignored issues
show
Bug introduced by
Are you sure $totalLinks of type Illuminate\Database\Eloquent\Builder|integer|mixed can be used in concatenation? ( Ignorable by Annotation )

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

66
        Log::debug('Retrieved count of total File Links for User ID'.$this->userID.'. Data - './** @scrutinizer ignore-type */ $totalLinks.' found');
Loading history...
67 2
        return $totalLinks;
68
    }
69
}
70