Completed
Push — master ( 5cda60...2b6dac )
by Constantin
06:34
created

TaskProgressCalculator::setStartTime()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Copyright (c) 2017 Constantin Galbenu <[email protected]>
4
 */
5
6
namespace Gica\Cqrs\ReadModel\ReadModelRecreator;
7
8
9
class TaskProgressCalculator
10
{
11
    /**
12
     * @var int
13
     */
14
    private $totalSteps;
15
16
    /** @var float */
17
    private $startTime;
18
19
    private $step = 0;
20
21 1
    public function __construct(
22
        int $totalSteps
23
    )
24
    {
25 1
        $this->totalSteps = $totalSteps;
26
27 1
        $this->setStartTime(microtime(true));
28 1
    }
29
30 1
    public function setStartTime(float $startTime)
31
    {
32 1
        $this->startTime = $startTime;
33 1
    }
34
35 1
    public function increment()
36
    {
37 1
        $this->step++;
38 1
    }
39
40 1
    public function getTotalSteps(): int
41
    {
42 1
        return $this->totalSteps;
43
    }
44
45
    /**
46
     * @return int
47
     */
48 1
    public function getStep(): int
49
    {
50 1
        return $this->step;
51
    }
52
53 1
    public function calculateSpeed()
54
    {
55 1
        return $this->step / (microtime(true) - $this->startTime);
56
    }
57
58 1
    public function calculateEta()
59
    {
60 1
        return ($this->totalSteps - $this->step) / $this->calculateSpeed();
61
    }
62
}