]> git.mxchange.org Git - friendica.git/blobdiff - view/theme/frio/php/PHPColors/Color.php
Merge pull request #4243 from MrPetovan/task/switch-to-array-new-style
[friendica.git] / view / theme / frio / php / PHPColors / Color.php
index e6937221a1c4723da15031224b99a088d55b60ac..3f290becf49d40baa10dac112fc0ebd2e15bae35 100644 (file)
@@ -9,7 +9,6 @@
 
 /**
  * A color utility that helps manipulate HEX colors
- * @todo convert space -> tab
  */
 class Color {
 
@@ -34,9 +33,9 @@ class Color {
         $color = str_replace("#", "", $hex);
 
         // Make sure it's 6 digits
-        if ( strlen($color) === 3 ) {
+        if( strlen($color) === 3 ) {
             $color = $color[0].$color[0].$color[1].$color[1].$color[2].$color[2];
-        } elseif ( strlen($color) != 6 ) {
+        } else if( strlen($color) != 6 ) {
             throw new Exception("HEX color needs to be 6 or 3 digits long");
         }
 
@@ -64,7 +63,7 @@ class Color {
         $G = hexdec($color[2].$color[3]);
         $B = hexdec($color[4].$color[5]);
 
-        $HSL = array();
+        $HSL = [];
 
         $var_R = ($R / 255);
         $var_G = ($G / 255);
@@ -111,21 +110,21 @@ class Color {
      * @return string HEX string
      * @throws Exception "Bad HSL Array"
      */
-    public static function hslToHex( $hsl = array() ){
+    public static function hslToHex( $hsl = [] ){
          // Make sure it's HSL
-        if (empty($hsl) || !isset($hsl["H"]) || !isset($hsl["S"]) || !isset($hsl["L"]) ) {
+        if(empty($hsl) || !isset($hsl["H"]) || !isset($hsl["S"]) || !isset($hsl["L"]) ) {
             throw new Exception("Param was not an HSL array");
         }
 
-        list($H,$S,$L) = array( $hsl['H']/360,$hsl['S'],$hsl['L'] );
+        list($H,$S,$L) = [ $hsl['H']/360,$hsl['S'],$hsl['L'] ];
 
-        if ( $S == 0 ) {
+        if( $S == 0 ) {
             $r = $L * 255;
             $g = $L * 255;
             $b = $L * 255;
         } else {
 
-            if ($L<0.5) {
+            if($L<0.5) {
                 $var_2 = $L*(1+$S);
             } else {
                 $var_2 = ($L+$S) - ($S*$L);
@@ -182,9 +181,9 @@ class Color {
      * @return string RGB string
      * @throws Exception "Bad RGB Array"
      */
-    public static function rgbToHex( $rgb = array() ){
+    public static function rgbToHex( $rgb = [] ){
          // Make sure it's RGB
-        if (empty($rgb) || !isset($rgb["R"]) || !isset($rgb["G"]) || !isset($rgb["B"]) ) {
+        if(empty($rgb) || !isset($rgb["R"]) || !isset($rgb["G"]) || !isset($rgb["B"]) ) {
             throw new Exception("Param was not an RGB array");
         }
 
@@ -245,7 +244,7 @@ class Color {
      */
     public function makeGradient( $amount = self::DEFAULT_ADJUST ) {
         // Decide which color needs to be made
-        if ( $this->isLight() ) {
+        if( $this->isLight() ) {
             $lightColor = $this->_hex;
             $darkColor = $this->darken($amount);
         } else {
@@ -254,7 +253,7 @@ class Color {
         }
 
         // Return our gradient array
-        return array( "light" => $lightColor, "dark" => $darkColor );
+        return [ "light" => $lightColor, "dark" => $darkColor ];
     }
 
 
@@ -309,7 +308,7 @@ class Color {
         // Return the new value in HEX
         return self::hslToHex($hsl);
     }
-    
+
     /**
      * Returns your color's HSL array
      */
@@ -328,7 +327,7 @@ class Color {
     public function getRgb() {
         return $this->_rgb;
     }
-    
+
     /**
      * Returns the cross browser CSS3 gradient
      * @param int $amount Optional: percentage amount to light/darken the gradient
@@ -388,7 +387,7 @@ class Color {
      */
     private function _darken( $hsl, $amount = self::DEFAULT_ADJUST){
         // Check if we were provided a number
-        if ( $amount ) {
+        if( $amount ) {
             $hsl['L'] = ($hsl['L'] * 100) - $amount;
             $hsl['L'] = ($hsl['L'] < 0) ? 0:$hsl['L']/100;
         } else {
@@ -407,7 +406,7 @@ class Color {
      */
     private function _lighten( $hsl, $amount = self::DEFAULT_ADJUST){
         // Check if we were provided a number
-        if ( $amount ) {
+        if( $amount ) {
             $hsl['L'] = ($hsl['L'] * 100) + $amount;
             $hsl['L'] = ($hsl['L'] > 100) ? 1:$hsl['L']/100;
         } else {
@@ -436,7 +435,7 @@ class Color {
          $gmix = (($rgb1['G'] * $r1) + ($rgb2['G'] * $r2)) / 2;
          $bmix = (($rgb1['B'] * $r1) + ($rgb2['B'] * $r2)) / 2;
 
-         return array('R' => $rmix, 'G' => $gmix, 'B' => $bmix);
+         return ['R' => $rmix, 'G' => $gmix, 'B' => $bmix];
      }
 
     /**
@@ -447,23 +446,23 @@ class Color {
      * @return int
      */
     private static function _huetorgb( $v1,$v2,$vH ) {
-        if ( $vH < 0 ) {
+        if( $vH < 0 ) {
             $vH += 1;
         }
 
-        if ( $vH > 1 ) {
+        if( $vH > 1 ) {
             $vH -= 1;
         }
 
-        if ( (6*$vH) < 1 ) {
+        if( (6*$vH) < 1 ) {
                return ($v1 + ($v2 - $v1) * 6 * $vH);
         }
 
-        if ( (2*$vH) < 1 ) {
+        if( (2*$vH) < 1 ) {
             return $v2;
         }
 
-        if ( (3*$vH) < 2 ) {
+        if( (3*$vH) < 2 ) {
             return ($v1 + ($v2-$v1) * ( (2/3)-$vH ) * 6);
         }
 
@@ -482,9 +481,9 @@ class Color {
         $color = str_replace("#", "", $hex);
 
         // Make sure it's 6 digits
-        if ( strlen($color) == 3 ) {
+        if( strlen($color) == 3 ) {
             $color = $color[0].$color[0].$color[1].$color[1].$color[2].$color[2];
-        } elseif ( strlen($color) != 6 ) {
+        } else if( strlen($color) != 6 ) {
             throw new Exception("HEX color needs to be 6 or 3 digits long");
         }