summaryrefslogtreecommitdiffstats
path: root/src/colors
diff options
context:
space:
mode:
authorKore Nordmann <github@kore-nordmann.de>2006-11-02 16:05:45 +0000
committerKore Nordmann <github@kore-nordmann.de>2006-11-02 16:05:45 +0000
commit5bdf51ead2a5e1dfb683c56df48e3d887e743472 (patch)
tree7e39889aca43eff30617df44f5bb567be94035f9 /src/colors
parent39d55ef60b9074920a1a3fc3d0c0f8d51f303760 (diff)
downloadzetacomponents-graph-5bdf51ead2a5e1dfb683c56df48e3d887e743472.zip
zetacomponents-graph-5bdf51ead2a5e1dfb683c56df48e3d887e743472.tar.gz
- Throw ezcBaseValueExceptions instead of typecasting
- Do range checks instead of converting numbers using min and max - Extended testcases to test for ezcBaseValueExceptions
Diffstat (limited to 'src/colors')
-rw-r--r--src/colors/color.php15
-rw-r--r--src/colors/radial_gradient.php21
2 files changed, 31 insertions, 5 deletions
diff --git a/src/colors/color.php b/src/colors/color.php
index 688621c..ef4c14e 100644
--- a/src/colors/color.php
+++ b/src/colors/color.php
@@ -65,7 +65,14 @@ class ezcGraphColor extends ezcBaseOptions
case 'green':
case 'blue':
case 'alpha':
- $this->properties[$propertyName] = max( 0, min( 255, (int) $propertyValue ) );
+ if ( !is_numeric( $propertyValue ) ||
+ ( $propertyValue < 0 ) ||
+ ( $propertyValue > 255 ) )
+ {
+ throw new ezcBaseValueException( $propertyName, $propertyValue, '0 <= int <= 255' );
+ }
+
+ $this->properties[$propertyName] = (int) $propertyValue;
break;
default:
throw new ezcBasePropertyNotFoundException( $propertyName );
@@ -250,9 +257,9 @@ class ezcGraphColor extends ezcBaseOptions
$color = clone $this;
$value = 1 - $value;
- $color->red = (int) round( $this->red * $value );
- $color->green = (int) round( $this->green * $value );
- $color->blue = (int) round( $this->blue * $value );
+ $color->red = min( 255, max( 0, (int) round( $this->red * $value ) ) );
+ $color->green = min( 255, max( 0, (int) round( $this->green * $value ) ) );
+ $color->blue = min( 255, max( 0, (int) round( $this->blue * $value ) ) );
return $color;
}
diff --git a/src/colors/radial_gradient.php b/src/colors/radial_gradient.php
index bbc28c2..f7157f9 100644
--- a/src/colors/radial_gradient.php
+++ b/src/colors/radial_gradient.php
@@ -77,13 +77,32 @@ class ezcGraphRadialGradient extends ezcGraphColor
}
break;
case 'width':
+ if ( !is_numeric( $propertyValue ) ||
+ ( $propertyValue <= 0 ) )
+ {
+ throw new ezcBaseValueException( $propertyName, $propertyValue, 'float > 0' );
+ }
+
$this->properties['width'] = (float) $propertyValue;
break;
case 'height':
+ if ( !is_numeric( $propertyValue ) ||
+ ( $propertyValue <= 0 ) )
+ {
+ throw new ezcBaseValueException( $propertyName, $propertyValue, 'float > 0' );
+ }
+
$this->properties['height'] = (float) $propertyValue;
break;
case 'offset':
- $this->properties['offset'] = min( 1., max( 0., (float) $propertyValue ) );
+ if ( !is_numeric( $propertyValue ) ||
+ ( $propertyValue < 0 ) ||
+ ( $propertyValue > 1 ) )
+ {
+ throw new ezcBaseValueException( $propertyName, $propertyValue, '0 <= float <= 1' );
+ }
+
+ $this->properties['offset'] = $propertyValue;
break;
case 'startColor':
$this->properties['startColor'] = ezcGraphColor::create( $propertyValue );
OpenPOWER on IntegriCloud