diff --git a/src/validator-docs/Validator.php b/src/validator-docs/Validator.php index fc40b4e..ee9c6d9 100644 --- a/src/validator-docs/Validator.php +++ b/src/validator-docs/Validator.php @@ -4,6 +4,13 @@ use Illuminate\Validation\Validator as BaseValidator; +use function preg_match; +use function preg_replace; +use function strlen; +use function str_repeat; +use function sprintf; +use function substr; + /** * * @author Daniel Rodrigues Lima @@ -11,57 +18,26 @@ */ class Validator extends BaseValidator { - /** - * Valida o formato do cpf - * @param string $attribute - * @param string $value - * @return boolean - */ protected function validateFormatoCpf($attribute, $value) { return preg_match('/^\d{3}\.\d{3}\.\d{3}-\d{2}$/', $value) > 0; } - /** - * Valida o formato do cnpj - * @param string $attribute - * @param string $value - * @return boolean - */ protected function validateFormatoCnpj($attribute, $value) { return preg_match('/^\d{2}\.\d{3}\.\d{3}\/\d{4}-\d{2}$/', $value) > 0; } - /** - * Valida o formato do cpf ou cnpj - * @param string $attribute - * @param string $value - * @return boolean - */ protected function validateFormatoCpfCnpj($attribute, $value) { return $this->validateFormatoCpf($attribute, $value) || $this->validateFormatoCnpj($attribute, $value); } - /** - * Valida o formato do PIS/PASEP/NIS/NIT - * @param string $attribute - * @param string $value - * @return boolean - */ protected function validateFormatoNis($attribute, $value) { return preg_match('/^\d{3}\.\d{5}\.\d{2}-\d{1}$/', $value) > 0; } - /** - * Valida CPF - * @param string $attribute - * @param string $value - * @return boolean - */ - protected function validateCpf($attribute, $value) { $c = preg_replace('/\D/', '', $value); @@ -85,12 +61,6 @@ protected function validateCpf($attribute, $value) return true; } - /** - * Valida CNPJ - * @param string $attribute - * @param string $value - * @return boolean - */ protected function validateCnpj($attribute, $value) { $c = preg_replace('/\D/', '', $value); @@ -116,28 +86,16 @@ protected function validateCnpj($attribute, $value) return true; } - /** - * Valida CNPJ ou CPF - * @param string $attribute - * @param string $value - * @return boolean - */ protected function validateCpfCnpj($attribute, $value) { return ($this->validateCpf($attribute, $value) || $this->validateCnpj($attribute, $value)); } /** - * Valida CNH - * @param string $attribute - * @param string $value - * @return boolean + * Trecho retirado do respect validation */ - protected function validateCnh($attribute, $value) { - // Trecho retirado do respect validation - $ret = false; if ((strlen($input = preg_replace('/[^\d]/', '', $value)) == 11) @@ -146,22 +104,16 @@ protected function validateCnh($attribute, $value) $dsc = 0; for ($i = 0, $j = 9, $v = 0; $i < 9; ++$i, --$j) { - - $v += (int)$input[$i] * $j; - + $v += (int) $input[$i] * $j; } if (($vl1 = $v % 11) >= 10) { - $vl1 = 0; $dsc = 2; - } for ($i = 0, $j = 1, $v = 0; $i < 9; ++$i, ++$j) { - - $v += (int)$input[$i] * $j; - + $v += (int) $input[$i] * $j; } $vl2 = ($x = ($v % 11)) >= 10 ? 0 : $x - $dsc; @@ -172,16 +124,8 @@ protected function validateCnh($attribute, $value) return $ret; } - /** - * Valida Titulo de Eleitor - * @param string $attribute - * @param string $value - * @return boolean - */ - protected function validateTituloEleitor($attribute, $value) { - $input = preg_replace('/[^\d]/', '', $value); $uf = substr($input, -4, 2); @@ -226,7 +170,6 @@ protected function validateTituloEleitor($attribute, $value) switch ($i) { case '0': $sequencia = $uf . $digito; - break; } } @@ -234,13 +177,6 @@ protected function validateTituloEleitor($attribute, $value) return true; } - /** - * Valida PIS/PASEP/NIS/NIT - * @param string $attribute - * @param string $value - * @return boolean - */ - protected function validateNis($attribute, $value) { $nis = sprintf('%011s', preg_replace('{\D}', '', $value)); @@ -255,5 +191,4 @@ protected function validateNis($attribute, $value) return ($nis[10] == (((10 * $d) % 11) % 10)); } - } diff --git a/src/validator-docs/ValidatorProvider.php b/src/validator-docs/ValidatorProvider.php index f4a767b..d62491f 100644 --- a/src/validator-docs/ValidatorProvider.php +++ b/src/validator-docs/ValidatorProvider.php @@ -23,7 +23,6 @@ class ValidatorProvider extends ServiceProvider public function boot() { - $me = $this; $this->app['validator']->resolver(function ($translator, $data, $rules, $messages, $attributes) use ($me) { @@ -66,7 +65,6 @@ public function register() */ public function provides() { - return array(); + return []; } - }