OperatingSystemRationComposer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
lcom 1
cbo 5
dl 0
loc 63
ccs 0
cts 17
cp 0
rs 10
c 2
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A compose() 0 11 1
A getOperatingSystemsCountFromSessions() 0 18 1
1
<?php namespace Arcanesoft\Tracker\ViewComposers\Dashboard;
2
3
use Arcanesoft\Tracker\Models\Visitor;
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     OperatingSystemRationComposer
12
 *
13
 * @package  Arcanesoft\Tracker\ViewComposers\Dashboard
14
 * @author   ARCANEDEV <[email protected]>
15
 */
16
class OperatingSystemRationComposer extends AbstractViewComposer
17
{
18
    /* -----------------------------------------------------------------
19
     |  Constants
20
     | -----------------------------------------------------------------
21
     */
22
23
    const VIEW = 'tracker::admin._composers.dashboard.os-ratio-chart';
24
25
    /* -----------------------------------------------------------------
26
     |  Main Methods
27
     | -----------------------------------------------------------------
28
     */
29
30
    /**
31
     * Compose the view.
32
     *
33
     * @param  \Illuminate\Contracts\View\View  $view
34
     */
35
    public function compose(View $view)
36
    {
37
        /**
38
         * @var  \Carbon\Carbon                  $start
39
         * @var  \Carbon\Carbon                  $end
40
         * @var  \Illuminate\Support\Collection  $range
41
         */
42
        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...
43
44
        $view->with('operatingSystemRatio', $this->getOperatingSystemsCountFromSessions($start, $end));
45
    }
46
47
    /* -----------------------------------------------------------------
48
     |  Other Methods
49
     | -----------------------------------------------------------------
50
     */
51
52
    /**
53
     * Get the operating systems count from sessions.
54
     *
55
     * @param  \Carbon\Carbon                  $start
56
     * @param  \Carbon\Carbon                  $end
57
     *
58
     * @return \Illuminate\Support\Collection
59
     */
60
    private function getOperatingSystemsCountFromSessions(Carbon $start, Carbon $end)
61
    {
62
        return $this->getVisitorsFilteredByDateRange($start, $end)
63
            ->filter(function (Visitor $visitor) {
64
                return $visitor->hasDevice();
65
            })
66
            ->transform(function (Visitor $visitor) {
67
                return $visitor->device;
68
            })
69
            ->groupBy('platform')
70
            ->transform(function (Collection $items, $platform) {
71
                return [
72
                    'platform' => $platform,
73
                    'count'    => $items->count(),
74
                ];
75
            })
76
            ->sortByDesc('count');
77
    }
78
}
79