Implement validation

@param mixed $value

@param array $arguments

@throws \Exception

@return integer|float $value
355351
public function validate($value, array $arguments = [])
    {
        $isNumeric = is_numeric($value);
        $min = Arr::get($arguments, 'min', false);
        $max = Arr::get($arguments, 'max', false);
        $float = Arr::get($arguments, 'float', false);
        $inArray = Arr::get($arguments, 'in_array', false);
        $filter = Arr::get($arguments, 'filter', false);

        if (!$isNumeric) {
            throw new Exception("O atributo '{$this->getAttribute()}' não é um número!");
        }

        if ($float) {
            $value = $value + 0;
            $value = (float)$value;
        } else {
            $value = (int)$value;
        }

        if ($min) {
            $min = $min + 0;
        } else {
            $min = false;
        }

        if ($max) {
            $max = $max + 0;
        } else {
            $max = false;
        }

        if ($min) {

            if ($value < $min) {
                throw new Exception("O atributo '{$this->getAttribute()}' deve ser maior ou igual a '{$min}'!");
            } elseif ($max && $value > $max) {
                throw new Exception("O atributo '{$this->getAttribute()}' deve ser menor ou igual a '{$max}'!");
            }
        }

        if ($inArray && !in_array($value, $inArray)) {
            throw new Exception("O atributo '{$this->getAttribute()}' não pertence ao conjunto de dados!");
        }

        if ($filter && $filter instanceof \Closure) {
            $value = $filter($value);
        } elseif ($filter) {
            $value = call_user_func($filter, $value);
        }

        return $value;
    }
376219
public function validate($value, $options)
	{
		$this->value = $value;
		$this->options = $options;
		$this->errors = [];

		return $this->checkIt();
	}
665890
public function validate($value) {
        if(filter_var($value, FILTER_VALIDATE_FLOAT, array('options' => array('decimal' => $this->decimal)))===false) {
            return new ValidationResult(false, 'Not a floating point value');
        }        
        return new ValidationResult(true);
    }
1226566
protected function _validate_int($value)
    {
        if (is_int($value)) {
            return $value;
        }

        return preg_match('#^[+-]?\d+$#', $value) ? (int)$value : null;
    }
186710
private function validateComparisonOperators($value) 
    {
        $operator = strtoupper(trim($value));
        $isValid = in_array($operator, $this->comparisonOperators);
        
        if($isValid === true) {
            return $operator;
        } 
        
        throw new \Exception("Comparison operator $value is not supported.");
    }
183740
public function validate($value)
    {
        // generic pattern match if it's numeric [float/int/double]
        if (!preg_match('/^\d{0,}[.,]?\d*$/', (string)$value)) return false;

        $this->value = $value;

        return true;
    }
1053639
function validate(string $value, \CharlotteDunois\Livia\Commands\Context $context, ?\CharlotteDunois\Livia\Arguments\Argument $arg = null) {
        if(\mb_strlen($value) === 0) {
            return false;
        }
        
        if($arg->min !== null && \mb_strlen($value) < $arg->min) {
            return 'Please enter something above or exactly '.$arg->min.' characters in length.';
        }
        
        if($arg->max !== null && \mb_strlen($value) > $arg->max) {
            return 'Please enter a number below or exactly '.$arg->max.' characters in length.';
        }
        
        return true;
    }
413699
public function setArgument($argument, $value)
    {
        Arr::set($this->arguments, $argument, $value);

        return $this;
    }
