src/Koldy/Validator.php
protected function validateMax($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
    {
        if (count($args) == 0) {
            throw new ValidatorConfigException('Validator \'max\' has to have defined maximum value');
        }

        $maxSize = $args[0] ?? null;

        if (!is_numeric($maxSize)) {
            throw new ValidatorConfigException('Validator \'max\' has non-numeric value');
        }

        $maxSize = (int)$maxSize;

        //$value = $this->getValue($parameter);

        if ($value === null) {
            return null;
        }

        if (is_array($value) && in_array('array', $rules)) {
            if (count($value) > $maxSize) {
                return Message::getMessage(Message::MAX_VALUE, [
                    'param' => $parameter,
                    'max' => $maxSize,
                    'value' => ''
                ]);
            }

            return null;
        }

        if (!is_scalar($value)) {
            return Message::getMessage(Message::PRIMITIVE, [
                'param' => $parameter
            ]);
        }

        $value = (string)$value;

        if ($value === '') {
            return null;
        }

        if (!is_numeric($value)) {
            return Message::getMessage(Message::NUMERIC, [
                'param' => $parameter,
                'value' => $value
            ]);
        }

        $value += 0;

        if ($value > $maxSize) {
            return Message::getMessage(Message::MAX_VALUE, [
                'param' => $parameter,
                'max' => $maxSize,
                'value' => $value
            ]);
        }

        return null;
    }
protected function validateMax($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
    {
        if (count($args) == 0) {
            throw new ValidatorConfigException('Validator \'max\' has to have defined maximum value');
        }

        $maxSize = $args[0] ?? null;

        if (!is_numeric($maxSize)) {
            throw new ValidatorConfigException('Validator \'max\' has non-numeric value');
        }

        $maxSize = (int)$maxSize;

        //$value = $this->getValue($parameter);

        if ($value === null) {
            return null;
        }

        if (is_array($value) && in_array('array', $rules)) {
            if (count($value) > $maxSize) {
                return Message::getMessage(Message::MAX_VALUE, [
                    'param' => $parameter,
                    'max' => $maxSize,
                    'value' => ''
                ]);
            }

            return null;
        }

        if (!is_scalar($value)) {
            return Message::getMessage(Message::PRIMITIVE, [
                'param' => $parameter
            ]);
        }

        $value = (string)$value;

        if ($value === '') {
            return null;
        }

        if (!is_numeric($value)) {
            return Message::getMessage(Message::NUMERIC, [
                'param' => $parameter,
                'value' => $value
            ]);
        }

        $value += 0;

        if ($value > $maxSize) {
            return Message::getMessage(Message::MAX_VALUE, [
                'param' => $parameter,
                'max' => $maxSize,
                'value' => $value
            ]);
        }

        return null;
    }
protected function validateMax ( $ value , string $ parameter , array $ args = [ ] , array $ rules = null , array $ context = null ) : ? string { if ( count ( $ args ) == 0 ) { throw new ValidatorConfigException ( 'Validator \'max\' has to have defined maximum value' ) ; } $ maxSize = $ args [ 0 ] ?? null ; if ( ! is_numeric ( $ maxSize ) ) { throw new ValidatorConfigException ( 'Validator \'max\' has non-numeric value' ) ; } $ maxSize = ( int ) $ maxSize ; //$value = $this->getValue($parameter); if ( $ value === null ) { return null ; } if ( is_array ( $ value ) && in_array ( 'array' , $ rules ) ) { if ( count ( $ value ) > $ maxSize ) { return Message :: getMessage ( Message :: MAX_VALUE , [ 'param' => $ parameter , 'max' => $ maxSize , 'value' => '' ] ) ; } return null ; } if ( ! is_scalar ( $ value ) ) { return Message :: getMessage ( Message :: PRIMITIVE , [ 'param' => $ parameter ] ) ; } $ value = ( string ) $ value ; if ( $ value === '' ) { return null ; } if ( ! is_numeric ( $ value ) ) { return Message :: getMessage ( Message :: NUMERIC , [ 'param' => $ parameter , 'value' => $ value ] ) ; } $ value += 0 ; if ( $ value > $ maxSize ) { return Message :: getMessage ( Message :: MAX_VALUE , [ 'param' => $ parameter , 'max' => $ maxSize , 'value' => $ value ] ) ; } return null ; }
Validate if value has the maximum value of

@param mixed $value
@param string $parameter
@param array $args
@param array $rules other rules
@param array|null $context

@return null|string
@throws ValidatorConfigException
@example 'param' => 'max:5' - will fail if value is not at least 5
Validate if value has the maximum value of