/src/Aura/Filter/Rule/Min.php
PHP | 71 lines | 26 code | 4 blank | 41 comment | 3 complexity | 86f52563f9fd16db20ed805637bef8aa MD5 | raw file
Possible License(s): BSD-3-Clause
- <?php
- /**
- *
- * This file is part of the Aura project for PHP.
- *
- * @package Aura.Filter
- *
- * @license http://opensource.org/licenses/bsd-license.php BSD
- *
- */
- namespace Aura\Filter\Rule;
- use Aura\Filter\AbstractRule;
- /**
- *
- * Validates that a value is greater than or equal to a minimum.
- *
- * @package Aura.Filter
- *
- * @license http://opensource.org/licenses/bsd-license.php BSD
- *
- */
- class Min extends AbstractRule
- {
- /**
- *
- * Error message
- *
- * @var string
- */
- protected $message = 'FILTER_MIN';
- /**
- *
- * Validates that the value is greater than or equal to a minimum.
- *
- * @param mixed $min The minimum valid value.
- *
- * @return bool True if valid, false if not.
- *
- */
- protected function validate($min)
- {
- $value = $this->getValue();
- if (! is_scalar($value)) {
- return false;
- }
- return $value >= $min;
- }
- /**
- *
- * check whether the value is less than min, if so set to min
- *
- * @param int $min
- *
- * @return boolean
- */
- protected function sanitize($min)
- {
- $value = $this->getValue();
- if (! is_scalar($value)) {
- return false;
- }
- if ($value < $min) {
- $this->setValue($min);
- }
- return true;
- }
- }