Passed
Push — master ( 823aee...b9b37f )
by Alec
13:15 queued 12s
created

ProgressStepsProcedure   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 27
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createSteps() 0 4 1
A update() 0 11 3
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AlecRabbit\Spinner\Extras\Procedure;
6
7
use AlecRabbit\Spinner\Contract\IFrame;
8
use AlecRabbit\Spinner\Core\Factory\FrameFactory;
9
use AlecRabbit\Spinner\Extras\Contract\IProgressValue;
10
use AlecRabbit\Spinner\Extras\Procedure\A\AProgressValueProcedure;
11
12
/** @psalm-suppress UnusedClass */
13
final class ProgressStepsProcedure extends AProgressValueProcedure
14
{
15
    private float $stepValue;
16
17
    public function __construct(IProgressValue $progressValue)
18
    {
19
        parent::__construct($progressValue);
20
        $this->stepValue = ($progressValue->getMax() - $progressValue->getMin()) / $progressValue->getSteps();
21
    }
22
23
    public function update(float $dt = null): IFrame
24
    {
25
        if ($this->progressValue->isFinished()) {
26
            if ($this->finishedDelay < 0) {
27
                return FrameFactory::createEmpty();
28
            }
29
            $this->finishedDelay -= $dt ?? 0.0;
30
        }
31
        $v = $this->createSteps($this->progressValue);
32
        return
33
            FrameFactory::create($v);
34
    }
35
36
    private function createSteps(IProgressValue $fractionValue): string
37
    {
38
        return
39
            sprintf('%s/%s', (int)($fractionValue->getValue() / $this->stepValue), $fractionValue->getSteps());
40
    }
41
}
42