Completed
Push — master ( 824977...b4976e )
by ARCANEDEV
04:42
created

DevicesRatioComposer::getUnavailableCount()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 1
nop 1
crap 12
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 Carbon\Carbon;
7
use Illuminate\Contracts\View\View;
8
use Illuminate\Support\Collection;
9
10
/**
11
 * Class     DevicesRatioComposer
12
 *
13
 * @package  Arcanesoft\Tracker\ViewComposers\Dashboard
14
 * @author   ARCANEDEV <[email protected]>
15
 */
16
class DevicesRatioComposer extends AbstractViewComposer
17
{
18
    /* ------------------------------------------------------------------------------------------------
19
     |  Constants
20
     | ------------------------------------------------------------------------------------------------
21
     */
22
    const VIEW = 'tracker::foundation._composers.dashboard.devices-ratio-chart';
23
24
    /* ------------------------------------------------------------------------------------------------
25
     |  Main Functions
26
     | ------------------------------------------------------------------------------------------------
27
     */
28
    /**
29
     * Compose the view.
30
     *
31
     * @param  \Illuminate\Contracts\View\View  $view
32
     */
33
    public function compose(View $view)
34
    {
35
        /**
36
         * @var  \Carbon\Carbon                  $start
37
         * @var  \Carbon\Carbon                  $end
38
         * @var  \Illuminate\Support\Collection  $range
39
         */
40
        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...
41
42
        $view->with('devicesRatio',  $this->getDevicesFromSessions($start, $end));
43
    }
44
45
    /* ------------------------------------------------------------------------------------------------
46
     |  Other Functions
47
     | ------------------------------------------------------------------------------------------------
48
     */
49
    /**
50
     * Get the devices from sessions.
51
     *
52
     * @param  \Carbon\Carbon  $start
53
     * @param  \Carbon\Carbon  $end
54
     *
55
     * @return \Illuminate\Support\Collection
56
     */
57
    protected function getDevicesFromSessions(Carbon $start, Carbon $end)
58
    {
59
        return $this->getVisitorsFilteredByDateRange($start, $end)
60
            ->filter(function (Session $session) {
61
                return $session->hasDevice();
62
            })
63
            ->transform(function (Session $session) {
64
                return $session->device;
65
            })
66
            ->groupBy('kind')
67
            ->transform(function (Collection $items, $key) {
68
                return [
69
                    'kind'  => trans("tracker::devices.kinds.$key"),
70
                    'count' => $items->count(),
71
                ];
72
            });
73
    }
74
}
75