summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorwn_ <[email protected]>2021-11-01 20:37:53 +0000
committerwn_ <[email protected]>2021-11-01 21:10:27 +0000
commit3cc60a02192eaf0f81065a40d5d781b60f371d15 (patch)
tree8c8b9815660590bb06ebf703e7e2903591b56597 /include
parent9dac9c5a0db520697794c00d29424e617aca55bd (diff)
Address PHPStan warnings in 'include/colors.php'.
------ ------------------------------------------------------------------ Line include/colors.php ------ ------------------------------------------------------------------ 215 Variable $out might not be defined. 223 Parameter #3 $pad_string of function str_pad expects string, int given. 255 Variable $h might not be defined. 317 Variable $img might not be defined. ------ ------------------------------------------------------------------
Diffstat (limited to 'include')
-rw-r--r--include/colors.php44
1 files changed, 27 insertions, 17 deletions
diff --git a/include/colors.php b/include/colors.php
index 41158f96e..94bb82cd2 100644
--- a/include/colors.php
+++ b/include/colors.php
@@ -200,27 +200,31 @@ function _color_hue2rgb($m1, $m2, $h) {
### Convert a hex color into an RGB triplet.
function _color_unpack($hex, $normalize = false) {
+ $hex = strpos($hex, '#') !== 0 ? _resolve_htmlcolor($hex) : substr($hex, 1);
- if (strpos($hex, '#') !== 0)
- $hex = _resolve_htmlcolor($hex);
- else
- $hex = substr($hex, 1);
+ if (strlen($hex) == 4) {
+ $hex = $hex[1] . $hex[1] . $hex[2] . $hex[2] . $hex[3] . $hex[3];
+ }
- if (strlen($hex) == 4) {
- $hex = $hex[1] . $hex[1] . $hex[2] . $hex[2] . $hex[3] . $hex[3];
- }
- $c = hexdec($hex);
- for ($i = 16; $i >= 0; $i -= 8) {
- $out[] = (($c >> $i) & 0xFF) / ($normalize ? 255 : 1);
- } return $out;
+ $c = hexdec($hex);
+ $out = [];
+
+ for ($i = 16; $i >= 0; $i -= 8) {
+ $out[] = (($c >> $i) & 0xFF) / ($normalize ? 255 : 1);
+ }
+
+ return $out;
}
### Convert an RGB triplet to a hex color.
function _color_pack($rgb, $normalize = false) {
$out = 0;
- foreach ($rgb as $k => $v) {
- $out |= (($v * ($normalize ? 255 : 1)) << (16 - $k * 8));
- }return '#'. str_pad(dechex($out), 6, 0, STR_PAD_LEFT);
+
+ foreach ($rgb as $k => $v) {
+ $out |= (($v * ($normalize ? 255 : 1)) << (16 - $k * 8));
+ }
+
+ return '#'. str_pad(dechex($out), 6, '0', STR_PAD_LEFT);
}
function rgb2hsl($arr) {
@@ -248,9 +252,14 @@ function rgb2hsl($arr) {
$del_G = ((($var_Max - $var_G ) / 6 ) + ($del_Max / 2 ) ) / $del_Max;
$del_B = ((($var_Max - $var_B ) / 6 ) + ($del_Max / 2 ) ) / $del_Max;
- if ($var_R == $var_Max) $h = $del_B - $del_G;
- else if ($var_G == $var_Max) $h = (1 / 3 ) + $del_R - $del_B;
- else if ($var_B == $var_Max) $h = (2 / 3 ) + $del_G - $del_R;
+ if ($var_R == $var_Max) {
+ $h = $del_B - $del_G;
+ } else if ($var_G == $var_Max) {
+ $h = (1 / 3 ) + $del_R - $del_B;
+ } else {
+ // ($var_B == $var_Max)
+ $h = (2 / 3 ) + $del_G - $del_R;
+ }
if ($h < 0) $h++;
if ($h > 1) $h--;
@@ -292,6 +301,7 @@ function hsl2rgb($arr) {
$colors = array();
$size = @getimagesize($imageFile);
+ $img = null;
// to enable .ico support place floIcon.php into lib/
if (strtolower($size['mime']) == 'image/vnd.microsoft.icon') {