AtMost

AtMost - Value is at most equal to provided number.

AtMost only works with int and float, any other type is ignored.

Basic usage

use Jawira\Sanitizer\Filters as Sanitizer;

class Exam {
  #[Sanitizer\AtMost(number: 100)]
  public string $grade;
}

Parameters

int|float number (optional):
The property value will be compared against this number, if value is greater than provided number then this number will be used instead.
Default value is 0.

Examples

Value must be negative or zero.

use Jawira\Sanitizer\Filters as Sanitizer;

class Submarine {
  #[Sanitizer\AtMost]
  public int|float $depth;
}
50 → 0
36 → 0
10 → 0
-5 → -5
-500.45 → -500.45

Value cannot be greater than 20.

use Jawira\Sanitizer\Filters as Sanitizer;

class Building {
  #[Sanitizer\AtMost(number: 20)]
  public int $levels;
}
50 → 20
36 → 20
10 → 10
0 → 0
-2 → -2

See also

AtLeast - Value is at least equal to provided number.