Skip to content

Support float step sizes and enforce validation in the set_step method for Number field #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/Field/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,20 @@ class Number extends \Geniem\ACF\Field {
/**
* Set step size
*
* @param integer $step Step size.
* @param integer|float $step Step size.
* @return self
*/
public function set_step( int $step ) {
public function set_step( $step ) {
// Validate that the step is an integer or a float
if ( ! is_int( $step ) && ! is_float( $step ) ) {
throw new \Geniem\ACF\Exception( 'Geniem\ACF\Field\Number: set_step() only accepts integers or floats' );
}

// Ensure the step is positive
if ( $step <= 0 ) {
throw new \Geniem\ACF\Exception( 'Geniem\ACF\Field\Number: set_step() only accepts positive values' );
}

$this->step = $step;

return $this;
Expand All @@ -54,7 +64,7 @@ public function set_step( int $step ) {
/**
* Get step size
*
* @return integer
* @return integer|float
*/
public function get_step() {
return $this->step;
Expand Down