Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| CubicBezier | |
100.00% |
9 / 9 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toCss | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| trim | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Css\Value; |
| 6 | |
| 7 | /** |
| 8 | * `cubic-bezier(x1, y1, x2, y2)` per CSS Easing 1 ยง3.4. The four |
| 9 | * control points define an easing curve from (0, 0) to (1, 1) via |
| 10 | * intermediate handles (x1, y1) and (x2, y2). x coordinates must |
| 11 | * be in [0, 1]; y coordinates may overshoot for spring-like |
| 12 | * easings. |
| 13 | */ |
| 14 | final readonly class CubicBezier extends Value |
| 15 | { |
| 16 | public function __construct( |
| 17 | public float $x1, |
| 18 | public float $y1, |
| 19 | public float $x2, |
| 20 | public float $y2, |
| 21 | ) {} |
| 22 | |
| 23 | public function toCss(): string |
| 24 | { |
| 25 | return sprintf( |
| 26 | 'cubic-bezier(%s, %s, %s, %s)', |
| 27 | self::trim($this->x1), |
| 28 | self::trim($this->y1), |
| 29 | self::trim($this->x2), |
| 30 | self::trim($this->y2), |
| 31 | ); |
| 32 | } |
| 33 | |
| 34 | private static function trim(float $v): string |
| 35 | { |
| 36 | return fmod($v, 1.0) === 0.0 ? (string) (int) $v : (string) $v; |
| 37 | } |
| 38 | } |