Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
FontVariationValue
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toCss
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Css\Value;
6
7/**
8 * One `<axis-tag> <number>` entry inside a CSS Fonts 4 ยง6.5
9 * `font-variation-settings` declaration. The number is a float
10 * along the OpenType variation axis range (e.g. `"wght" 600.5`
11 * picks a weight halfway between named 600 and 700).
12 */
13final readonly class FontVariationValue
14{
15    public function __construct(
16        public string $tag,
17        public float $value,
18    ) {}
19
20    public function toCss(): string
21    {
22        $v = fmod($this->value, 1.0) === 0.0
23            ? (string) (int) $this->value
24            : (string) $this->value;
25        return sprintf('"%s" %s', $this->tag, $v);
26    }
27}