Skip to content

Commit fa066ac

Browse files
committed
atualizacao na documentacao
1 parent 66df3b1 commit fa066ac

File tree

5 files changed

+67
-64
lines changed

5 files changed

+67
-64
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
#Validator Docs Brasil 1.0
1+
# Validate Docs - Brasil
2+
3+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/geekcom/validator-docs/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/geekcom/validator-docs/?branch=master)
24

35
Biblioteca para validação dos seguintes documentos: CPF, CNPJ e CNH.
46

5-
#Instalação
7+
# Instalação
68

79
No arquivo `composer.json`, adicione:
810

src/validator-docs/Validator.php

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,43 @@
1-
<?php
1+
<?php
22

33
namespace geekcom\ValidatorDocs;
44

55
use Illuminate\Validation\Validator as BaseValidator;
66

77
/**
8-
*
9-
* @author Daniel Rodrigues Lima
10-
*/
11-
8+
*
9+
* @author Daniel Rodrigues Lima
10+
*/
1211
class Validator extends BaseValidator
1312
{
1413
/**
15-
* Valida o formato do cpf
16-
* @param string $attribute
17-
* @param string $value
18-
* @return boolean
19-
*/
14+
* Valida o formato do cpf
15+
* @param string $attribute
16+
* @param string $value
17+
* @return boolean
18+
*/
2019
protected function validateFormatoCpf($attribute, $value)
2120
{
2221
return preg_match('/^\d{3}\.\d{3}\.\d{3}-\d{2}$/', $value) > 0;
2322
}
2423

2524
/**
26-
* Valida o formato do cnpj
27-
* @param string $attribute
28-
* @param string $value
29-
* @return boolean
30-
*/
25+
* Valida o formato do cnpj
26+
* @param string $attribute
27+
* @param string $value
28+
* @return boolean
29+
*/
3130
protected function validateFormatoCnpj($attribute, $value)
3231
{
3332
return preg_match('/^\d{2}\.\d{3}\.\d{3}\/\d{4}-\d{2}$/', $value) > 0;
3433
}
3534

3635
/**
37-
* Valida se o CPF é válido
38-
* @param string $attribute
39-
* @param string $value
40-
* @return boolean
41-
*/
36+
* Valida se o CPF é válido
37+
* @param string $attribute
38+
* @param string $value
39+
* @return boolean
40+
*/
4241

4342
protected function validateCpf($attribute, $value)
4443
{
@@ -48,13 +47,13 @@ protected function validateCpf($attribute, $value)
4847
return false;
4948
}
5049

51-
for ($s = 10, $n = 0, $i = 0; $s >= 2; $n += $c[$i++] * $s--);
50+
for ($s = 10, $n = 0, $i = 0; $s >= 2; $n += $c[$i++] * $s--) ;
5251

5352
if ($c[9] != ((($n %= 11) < 2) ? 0 : 11 - $n)) {
5453
return false;
5554
}
5655

57-
for ($s = 11, $n = 0, $i = 0; $s >= 2; $n += $c[$i++] * $s--);
56+
for ($s = 11, $n = 0, $i = 0; $s >= 2; $n += $c[$i++] * $s--) ;
5857

5958
if ($c[10] != ((($n %= 11) < 2) ? 0 : 11 - $n)) {
6059
return false;
@@ -65,11 +64,11 @@ protected function validateCpf($attribute, $value)
6564
}
6665

6766
/**
68-
* Valida se o CNPJ é válido
69-
* @param string $attribute
70-
* @param string $value
71-
* @return boolean
72-
*/
67+
* Valida se o CNPJ é válido
68+
* @param string $attribute
69+
* @param string $value
70+
* @return boolean
71+
*/
7372
protected function validateCnpj($attribute, $value)
7473
{
7574
$c = preg_replace('/\D/', '', $value);
@@ -80,13 +79,13 @@ protected function validateCnpj($attribute, $value)
8079
return false;
8180
}
8281

83-
for ($i = 0, $n = 0; $i < 12; $n += $c[$i] * $b[++$i]);
82+
for ($i = 0, $n = 0; $i < 12; $n += $c[$i] * $b[++$i]) ;
8483

8584
if ($c[12] != ((($n %= 11) < 2) ? 0 : 11 - $n)) {
8685
return false;
8786
}
8887

89-
for ($i = 0, $n = 0; $i <= 12; $n += $c[$i] * $b[$i++]);
88+
for ($i = 0, $n = 0; $i <= 12; $n += $c[$i] * $b[$i++]) ;
9089

9190
if ($c[13] != ((($n %= 11) < 2) ? 0 : 11 - $n)) {
9291
return false;
@@ -97,25 +96,26 @@ protected function validateCnpj($attribute, $value)
9796
}
9897

9998
/**
100-
* Valida se o CNH é válido
101-
* @param string $attribute
102-
* @param string $value
103-
* @return boolean
104-
*/
99+
* Valida se o CNH é válido
100+
* @param string $attribute
101+
* @param string $value
102+
* @return boolean
103+
*/
105104

106105
protected function validateCnh($attribute, $value)
107106
{
108107
// Trecho retirado do respect validation
109108

110109
$ret = false;
111-
110+
112111
if ((strlen($input = preg_replace('/[^\d]/', '', $value)) == 11)
113-
&& (str_repeat($input[1], 11) != $input)) {
112+
&& (str_repeat($input[1], 11) != $input)
113+
) {
114114
$dsc = 0;
115115

116116
for ($i = 0, $j = 9, $v = 0; $i < 9; ++$i, --$j) {
117117

118-
$v += (int) $input[$i] * $j;
118+
$v += (int)$input[$i] * $j;
119119

120120
}
121121

@@ -128,8 +128,8 @@ protected function validateCnh($attribute, $value)
128128

129129
for ($i = 0, $j = 1, $v = 0; $i < 9; ++$i, ++$j) {
130130

131-
$v += (int) $input[$i] * $j;
132-
131+
$v += (int)$input[$i] * $j;
132+
133133
}
134134

135135
$vl2 = ($x = ($v % 11)) >= 10 ? 0 : $x - $dsc;

src/validator-docs/ValidatorProvider.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php
22

33
namespace geekcom\ValidatorDocs;
44

@@ -14,35 +14,34 @@ class ValidatorProvider extends ServiceProvider
1414
*/
1515
protected $defer = false;
1616

17-
17+
1818
/**
1919
* Bootstrap the application events.
2020
*
2121
* @return void
2222
*/
23-
23+
2424
public function boot()
2525
{
2626

2727
$me = $this;
2828

29-
$this->app['validator']->resolver(function ($translator, $data, $rules, $messages) use($me)
30-
{
29+
$this->app['validator']->resolver(function ($translator, $data, $rules, $messages) use ($me) {
3130
$messages += $me->getMessages();
32-
31+
3332
return new Validator($translator, $data, $rules, $messages);
3433
});
3534
}
3635

3736

3837
protected function getMessages()
3938
{
40-
return [
41-
'cnh' => 'O campo :attribute não é uma carteira nacional de habilitação válida',
42-
'cnpj' => 'O campo :attribute não é um CNPJ válido',
43-
'cpf' => 'O campo :attribute não é um CPF válido',
44-
'formato_cnpj' => 'O campo :attribute não possui o formato válido de CNPJ',
45-
'formato_cpf' => 'O campo :attribute não possui o formato válido de CPF',
39+
return [
40+
'cnh' => 'O campo :attribute não é uma carteira nacional de habilitação válida',
41+
'cnpj' => 'O campo :attribute não é um CNPJ válido',
42+
'cpf' => 'O campo :attribute não é um CPF válido',
43+
'formato_cnpj' => 'O campo :attribute não possui o formato válido de CNPJ',
44+
'formato_cpf' => 'O campo :attribute não possui o formato válido de CPF',
4645
];
4746
}
4847

@@ -51,7 +50,9 @@ protected function getMessages()
5150
*
5251
* @return void
5352
*/
54-
public function register(){}
53+
public function register()
54+
{
55+
}
5556

5657
/**
5758
* Get the services provided by the provider.

tests/TestValidator.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function testCpf()
1818

1919
$this->assertTrue($correct->passes());
2020

21-
$this->assertTrue($incorrect->fails());
21+
$this->assertTrue($incorrect->fails());
2222
}
2323

2424
public function testCpfFormato()
@@ -35,7 +35,7 @@ public function testCpfFormato()
3535

3636
$this->assertTrue($correct->passes());
3737

38-
$this->assertTrue($incorrect->fails());
38+
$this->assertTrue($incorrect->fails());
3939
}
4040

4141

@@ -53,7 +53,7 @@ public function testCnpj()
5353

5454
$this->assertTrue($correct->passes());
5555

56-
$this->assertTrue($incorrect->fails());
56+
$this->assertTrue($incorrect->fails());
5757
}
5858

5959

@@ -71,7 +71,7 @@ public function testCnpjFormato()
7171

7272
$this->assertTrue($correct->passes());
7373

74-
$this->assertTrue($incorrect->fails());
74+
$this->assertTrue($incorrect->fails());
7575
}
7676

7777
public function testCnh()
@@ -88,7 +88,7 @@ public function testCnh()
8888

8989
$this->assertTrue($correct->passes());
9090

91-
$this->assertTrue($incorrect->fails());
91+
$this->assertTrue($incorrect->fails());
9292
}
9393

9494
}

tests/ValidatorTestCase.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
abstract class ValidatorTestCase extends TestCase
44
{
5-
public function setUp()
6-
{
7-
parent::setUp();
5+
public function setUp()
6+
{
7+
parent::setUp();
88

9-
$this->app->register(\geekcom\ValidatorDocs\ValidatorProvider::class);
10-
}
9+
$this->app->register(\geekcom\ValidatorDocs\ValidatorProvider::class);
10+
}
1111
}

0 commit comments

Comments
 (0)