Skip to content

Commit

Permalink
allowmask
Browse files Browse the repository at this point in the history
  • Loading branch information
bachilli committed Aug 12, 2019
1 parent fc36064 commit 3d42be1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/Rules/Cnpj.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ class Cnpj implements Rule
{
protected $invalidCnpjs;

public function __construct()
public $allowMask;

public function __construct($allowMask = true)
{
$this->allowMask = $allowMask;

$this->invalidCnpjs = [
'00000000000000',
'11111111111111',
Expand All @@ -32,7 +36,9 @@ public function passes($attribute, $value): bool
return true;
}

$value = preg_replace('/\D/', '', $value);
if ($this->allowMask) {
$value = preg_replace('/\D/', '', $value);
}

if (!($value && mb_strlen($value) === 14)) {
return false;
Expand Down
10 changes: 8 additions & 2 deletions src/Rules/Cpf.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ class Cpf implements Rule
{
protected $invalidCpfs;

public function __construct()
public $allowMask;

public function __construct($allowMask = true)
{
$this->allowMask = $allowMask;

$this->invalidCpfs = [
'00000000000',
'11111111111',
Expand All @@ -32,7 +36,9 @@ public function passes($attribute, $value): bool
return true;
}

$value = preg_replace('/\D/', '', $value);
if ($this->allowMask) {
$value = preg_replace('/\D/', '', $value);
}

if (!($value && mb_strlen($value) === 11)) {
return false;
Expand Down
11 changes: 10 additions & 1 deletion src/Rules/Nfe.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@

class Nfe
{
public $allowMask;

public function __construct($allowMask = false)
{
$this->allowMask = $allowMask;
}

public function passes($attribute, $value): bool
{
if (!$value) {
return true;
}

$value = preg_replace('/\D/', '', $value);
if ($this->allowMask) {
$value = preg_replace('/\D/', '', $value);
}

if (!($value && mb_strlen($value) === 44) || mb_substr($value, 0, 2) === '00') {
return false;
Expand Down

0 comments on commit 3d42be1

Please sign in to comment.