public static function getValidColorHexValue($color, $throwException = true)
    {
        /*
         * Not a scalar value?
         * Nothing to do
         */
        if (!is_scalar($color)) {
            return false;
        }

        $color = Miscellaneous::replace($color, '/#/', '');
        $length = strlen($color);

        /*
         * Color is not 3 or 6 characters long?
         * Nothing to do
         */
        if (3 !== $length && 6 !== $length) {
            if ($throwException) {
                throw new IncorrectColorHexLengthException($color);
            }

            return false;
        }

        /*
         * Color is 3 characters long?
         * Let's make it 6 characters long
         */
        if (3 === $length) {
            $color = Miscellaneous::replace($color, '/(.)(.)(.)/', '$1$1$2$2$3$3');
        }

        $pattern = self::$patterns['color'];
        $match = (bool)preg_match($pattern, $color);

        /*
         * It's valid color
         * Nothing to do more
         */
        if ($match) {
            return strtolower($color);
        }

        if ($throwException) {
            throw new InvalidColorHexValueException($color);
        }

        return false;
    }