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

TaskProgressCalculator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 54
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A setStartTime() 0 4 1
A increment() 0 4 1
A getTotalSteps() 0 4 1
A getStep() 0 4 1
A calculateSpeed() 0 4 1
A calculateEta() 0 4 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
}