Skip to content

Commit 9434700

Browse files
author
Mark Baker
committed
Simplify getRed, Green and Blue methods for colour styles
1 parent 245a1dc commit 9434700

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

Classes/PHPExcel/Style/Color.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,7 @@ private static function _getColourComponent($RGB,$offset,$hex=TRUE) {
263263
* @return string The red colour component
264264
*/
265265
public static function getRed($RGB,$hex=TRUE) {
266-
if (strlen($RGB) == 8) {
267-
return self::_getColourComponent($RGB, 2, $hex);
268-
} elseif (strlen($RGB) == 6) {
269-
return self::_getColourComponent($RGB, 0, $hex);
270-
}
266+
return self::_getColourComponent($RGB, strlen($RGB) - 6, $hex);
271267
}
272268

273269
/**
@@ -279,11 +275,7 @@ public static function getRed($RGB,$hex=TRUE) {
279275
* @return string The green colour component
280276
*/
281277
public static function getGreen($RGB,$hex=TRUE) {
282-
if (strlen($RGB) == 8) {
283-
return self::_getColourComponent($RGB, 4, $hex);
284-
} elseif (strlen($RGB) == 6) {
285-
return self::_getColourComponent($RGB, 2, $hex);
286-
}
278+
return self::_getColourComponent($RGB, strlen($RGB) - 4, $hex);
287279
}
288280

289281
/**
@@ -295,11 +287,7 @@ public static function getGreen($RGB,$hex=TRUE) {
295287
* @return string The blue colour component
296288
*/
297289
public static function getBlue($RGB,$hex=TRUE) {
298-
if (strlen($RGB) == 8) {
299-
return self::_getColourComponent($RGB, 6, $hex);
300-
} elseif (strlen($RGB) == 6) {
301-
return self::_getColourComponent($RGB, 4, $hex);
302-
}
290+
return self::_getColourComponent($RGB, strlen($RGB) - 2, $hex);
303291
}
304292

305293
/**

0 commit comments

Comments
 (0)