summaryrefslogtreecommitdiffstats
path: root/src/element
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/element
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/element')
-rw-r--r--src/element/axis.php45
-rw-r--r--src/element/legend.php51
-rw-r--r--src/element/text.php9
3 files changed, 90 insertions, 15 deletions
diff --git a/src/element/axis.php b/src/element/axis.php
index edcefb1..cdcd26c 100644
--- a/src/element/axis.php
+++ b/src/element/axis.php
@@ -110,7 +110,14 @@ abstract class ezcGraphChartElementAxis extends ezcGraphChartElement
$this->properties['nullPosition'] = (float) $propertyValue;
break;
case 'axisSpace':
- $this->properties['axisSpace'] = min( 1, max( 0, (float) $propertyValue ) );
+ if ( !is_numeric( $propertyValue ) ||
+ ( $propertyValue < 0 ) ||
+ ( $propertyValue > 1 ) )
+ {
+ throw new ezcBaseValueException( $propertyName, $propertyValue, '0 <= float <= 1' );
+ }
+
+ $this->properties['axisSpace'] = (float) $propertyValue;
break;
case 'majorGrid':
$this->properties['majorGrid'] = ezcGraphColor::create( $propertyValue );
@@ -119,17 +126,21 @@ abstract class ezcGraphChartElementAxis extends ezcGraphChartElement
$this->properties['minorGrid'] = ezcGraphColor::create( $propertyValue );
break;
case 'majorStep':
- if ( $propertyValue <= 0 )
+ if ( !is_numeric( $propertyValue ) ||
+ ( $propertyValue <= 0 ) )
{
- throw new ezcBaseValueException( 'majorStep', $propertyValue, 'float > 0' );
+ throw new ezcBaseValueException( $propertyName, $propertyValue, 'float > 0' );
}
+
$this->properties['majorStep'] = (float) $propertyValue;
break;
case 'minorStep':
- if ( $propertyValue <= 0 )
+ if ( !is_numeric( $propertyValue ) ||
+ ( $propertyValue <= 0 ) )
{
- throw new ezcBaseValueException( 'minorStep', $propertyValue, 'float > 0' );
+ throw new ezcBaseValueException( $propertyName, $propertyValue, 'float > 0' );
}
+
$this->properties['minorStep'] = (float) $propertyValue;
break;
case 'formatString':
@@ -139,13 +150,31 @@ abstract class ezcGraphChartElementAxis extends ezcGraphChartElement
$this->properties['label'] = (string) $propertyValue;
break;
case 'labelSize':
- $this->properties['labelSize'] = max( 6, (int) $propertyValue );
+ if ( !is_numeric( $propertyValue ) ||
+ ( $propertyValue <= 6 ) )
+ {
+ throw new ezcBaseValueException( $propertyName, $propertyValue, 'int >= 6' );
+ }
+
+ $this->properties['labelSize'] = (int) $propertyValue;
break;
case 'labelMargin':
- $this->properties['labelMargin'] = max( 0, (int) $propertyValue );
+ if ( !is_numeric( $propertyValue ) ||
+ ( $propertyValue <= 0 ) )
+ {
+ throw new ezcBaseValueException( $propertyName, $propertyValue, 'int >= 0' );
+ }
+
+ $this->properties['labelMargin'] = (int) $propertyValue;
break;
case 'maxArrowHeadSize':
- $this->properties['maxArrowHeadSize'] = max( 0, (int) $propertyValue );
+ if ( !is_numeric( $propertyValue ) ||
+ ( $propertyValue <= 0 ) )
+ {
+ throw new ezcBaseValueException( $propertyName, $propertyValue, 'int >= 0' );
+ }
+
+ $this->properties['maxArrowHeadSize'] = (int) $propertyValue;
break;
case 'axisLabelRenderer':
if ( $propertyValue instanceof ezcGraphAxisLabelRenderer )
diff --git a/src/element/legend.php b/src/element/legend.php
index d9953b5..95e9cae 100644
--- a/src/element/legend.php
+++ b/src/element/legend.php
@@ -80,22 +80,61 @@ class ezcGraphChartElementLegend extends ezcGraphChartElement
switch ( $propertyName )
{
case 'padding':
- $this->properties['padding'] = max( 0, (int) $propertyValue );
+ if ( !is_numeric( $propertyValue ) ||
+ ( $propertyValue < 0 ) )
+ {
+ throw new ezcBaseValueException( $propertyName, $propertyValue, 'int >= 0' );
+ }
+
+ $this->properties['padding'] = (int) $propertyValue;
break;
case 'symbolSize':
- $this->properties['symbolSize'] = max( 1, (int) $propertyValue );
+ if ( !is_numeric( $propertyValue ) ||
+ ( $propertyValue < 1 ) )
+ {
+ throw new ezcBaseValueException( $propertyName, $propertyValue, 'int >= 1' );
+ }
+
+ $this->properties['symbolSize'] = (int) $propertyValue;
break;
case 'landscapeSize':
- $this->properties['landscapeSize'] = max( 0, min( 1, (float) $propertyValue ) );
+ if ( !is_numeric( $propertyValue ) ||
+ ( $propertyValue < 0 ) ||
+ ( $propertyValue > 1 ) )
+ {
+ throw new ezcBaseValueException( $propertyName, $propertyValue, '0 <= int <= 1' );
+ }
+
+ $this->properties['landscapeSize'] = (float) $propertyValue;
break;
case 'portraitSize':
- $this->properties['portraitSize'] = max( 0, min( 1, (float) $propertyValue ) );
+ if ( !is_numeric( $propertyValue ) ||
+ ( $propertyValue < 0 ) ||
+ ( $propertyValue > 1 ) )
+ {
+ throw new ezcBaseValueException( $propertyName, $propertyValue, '0 <= int <= 1' );
+ }
+
+ $this->properties['portraitSize'] = (float) $propertyValue;
break;
case 'minimumSymbolSize':
- $this->properties['minimumSymbolSize'] = max( 0, min( 1, (float) $propertyValue ) );
+ if ( !is_numeric( $propertyValue ) ||
+ ( $propertyValue < 0 ) ||
+ ( $propertyValue > 1 ) )
+ {
+ throw new ezcBaseValueException( $propertyName, $propertyValue, '0 <= int <= 1' );
+ }
+
+ $this->properties['minimumSymbolSize'] = (float) $propertyValue;
break;
case 'spacing':
- $this->properties['spacing'] = max( 0, (int) $propertyValue );
+ if ( !is_numeric( $propertyValue ) ||
+ ( $propertyValue < 0 ) )
+ {
+ throw new ezcBaseValueException( $propertyName, $propertyValue, 'int >= 0' );
+ }
+
+ $this->properties['spacing'] = (int) $propertyValue;
break;
default:
parent::__set( $propertyName, $propertyValue );
diff --git a/src/element/text.php b/src/element/text.php
index 4792468..66b0b19 100644
--- a/src/element/text.php
+++ b/src/element/text.php
@@ -47,7 +47,14 @@ class ezcGraphChartElementText extends ezcGraphChartElement
switch ( $propertyName )
{
case 'maxHeight':
- $this->properties['maxHeight'] = min( 1, max( 0, (float) $propertyValue ) );
+ if ( !is_numeric( $propertyValue ) ||
+ ( $propertyValue < 0 ) ||
+ ( $propertyValue > 1 ) )
+ {
+ throw new ezcBaseValueException( $propertyName, $propertyValue, '0 <= float <= 1' );
+ }
+
+ $this->properties['maxHeight'] = (float) $propertyValue;
break;
default:
parent::__set( $propertyName, $propertyValue );
OpenPOWER on IntegriCloud