Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
14.29% |
1 / 7 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
| ScaleTransform | |
14.29% |
1 / 7 |
|
33.33% |
1 / 3 |
28.67 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toCss | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| trim | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Css\Value; |
| 6 | |
| 7 | final readonly class ScaleTransform extends TransformFunction |
| 8 | { |
| 9 | public function __construct( |
| 10 | public float $sx, |
| 11 | public float $sy, |
| 12 | public ?float $sz = null, |
| 13 | ) {} |
| 14 | |
| 15 | public function toCss(): string |
| 16 | { |
| 17 | if ($this->sz !== null) { |
| 18 | return sprintf('scale3d(%s, %s, %s)', self::trim($this->sx), self::trim($this->sy), self::trim($this->sz)); |
| 19 | } |
| 20 | if ($this->sx === $this->sy) { |
| 21 | return sprintf('scale(%s)', self::trim($this->sx)); |
| 22 | } |
| 23 | return sprintf('scale(%s, %s)', self::trim($this->sx), self::trim($this->sy)); |
| 24 | } |
| 25 | |
| 26 | private static function trim(float $v): string |
| 27 | { |
| 28 | return fmod($v, 1.0) === 0.0 ? (string) (int) $v : (string) $v; |
| 29 | } |
| 30 | } |