Completed
Push — master ( 52ee14...16f440 )
by Manuel
11:23 queued 08:50
created

UpdateStatistics::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
ccs 11
cts 11
cp 1
rs 9.4285
cc 1
eloc 9
nc 1
nop 1
crap 1
1
<?php
2
3
namespace PiFinder\Handlers\Events;
4
5
use Carbon\Carbon;
6
use Illuminate\Support\Facades\DB;
7
use PiFinder\DeviceArchive;
8
use PiFinder\Events\ServerWasPoked;
9
use PiFinder\Poke;
10
use PiFinder\Utilities\ExtractNetwork;
11
12
class UpdateStatistics
13
{
14
    /**
15
     * Handle the event.
16
     *
17
     * @param ServerWasPoked $event
18
     *
19
     * @return void
20
     */
21 4
    public function handle(ServerWasPoked $event)
22
    {
23 4
        $device = $event->getDevice()->toArray();
24
25
        // device count
26 4
        DeviceArchive::updateOrCreate(
0 ignored issues
show
Bug introduced by
The method updateOrCreate() does not exist on PiFinder\DeviceArchive. Did you maybe mean create()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
27 4
            ['mac_hash' => md5($device['mac'])],
28 4
            ['updated_at' => Carbon::now()]
29 4
        );
30
31
        // network distribution
32 4
        $network = ExtractNetwork::fromIp($device['ip']);
33 4
        DB::table('network_distribution')->where('network', $network)->increment('pokes');
34
35
        // pokes
36 4
        $date = Carbon::now()->toDateString();
37 4
        Poke::firstOrCreate(['date' => $date])->increment('pokes');
0 ignored issues
show
Bug introduced by
The method firstOrCreate() does not exist on PiFinder\Poke. Did you maybe mean create()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
38 4
    }
39
}
40