LaravelScheduleLogger   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 0
cbo 0
dl 0
loc 62
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getExecutionTime() 0 4 1
A start() 0 4 1
A end() 0 4 1
A log() 0 16 2
1
<?php
2
3
namespace PendoNL\LaravelScheduleLogger;
4
5
class LaravelScheduleLogger
6
{
7
    /**
8
     * Log the start of an event.
9
     *
10
     * @param $command_name
11
     *
12
     * @return mixed
13
     */
14
    public function start($command_name)
15
    {
16
        return $this->log($command_name);
17
    }
18
19
    /**
20
     * Log the end of an event.
21
     *
22
     * @param $command_name
23
     *
24
     * @return mixed
25
     */
26
    public function end($command_name)
27
    {
28
        return $this->log($command_name);
29
    }
30
31
    /**
32
     * Save the event to the database.
33
     *
34
     * @param $command_name
35
     *
36
     * @return mixed
37
     */
38
    public function log($command_name)
39
    {
40
        $log = Schedulelog::where('end', null)->latest('id', 'DESC')->first();
41
42
        if (count($log) == 0) {
43
            return Schedulelog::create([
44
                'command_name' => $command_name,
45
                'start'        => microtime(true),
46
            ]);
47
        } else {
48
            $log->end = microtime(true);
49
            $log->save();
50
51
            return $log;
52
        }
53
    }
54
55
    /**
56
     * Returns the execution time in ms.
57
     *
58
     * @param Schedulelog $log
59
     *
60
     * @return mixed
61
     */
62
    public function getExecutionTime(Schedulelog $log)
63
    {
64
        return $log->end - $log->start;
65
    }
66
}
67