Implement validation

@param mixed $value

@param array $arguments

@throws \Exception

@return boolean $value
160247
public function validate($value, array $arguments = [])
    {
        $int = Arr::get($arguments, 'int', false);
        $isBool = is_bool($value);

        if (!$isBool && !$int) {
            throw new Exception("O atributo '{$this->getAttribute()}' não é um booleano!");

        } elseif(!$isBool && $int){
            $value = is_numeric($value) && $value > 0;
        }

        return (bool) $value;
    }
19678
protected function validateValue($value, $definition)
    {
        try {
            return $definition->getValidator()->validate($value);
        } catch (\Exception $e) {
            throw new \Exception(sprintf('[%s] %s', $definition->getName(), $e->getMessage()));
        }
    }
1147946
public function validateValue($value)
    {
        if (!$value instanceof MoneyInterface) {
            throw new Exception\InvalidArgumentException(
                sprintf(
                    'Value of type "%s" is invalid for %s; must implement "%s"',
                    is_object($value) ? get_class($value) : gettype($value),
                    get_class($this),
                    MoneyInterface::class
                )
            );
        }
    }
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;
    }
87673
public function validate( $value, $predicate, $argument = NULL )
	{
		if( !method_exists( $this->validator, $predicate ) )
			throw new BadMethodCallException( 'Predicate "'.$predicate.'" is not defined.' );
		try
		{
			return $this->validator->$predicate( $value, $argument );
		}
		catch( InvalidArgumentException $e )
		{
			return false;
		}
		catch( Exception $e )
		{
			throw $e;
		}
	}
417528
protected function validateEndsWith($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
    {
        if (count($args) == 0) {
            throw new ValidatorConfigException("Validator 'endsWith' must have argument in validator list for parameter {$parameter}");
        }

        $endsWith = $args[0] ?? '';

        if (strlen($endsWith) == 0) {
            throw new ValidatorConfigException("Validator 'endsWith' have empty argument in validator list for parameter {$parameter}");
        }

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

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

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

        $value = trim((string)$value);

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

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

        return null;
    }
771190
public function isValid($value = null, array $options = []): bool
    {
        if (\count($options) > 0) {
            $this->setOptions($options);
        }
        $this->setValue($value);
        $this->errors = [];

        if (\strpos($this->value, '..') !== false || !\preg_match('/^(.+)@([^@]+)$/', $this->value, $matches)) {
            $this->setError(self::VALIDATOR_ERROR_EMAIL_INCORRECT_FORMAT);
            return false;
        }
        if (!\filter_var($this->value, FILTER_VALIDATE_EMAIL) !== false) {
            $this->setError(self::VALIDATOR_ERROR_EMAIL_INCORRECT_FORMAT);
            return false;
        }
        $host = $matches[2];
        if ($this->options['domain-check'] === true && @\gethostbyname($host) === $host) {
            $this->setError(self::VALIDATOR_ERROR_EMAIL_INVALID_DOMAIN);
            return false;
        }
        if ($this->options['mx-check'] === true) {
            return $this->mxCheck($host);
        }

        return true;
    }
687792
public function checkValue(&$value)
    {
        if (parent::checkValue($value) === true) {
            $value = trim($value);
            if (in_array($value,
                [
                    self::SELECTOR_ALL, self::SELECTOR_FIRST, self::SELECTOR_LEFT,
                    self::SELECTOR_RIGHT, self::SELECTOR_BLANK
                ])) {
                return true;
            } else {
                throw new \InvalidArgumentException("Invalid value '" . $value . "' for argument 'value'.");
            }
        }

        return false;
    }
413699
public function setArgument($argument, $value)
    {
        Arr::set($this->arguments, $argument, $value);

        return $this;
    }
786631
function validate(string $value, \CharlotteDunois\Livia\Commands\Context $context, ?\CharlotteDunois\Livia\Arguments\Argument $arg = null) {
        $prg = \preg_match('/(?:<@&)?(\d{15,})>?/', $value, $matches);
        if($prg === 1) {
            return $context->message->guild->roles->has($matches[1]);
        }
        
        $search = \mb_strtolower($value);
        
        $inexactRoles = $context->message->guild->roles->filter(function ($role) use ($search) {
            return (\mb_stripos($role->name, $search) !== false);
        });
        $inexactLength = $inexactRoles->count();
        
        if($inexactLength === 0) {
             return false;
        }
        if($inexactLength === 1) {
            return true;
        }
        
        $exactRoles = $context->message->guild->roles->filter(function ($role) use ($search) {
            return ($role->name === $search);
        });
        $exactLength = $exactRoles->count();
        
        if($exactLength === 1) {
            return true;
        }
        
        if($exactLength > 0) {
            $roles = $exactRoles;
        } else {
            $roles = $inexactRoles;
        }
        
        if($roles->count() >= 15) {
            return 'Multiple roles found. Please be more specific.';
        }
        
        return \CharlotteDunois\Livia\Utils\DataHelpers::disambiguation($roles, 'roles', null).\PHP_EOL;
    }
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.");
    }
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;
    }
840064
public function validate($value) {
        if(!filter_var($value, FILTER_VALIDATE_IP, $this->flags)) {
            return new ValidationResult(false, 'Not a valid ip address');
        }        
        return new ValidationResult(true);
    }
634523
public function validate($rule, $value)
    {
        $arguments = $this->buildArgumentArray($rule, $value);

        $method = $this->makeRuleMethod($rule);

        if ($this->userDefinedExists($method)) {
            $class = NameResolver::makeRulesFileName();

            return call_user_func_array([$class, $method], $arguments);
        } elseif (method_exists(Rules::class, $method)) {
            return call_user_func_array([Rules::class, $method], $arguments);
        }

        throw InvalidSettingsRule::ruleNotFound($rule, $method);
    }
1182870
public function checkType($value)
    {
        if (isset($this->name) && null !== $this->name) {
            $fn = 'is_'.$this->name;

            return $fn($value);
        }

        throw new \Exception('Invalid name or name not defined for primitive type.');
    }
984543
function validate(string $value, \CharlotteDunois\Livia\Commands\Context $context, ?\CharlotteDunois\Livia\Arguments\Argument $arg = null) {
        $groups = $this->client->registry->findGroups($value);
        if(\count($groups) === 1) {
            return true;
        }
        
        if(\count($groups) === 0) {
            return false;
        }
        
        return \CharlotteDunois\Livia\Utils\DataHelpers::disambiguation($groups, 'groups', 'name').\PHP_EOL;
    }
721765
protected function validateIs($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
    {
        if (count($args) == 0) {
            throw new ValidatorConfigException("Validator 'is' must have argument in validator list for parameter {$parameter}");
        }

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

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

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

        $value = trim((string)$value);

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

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

        return null;
    }