Statistics   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 65.52%

Importance

Changes 5
Bugs 1 Features 2
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 59
ccs 19
cts 29
cp 0.6552
rs 10
c 5
b 1
f 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A totalPokes() 0 6 1
A totalDevices() 0 4 1
A allPokes() 0 4 1
A networkDistribution() 0 8 1
A addColors() 0 10 1
1
<?php
2
3
namespace PiFinder\Services;
4
5
use DB;
6
use PiFinder\Poke;
7
use PiFinder\DeviceArchive;
8
9
class Statistics
10
{
11
    /**
12
     * Returns the count of all pokes.
13
     *
14
     * @return mixed
15
     */
16 1
    public function totalPokes()
17
    {
18 1
        $base = 189771;
19
20 1
        return DB::table('network_distribution')->sum('pokes') + $base;
21
    }
22
23
    /**
24
     * Returns the the count of all devices.
25
     *
26
     * @return mixed
27
     */
28 1
    public function totalDevices()
29
    {
30 1
        return DeviceArchive::count();
31
    }
32
33
    /**
34
     * Returns all pokes.
35
     *
36
     * @return mixed
37
     */
38 1
    public function allPokes()
39
    {
40 1
        return Poke::all();
41
    }
42
43
    /**
44
     * Returns a collection of all networks and it's count.
45
     *
46
     * @return mixed
47
     */
48 1
    public function networkDistribution()
49
    {
50 1
        $data = DB::table('network_distribution')
51 1
            ->select('network as label', 'pokes as value')
52 1
            ->get();
53
54 1
        return $this->addColors($data);
55
    }
56
57 1
    private function addColors($data)
58
    {
59 1
        $colors = ['rgb(23,103,153)', 'rgb(47,135,176)', 'rgb(66,164,187)', 'rgb(91,192,196)'];
60 1
        $highlight_colors = ['#8BB3CC', '#97C3D7', '#ADDFE1', '#BBEAE3'];
61
62 1
        return $data->each(function ($network, $i) use ($colors, $highlight_colors) {
63 1
            $network->color = $colors[$i];
64 1
            $network->highlight = $highlight_colors[$i];
65 1
        });
66
    }
67
}
68