Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
50.00% covered (danger)
50.00%
2 / 4
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
Time
50.00% covered (danger)
50.00%
2 / 4
66.67% covered (warning)
66.67%
2 / 3
6.00
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toSeconds
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toCss
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Css\Value;
6
7/**
8 * CSS Values 4 §6.6 — a time value. Used by transitions /
9 * animations for durations and delays.
10 */
11final readonly class Time extends Value
12{
13    public function __construct(public float $value, public TimeUnit $unit) {}
14
15    public function toSeconds(): float
16    {
17        return $this->unit->toSeconds($this->value);
18    }
19
20    public function toCss(): string
21    {
22        $v = fmod($this->value, 1.0) === 0.0 ? (string) (int) $this->value : (string) $this->value;
23        return $v . $this->unit->value;
24    }
25}