summaryrefslogtreecommitdiffstats
path: root/src/axis/numeric.php
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/axis/numeric.php
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/axis/numeric.php')
-rw-r--r--src/axis/numeric.php38
1 files changed, 24 insertions, 14 deletions
diff --git a/src/axis/numeric.php b/src/axis/numeric.php
index bd4ae58..bb62ff1 100644
--- a/src/axis/numeric.php
+++ b/src/axis/numeric.php
@@ -19,10 +19,10 @@
* Minimum value of displayed scale on axis.
* @property float $max
* Maximum value of displayed scale on axis.
- * @property float $minValue
- * Minimum Value to display on this axis.
- * @property float $maxValue
- * Maximum value to display on this axis.
+ * @property-read float $minValue
+ * Minimum Value to display on this axis.
+ * @property-read float $maxValue
+ * Maximum value to display on this axis.
*
* @package Graph
*/
@@ -50,10 +50,10 @@ class ezcGraphChartElementNumericAxis extends ezcGraphChartElementAxis
*/
public function __construct( array $options = array() )
{
- $this->properties['min'] = false;
- $this->properties['max'] = false;
- $this->properties['minValue'] = false;
- $this->properties['maxValue'] = false;
+ $this->properties['min'] = null;
+ $this->properties['max'] = null;
+ $this->properties['minValue'] = null;
+ $this->properties['maxValue'] = null;
parent::__construct( $options );
}
@@ -75,9 +75,19 @@ class ezcGraphChartElementNumericAxis extends ezcGraphChartElementAxis
switch ( $propertyName )
{
case 'min':
+ if ( !is_numeric( $propertyValue ) )
+ {
+ throw new ezcBaseValueException( $propertyName, $propertyValue, 'float' );
+ }
+
$this->properties['min'] = (float) $propertyValue;
break;
case 'max':
+ if ( !is_numeric( $propertyValue ) )
+ {
+ throw new ezcBaseValueException( $propertyName, $propertyValue, 'float' );
+ }
+
$this->properties['max'] = (float) $propertyValue;
break;
default:
@@ -192,13 +202,13 @@ class ezcGraphChartElementNumericAxis extends ezcGraphChartElementAxis
{
foreach ( $values as $value )
{
- if ( $this->properties['minValue'] === false ||
+ if ( $this->properties['minValue'] === null ||
$value < $this->properties['minValue'] )
{
$this->properties['minValue'] = $value;
}
- if ( $this->properties['maxValue'] === false ||
+ if ( $this->properties['maxValue'] === null ||
$value > $this->properties['maxValue'] )
{
$this->properties['maxValue'] = $value;
@@ -230,12 +240,12 @@ class ezcGraphChartElementNumericAxis extends ezcGraphChartElementAxis
}
// Use custom minimum and maximum if available
- if ( $this->properties['min'] !== false )
+ if ( $this->properties['min'] !== null )
{
$this->properties['minValue'] = $this->properties['min'];
}
- if ( $this->properties['max'] !== false )
+ if ( $this->properties['max'] !== null )
{
$this->properties['maxValue'] = $this->properties['max'];
}
@@ -251,12 +261,12 @@ class ezcGraphChartElementNumericAxis extends ezcGraphChartElementAxis
$this->calculateMinorStep( $this->properties['minValue'], $this->properties['maxValue'] );
}
- if ( $this->properties['min'] === false )
+ if ( $this->properties['min'] === null )
{
$this->calculateMinimum( $this->properties['minValue'], $this->properties['maxValue'] );
}
- if ( $this->properties['max'] === false )
+ if ( $this->properties['max'] === null )
{
$this->calculateMaximum( $this->properties['minValue'], $this->properties['maxValue'] );
}
OpenPOWER on IntegriCloud