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

AFloatValueProcedure::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AlecRabbit\Spinner\Extras\Procedure\A;
6
7
use AlecRabbit\Spinner\Contract\IFloatValue;
8
use AlecRabbit\Spinner\Contract\IFrame;
9
use AlecRabbit\Spinner\Core\Frame;
10
use AlecRabbit\Spinner\Core\WidthDeterminer;
11
12
abstract class AFloatValueProcedure extends AProcedure
13
{
14
    /** @var string */
15
    protected const FORMAT = "%s";
16
    protected string $format;
17
18
    public function __construct(
19
        protected readonly IFloatValue $floatValue,
20
        string $format = null,
21
    ) {
22
        $this->format = $format ?? static::FORMAT;
23
    }
24
25
    public function update(float $dt = null): IFrame
26
    {
27
        $v = sprintf(
28
            $this->format,
29
            $this->floatValue->getValue()
30
        );
31
        return
32
            new Frame($v, WidthDeterminer::determine($v));
33
    }
34
}
35