658942
public function validate($value, array $arguments = [])
    {
        $mimetype = Arr::get($arguments, 'mimetype', false);
        $extension = Arr::get($arguments, 'extension', false);
        $minSize = Arr::get($arguments, 'minSize', false);
        $maxSize = Arr::get($arguments, 'maxSize', false);
        $arrayFiles = Arr::get($arguments, 'arrayFiles', false);
        $filter = Arr::get($arguments, 'filter', false);

        if ($arrayFiles && is_array($value)) {
            $files = [];
            Arr::set($arguments, 'arrayFiles', false);
            foreach ($value as $file) {
                $files[] = $this->validate($file, $arguments);
            }

            return $files;

        } elseif (!$value instanceof SplFileInfo || !$value->isFile() || $value->getPath() == '') {
            throw new MbException("O atributo '{$this->getAttribute()}' deve ser um arquivo válido!");
        }

        if($value instanceof UploadedFile && !$value->isValid()){
            throw new MbException("O atributo '{$this->getAttribute()}' é inválido!");
        }

        $tamanho = $value->getSize() / 1024;

        if (is_string($mimetype)) {
            $mimetype = [$mimetype];
        }

        if (is_array($mimetype) && !in_array($value->getMimeType(), $mimetype)) {
            throw new MbException("O arquivo '{$this->getAttribute()}' tem um formato inválido!");
        }

        if (is_string($extension)) {
            $extension = [$extension];
        }

        if (is_array($extension) && !in_array($value->getExtension(), $extension)) {
            throw new MbException(
                "A extensão {$value->getExtension()} do arquivo '{$this->getAttribute()}' é inválida! Por favor utilizar uma das extensöes (" . implode(", ",
                    $extension) . ")."
            );
        }

        if (is_numeric($minSize) && $minSize > $tamanho) {
            throw new MbException("O arquivo '{$this->getAttribute()}' tem um tamanho menor que {$minSize}KB!");
        }

        if (is_numeric($maxSize) && $maxSize < $tamanho) {
            throw new MbException("O arquivo '{$this->getAttribute()}' tem um tamanho maior que {$maxSize}KB!");
        }

        if ($filter instanceof \Closure) {
            $value = $filter($value);
        } elseif ($filter) {
            $value = call_user_func($filter, $value);
        }

        return $value;
    }
65802
public function validate($value): void
    {
        if (in_array($value, $this->values)) {
            return;
        }

        throw new Exception\Invalid(
            $value,
            "Invalid value, expected one of " . implode(",", $this->valuesString())
        );
    }
890311
public function validate($value) {
        if(filter_var($value, FILTER_VALIDATE_INT)===false) {
            return new ValidationResult(false, 'Not a valid integer');
        }        
        return new ValidationResult(true);
    }
978851
protected function validateBool($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
    {
        //$value = $this->getValue($parameter);

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

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

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

        if (!is_bool($value) && $value !== 'true' && $value !== 'false') {
            return Message::getMessage(Message::BOOL, [
                'param' => $parameter
            ]);
        }

        return null;
    }
275493
function validate($value, $options = null) {
        global $CFG;
        if (is_array($value) && array_key_exists('text', $value)) {
            $value = $value['text'];
        }
        if (is_array($value)) {
            // nasty guess - there has to be something in the array, hopefully nobody invents arrays in arrays
            $value = implode('', $value);
        }
        $stripvalues = array(
            '#</?(?!img|canvas|hr).*?>#im', // all tags except img, canvas and hr
            '#(\xc2\xa0|\s|&nbsp;)#', // Any whitespaces actually.
        );
        if (!empty($CFG->strictformsrequired)) {
            $value = preg_replace($stripvalues, '', (string)$value);
        }
        if ((string)$value == '') {
            return false;
        }
        return true;
    }
492192
public function validateValue($value) {
        $validationResultSet = new ValidationResultSet();
        foreach($this->validators as $validator) {
            $validationResultSet->add($validator->validate($value));
        }
        return $validationResultSet;
    }
259770
protected function isValid($value)
    {
        if (is_null($value) || is_float($value) || is_int($value)) {
            return;
        }
        $this->addError('A valid float is expected.', 1514998717);
    }
936349
public function validate($value, $constraints = null, $groups = null)
    {
        return $this->validator->validate($value, $constraints, $groups);
    }
520064
private function validateLogicalOperator($value) 
    {
        $operator = strtoupper(trim($value));
        $isValid = in_array($operator, $this->logicalOperators);
        
        if($isValid === true) {
            return $operator;
        } 
        
        throw new \Exception("Logical operator $value is not supported.");
    }