Skip to content
Snippets Groups Projects
Commit e14e5e81 authored by Piotr Potrebka's avatar Piotr Potrebka
Browse files

feat: refactor

parent b537f22a
No related branches found
No related tags found
2 merge requests!5Devel,!4Refactor/templates
Pipeline #406284 passed with warnings with stages
in 33 seconds
......@@ -11,7 +11,7 @@ class ColorConversion {
*
* @return bool True if a light color.
*/
public static function is_hex_light( $color ) {
public static function is_hex_light( $color ): bool {
$hex = str_replace( '#', '', $color );
$c_r = hexdec( substr( $hex, 0, 2 ) );
......@@ -31,11 +31,11 @@ class ColorConversion {
/**
* Convert RGB to HEX.
*
* @param mixed $color Color.
* @param string $color Color.
*
* @return array
*/
public static function rgb_from_hex( $color ) {
public static function rgb_from_hex( string $color ): array {
$color = str_replace( '#', '', $color );
// Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF".
$color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
......@@ -52,17 +52,17 @@ class ColorConversion {
/**
* Make HEX color darker.
*
* @param mixed $color Color.
* @param string $color Color.
* @param int $factor Darker factor.
* Defaults to 30.
*
* @return string
*/
public static function hex_darker( $color, $factor = 30 ) {
public static function hex_darker( string $color, int $factor = 30 ): string {
$base = self::rgb_from_hex( $color );
$color = '#';
foreach ( $base as $k => $v ) {
foreach ( $base as $v ) {
$amount = $v / 100;
$amount = self::round( $amount * $factor );
$new_decimal = $v - $amount;
......@@ -81,17 +81,17 @@ class ColorConversion {
/**
* Make HEX color lighter.
*
* @param mixed $color Color.
* @param int $factor Lighter factor.
* @param string $color Color.
* @param int $factor Lighter factor.
* Defaults to 30.
*
* @return string
*/
public static function hex_lighter( $color, $factor = 30 ) {
public static function hex_lighter( string $color, int $factor = 30 ): string {
$base = self::rgb_from_hex( $color );
$color = '#';
foreach ( $base as $k => $v ) {
foreach ( $base as $v ) {
$amount = 255 - $v;
$amount = $amount / 100;
$amount = self::round( $amount * $factor );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment