From afdef1436ce4febe2e8eaa444ae1c0d84657c431 Mon Sep 17 00:00:00 2001 From: Peter Knut Date: Wed, 13 Nov 2024 13:01:32 +0100 Subject: [PATCH] Less_Functions: Fix "Implicit conversion from float to int" on PHP 8.1 warning This could happen when using the `hsv()` Less function. Closes https://github.com/wikimedia/less.php/issues/119. Bug: T383085 Change-Id: Icaeaff167a574f3d335d984c02c4bbe2cdb150f7 --- lib/Less/Functions.php | 2 +- test/Fixtures/less.php/css/T383085-float-precision.css | 3 +++ test/Fixtures/less.php/less/T383085-float-precision.less | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 test/Fixtures/less.php/css/T383085-float-precision.css create mode 100644 test/Fixtures/less.php/less/T383085-float-precision.less diff --git a/lib/Less/Functions.php b/lib/Less/Functions.php index b571392d..39903ed6 100644 --- a/lib/Less/Functions.php +++ b/lib/Less/Functions.php @@ -105,7 +105,7 @@ public function hsv( $h, $s, $v ) { * @param float $a */ public function hsva( $h, $s, $v, $a ) { - $h = ( ( self::_number( $h ) % 360 ) / 360 ) * 360; + $h = ( ( (int)self::_number( $h ) % 360 ) / 360 ) * 360; $s = self::_number( $s ); $v = self::_number( $v ); $a = self::_number( $a ); diff --git a/test/Fixtures/less.php/css/T383085-float-precision.css b/test/Fixtures/less.php/css/T383085-float-precision.css new file mode 100644 index 00000000..c2e7abbf --- /dev/null +++ b/test/Fixtures/less.php/css/T383085-float-precision.css @@ -0,0 +1,3 @@ +div { + color: #efffde; +} diff --git a/test/Fixtures/less.php/less/T383085-float-precision.less b/test/Fixtures/less.php/less/T383085-float-precision.less new file mode 100644 index 00000000..94fde137 --- /dev/null +++ b/test/Fixtures/less.php/less/T383085-float-precision.less @@ -0,0 +1,6 @@ +@a: #EEFFDE; +@b: hsv(hsvhue(@a), hsvsaturation(@a), hsvvalue(@a)); + +div { + color: @b; +}