Completed
Push — 0.4 ( bc6dc3...283c8e )
by jean
9s
created

StatsCollectorProcessNotifier   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 71
ccs 36
cts 36
cp 1
rs 10
c 0
b 0
f 0
wmc 13

9 Methods

Rating   Name   Duplication   Size   Complexity  
A onExecutedProcess() 0 10 2
A setEnabled() 0 3 1
A onUpdateIterableProcess() 0 2 1
A getData() 0 3 1
A onStartIterableProcess() 0 3 1
A onStartProcess() 0 18 4
A onEndProcess() 0 2 1
A onSuccessLoop() 0 3 1
A onFailedLoop() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Darkilliant\ProcessBundle\ProcessNotifier;
6
7
use Darkilliant\ProcessBundle\State\ProcessState;
8
use Darkilliant\ProcessBundle\Step\StepInterface;
9
10
class StatsCollectorProcessNotifier extends AbstractProcessNotifier
11
{
12
    private $stats = [];
13
    private $resolvedStat = [];
0 ignored issues
show
introduced by
The private property $resolvedStat is not used, and could be removed.
Loading history...
14
    private $position = 0;
15
    private $enabled = false;
16
17 2
    public function onStartProcess(ProcessState $state, StepInterface $step)
18
    {
19 2
        if (!$this->enabled) {
20 1
            return;
21
        }
22
23 1
        if (!isset($this->stats[get_class($step)])) {
24 1
            $this->stats[get_class($step)] = [];
25
        }
26
27 1
        $this->stats[get_class($step)]['last_start'] = microtime(true) * 1000;
28 1
        if (!isset($this->stats[get_class($step)]['time'])) {
29 1
            $this->stats[get_class($step)]['time'] = [];
30 1
            $this->stats[get_class($step)]['real_time'] = [];
31 1
            $this->stats[get_class($step)]['position'] = ++$this->position;
32 1
            $this->stats[get_class($step)]['wait'] = [];
33
        } else {
34 1
            $this->stats[get_class($step)]['wait'][] = $this->stats[get_class($step)]['last_start'] - $this->stats[get_class($step)]['last_finish'];
35
        }
36 1
    }
37
38 1
    public function onStartIterableProcess(ProcessState $state, StepInterface $step)
39
    {
40 1
        return;
41
    }
42
43 1
    public function onUpdateIterableProcess(ProcessState $state, StepInterface $step)
44
    {
45 1
    }
46
47 1
    public function onEndProcess(ProcessState $state, StepInterface $step)
48
    {
49 1
    }
50
51 2
    public function onExecutedProcess(ProcessState $state, StepInterface $step)
52
    {
53 2
        if (!$this->enabled) {
54 1
            return;
55
        }
56
57 1
        $currentTime = (microtime(true) * 1000);
58 1
        $time = $currentTime - $this->stats[get_class($step)]['last_start'];
59 1
        $this->stats[get_class($step)]['time'][] = $time;
60 1
        $this->stats[get_class($step)]['last_finish'] = $currentTime;
61 1
    }
62
63 2
    public function setEnabled($enabled)
64
    {
65 2
        $this->enabled = $enabled;
66 2
    }
67
68 2
    public function getData()
69
    {
70 2
        return $this->stats;
71
    }
72
73 1
    public function onFailedLoop(ProcessState $state, StepInterface $step)
74
    {
75 1
        return;
76
    }
77
78 1
    public function onSuccessLoop(ProcessState $state, StepInterface $step)
79
    {
80 1
        return;
81
    }
82
}
83