Completed
Pull Request — master (#17)
by ARCANEDEV
04:55
created

OnlineUsersCountComposer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 31
ccs 0
cts 9
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A compose() 0 13 2
1
<?php namespace Arcanesoft\Auth\ViewComposers\Dashboard;
2
3
use Arcanesoft\Auth\ViewComposers\ViewComposer;
4
use Carbon\Carbon;
5
use Illuminate\Contracts\View\View;
6
7
/**
8
 * Class     OnlineUsersCountComposer
9
 *
10
 * @package  Arcanesoft\Auth\ViewComposers\Dashboard
11
 * @author   ARCANEDEV <[email protected]>
12
 */
13
class OnlineUsersCountComposer extends ViewComposer
14
{
15
    /* ------------------------------------------------------------------------------------------------
16
     |  Constants
17
     | ------------------------------------------------------------------------------------------------
18
     */
19
    const VIEW = 'auth::foundation._composers.dashboard.online-users-count-box';
20
21
    /* ------------------------------------------------------------------------------------------------
22
     |  Main Functions
23
     | ------------------------------------------------------------------------------------------------
24
     */
25
    /**
26
     * Compose the view.
27
     *
28
     * @param  \Illuminate\Contracts\View\View  $view
29
     */
30
    public function compose(View $view)
31
    {
32
        $date = Carbon::now()->subMinutes(
33
            config('arcanesoft.auth.track-activity.minutes', 5)
34
        );
35
36
        $users = $this->getCachedUsers()->filter(function ($user) use ($date) {
37
            /** @var  \Arcanesoft\Auth\Models\User  $user */
38
            return ! is_null($user->last_activity) && $user->last_activity->gte($date);
39
        });
40
41
        $view->with('onlineUsersCount', $users->count());
42
    }
43
}
44