Failed Conditions
Pull Request — 0.3 (#20)
by jean
03:05
created

StatsCollectorProcessNotifier::onStartProcess()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4

Importance

Changes 0
Metric Value
cc 4
nc 5
nop 2
dl 0
loc 18
ccs 12
cts 12
cp 1
crap 4
rs 9.6666
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 implements ProcessNotifierInterface
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