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

StatsCollectorProcessNotifier::onFailedLoop()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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