Completed
Push — master ( 3f7578...5307b5 )
by ARCANEDEV
04:28
created

getGuestVisitors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 2
crap 2
1
<?php namespace Arcanesoft\Tracker\ViewComposers\Dashboard;
2
3
use Arcanesoft\Tracker\Models\Session;
4
use Arcanesoft\Tracker\Support\DateRange;
5
use Arcanesoft\Tracker\ViewComposers\AbstractViewComposer;
6
use Illuminate\Contracts\View\View;
7
8
/**
9
 * Class     AuthenticatedVisitorsRatioComposer
10
 *
11
 * @package  Arcanesoft\Tracker\ViewComposers\Dashboard
12
 * @author   ARCANEDEV <[email protected]>
13
 */
14
class AuthenticatedVisitorsRatioComposer extends AbstractViewComposer
15
{
16
    /* ------------------------------------------------------------------------------------------------
17
     |  Constants
18
     | ------------------------------------------------------------------------------------------------
19
     */
20
    const VIEW = 'tracker::foundation._composers.dashboard.authenticated-visitors-ratio-chart';
21
22
    /* ------------------------------------------------------------------------------------------------
23
     |  Main Functions
24
     | ------------------------------------------------------------------------------------------------
25
     */
26
    /**
27
     * Compose the view.
28
     *
29
     * @param  \Illuminate\Contracts\View\View  $view
30
     */
31
    public function compose(View $view)
32
    {
33
        /**
34
         * @var  \Carbon\Carbon                  $start
35
         * @var  \Carbon\Carbon                  $end
36
         * @var  \Illuminate\Support\Collection  $range
37
         */
38
        extract(DateRange::getCurrentMonthDaysRange());
0 ignored issues
show
Bug introduced by
\Arcanesoft\Tracker\Supp...CurrentMonthDaysRange() cannot be passed to extract() as the parameter $var_array expects a reference.
Loading history...
39
40
        $view->with(
41
            'authenticatedVisitors',
42
            $this->getAuthenticatedVisitors($start, $end)
43
        );
44
45
        $view->with(
46
            'guestVisitors',
47
            $this->getGuestVisitors($start, $end)
48
        );
49
    }
50
51
    /* ------------------------------------------------------------------------------------------------
52
     |  Other Functions
53
     | ------------------------------------------------------------------------------------------------
54
     */
55
    /**
56
     * Get the authenticated visitors.
57
     *
58
     * @param  \Carbon\Carbon  $start
59
     * @param  \Carbon\Carbon  $end
60
     *
61
     * @return \Illuminate\Support\Collection
62
     */
63
    private function getAuthenticatedVisitors($start, $end)
64
    {
65
        return $this->getCachedVisitors()
66
            ->filter(function (Session $session) use ($start, $end) {
67
                return $session->updated_at->between($start, $end);
68
            })
69
            ->filter(function (Session $session) use ($start, $end) {
70
                return $session->hasUser();
71
            });
72
    }
73
74
    /**
75
     * Get the guest visitors.
76
     *
77
     * @param  \Carbon\Carbon  $start
78
     * @param  \Carbon\Carbon  $end
79
     *
80
     * @return \Illuminate\Support\Collection
81
     */
82
    private function getGuestVisitors($start, $end)
83
    {
84
        return $this->getCachedVisitors()
85
            ->filter(function (Session $session) use ($start, $end) {
86
                return $session->updated_at->between($start, $end);
87
            })
88
            ->filter(function (Session $session) use ($start, $end) {
89
                return ! $session->hasUser();
90
            });
91
    }
92
}
93