Skip to content

Commit 48e70a2

Browse files
authored
Merge pull request #25 from geekcom/develop
Melhorias de leitura nos códigos
2 parents 7bc0e7a + ca5742f commit 48e70a2

File tree

2 files changed

+11
-78
lines changed

2 files changed

+11
-78
lines changed

src/validator-docs/Validator.php

Lines changed: 10 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -4,64 +4,40 @@
44

55
use Illuminate\Validation\Validator as BaseValidator;
66

7+
use function preg_match;
8+
use function preg_replace;
9+
use function strlen;
10+
use function str_repeat;
11+
use function sprintf;
12+
use function substr;
13+
714
/**
815
*
916
* @author Daniel Rodrigues Lima
1017
1118
*/
1219
class Validator extends BaseValidator
1320
{
14-
/**
15-
* Valida o formato do cpf
16-
* @param string $attribute
17-
* @param string $value
18-
* @return boolean
19-
*/
2021
protected function validateFormatoCpf($attribute, $value)
2122
{
2223
return preg_match('/^\d{3}\.\d{3}\.\d{3}-\d{2}$/', $value) > 0;
2324
}
2425

25-
/**
26-
* Valida o formato do cnpj
27-
* @param string $attribute
28-
* @param string $value
29-
* @return boolean
30-
*/
3126
protected function validateFormatoCnpj($attribute, $value)
3227
{
3328
return preg_match('/^\d{2}\.\d{3}\.\d{3}\/\d{4}-\d{2}$/', $value) > 0;
3429
}
3530

36-
/**
37-
* Valida o formato do cpf ou cnpj
38-
* @param string $attribute
39-
* @param string $value
40-
* @return boolean
41-
*/
4231
protected function validateFormatoCpfCnpj($attribute, $value)
4332
{
4433
return $this->validateFormatoCpf($attribute, $value) || $this->validateFormatoCnpj($attribute, $value);
4534
}
4635

47-
/**
48-
* Valida o formato do PIS/PASEP/NIS/NIT
49-
* @param string $attribute
50-
* @param string $value
51-
* @return boolean
52-
*/
5336
protected function validateFormatoNis($attribute, $value)
5437
{
5538
return preg_match('/^\d{3}\.\d{5}\.\d{2}-\d{1}$/', $value) > 0;
5639
}
5740

58-
/**
59-
* Valida CPF
60-
* @param string $attribute
61-
* @param string $value
62-
* @return boolean
63-
*/
64-
6541
protected function validateCpf($attribute, $value)
6642
{
6743
$c = preg_replace('/\D/', '', $value);
@@ -85,12 +61,6 @@ protected function validateCpf($attribute, $value)
8561
return true;
8662
}
8763

88-
/**
89-
* Valida CNPJ
90-
* @param string $attribute
91-
* @param string $value
92-
* @return boolean
93-
*/
9464
protected function validateCnpj($attribute, $value)
9565
{
9666
$c = preg_replace('/\D/', '', $value);
@@ -116,28 +86,16 @@ protected function validateCnpj($attribute, $value)
11686
return true;
11787
}
11888

119-
/**
120-
* Valida CNPJ ou CPF
121-
* @param string $attribute
122-
* @param string $value
123-
* @return boolean
124-
*/
12589
protected function validateCpfCnpj($attribute, $value)
12690
{
12791
return ($this->validateCpf($attribute, $value) || $this->validateCnpj($attribute, $value));
12892
}
12993

13094
/**
131-
* Valida CNH
132-
* @param string $attribute
133-
* @param string $value
134-
* @return boolean
95+
* Trecho retirado do respect validation
13596
*/
136-
13797
protected function validateCnh($attribute, $value)
13898
{
139-
// Trecho retirado do respect validation
140-
14199
$ret = false;
142100

143101
if ((strlen($input = preg_replace('/[^\d]/', '', $value)) == 11)
@@ -146,22 +104,16 @@ protected function validateCnh($attribute, $value)
146104
$dsc = 0;
147105

148106
for ($i = 0, $j = 9, $v = 0; $i < 9; ++$i, --$j) {
149-
150-
$v += (int)$input[$i] * $j;
151-
107+
$v += (int) $input[$i] * $j;
152108
}
153109

154110
if (($vl1 = $v % 11) >= 10) {
155-
156111
$vl1 = 0;
157112
$dsc = 2;
158-
159113
}
160114

161115
for ($i = 0, $j = 1, $v = 0; $i < 9; ++$i, ++$j) {
162-
163-
$v += (int)$input[$i] * $j;
164-
116+
$v += (int) $input[$i] * $j;
165117
}
166118

167119
$vl2 = ($x = ($v % 11)) >= 10 ? 0 : $x - $dsc;
@@ -172,16 +124,8 @@ protected function validateCnh($attribute, $value)
172124
return $ret;
173125
}
174126

175-
/**
176-
* Valida Titulo de Eleitor
177-
* @param string $attribute
178-
* @param string $value
179-
* @return boolean
180-
*/
181-
182127
protected function validateTituloEleitor($attribute, $value)
183128
{
184-
185129
$input = preg_replace('/[^\d]/', '', $value);
186130

187131
$uf = substr($input, -4, 2);
@@ -226,21 +170,13 @@ protected function validateTituloEleitor($attribute, $value)
226170
switch ($i) {
227171
case '0':
228172
$sequencia = $uf . $digito;
229-
230173
break;
231174
}
232175
}
233176

234177
return true;
235178
}
236179

237-
/**
238-
* Valida PIS/PASEP/NIS/NIT
239-
* @param string $attribute
240-
* @param string $value
241-
* @return boolean
242-
*/
243-
244180
protected function validateNis($attribute, $value)
245181
{
246182
$nis = sprintf('%011s', preg_replace('{\D}', '', $value));
@@ -255,5 +191,4 @@ protected function validateNis($attribute, $value)
255191

256192
return ($nis[10] == (((10 * $d) % 11) % 10));
257193
}
258-
259194
}

src/validator-docs/ValidatorProvider.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class ValidatorProvider extends ServiceProvider
2323

2424
public function boot()
2525
{
26-
2726
$me = $this;
2827

2928
$this->app['validator']->resolver(function ($translator, $data, $rules, $messages, $attributes) use ($me) {
@@ -66,7 +65,6 @@ public function register()
6665
*/
6766
public function provides()
6867
{
69-
return array();
68+
return [];
7069
}
71-
7270
}

0 commit comments

Comments
 (0)