Skip to content

Commit 6b3f131

Browse files
author
Thiago Ribeiro
committed
Adicionando suporte a NaturezaTributacao e deixando cpfCnpj null, 11, ou 14.
1 parent 977afb0 commit 6b3f131

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

src/Nfse.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class Nfse extends BuilderAbstract implements IDfe
3131
private $servico;
3232
private $substituicao;
3333
private $tomador;
34+
private $naturezaTributacao;
3435

3536
public function setCidadePrestacao(CidadePrestacao $cidadePrestacao)
3637
{
@@ -75,6 +76,15 @@ public function getIdIntegracao()
7576
return $this->idIntegracao;
7677
}
7778

79+
public function setNaturezaTributacao($naturezaTributacao)
80+
{
81+
$this->naturezaTributacao = $naturezaTributacao;
82+
}
83+
84+
public function getNaturezaTributacao()
85+
{
86+
return $this->naturezaTributacao;
87+
}
7888
public function setImpressao(Impressao $impressao)
7989
{
8090
$this->impressao = $impressao;
@@ -144,15 +154,6 @@ public function validate()
144154
if(
145155
!v::allOf(
146156
v::keyNested('prestador.cpfCnpj'),
147-
v::keyNested('prestador.inscricaoMunicipal'),
148-
v::keyNested('prestador.razaoSocial'),
149-
v::keyNested('prestador.simplesNacional'),
150-
v::keyNested('prestador.endereco.logradouro'),
151-
v::keyNested('prestador.endereco.numero'),
152-
v::keyNested('prestador.endereco.codigoCidade'),
153-
v::keyNested('prestador.endereco.cep'),
154-
v::keyNested('tomador.cpfCnpj'),
155-
v::keyNested('tomador.razaoSocial'),
156157
v::keyNested('servico.codigo'),
157158
v::keyNested('servico.discriminacao'),
158159
v::keyNested('servico.cnae'),
@@ -161,7 +162,6 @@ public function validate()
161162
)->validate($data) ||
162163
!v::allOf(
163164
v::keyNested('prestador.cpfCnpj'),
164-
v::keyNested('tomador.cpfCnpj'),
165165
v::keyNested('servico.id')
166166
)->validate($data)
167167
) {

src/Nfse/Tomador.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ public function setCpfCnpj($cpfCnpj)
3030
{
3131
$cleanCpfCnpj = preg_replace('/[^0-9]/', '', $cpfCnpj);
3232

33-
if (!(strlen($cleanCpfCnpj) === 11 || strlen($cleanCpfCnpj) === 14)) {
33+
if (
34+
!is_null($cpfCnpj) &&
35+
!((strlen($cleanCpfCnpj) === 11 || strlen($cleanCpfCnpj) === 14))
36+
) {
3437
throw new ValidationError(
35-
'Campo cpfCnpj deve ter 11 ou 14 números.'
38+
'Quando preenchido, o campo cpfCnpj deve possuir 11 ou 14 números.'
3639
);
3740
}
3841

tests/Nfse/TomadorTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,23 @@
1919

2020
class TomadorTest extends TestCase
2121
{
22+
/**
23+
* @covers TecnoSpeed\Plugnotas\Nfse\Tomador::setCpfCnpj
24+
*/
25+
public function testWithNullcpfCnpj()
26+
{
27+
$tomador = new Tomador();
28+
$tomador->setCpfCnpj(null);
29+
$this->assertSame($tomador->getCpfCnpj(), '');
30+
}
31+
2232
/**
2333
* @covers TecnoSpeed\Plugnotas\Nfse\Tomador::setCpfCnpj
2434
*/
2535
public function testWithInvalidLengthCpfCnpj()
2636
{
2737
$this->expectException(ValidationError::class);
28-
$this->expectExceptionMessage('Campo cpfCnpj deve ter 11 ou 14 números.');
38+
$this->expectExceptionMessage('Quando preenchido, o campo cpfCnpj deve possuir 11 ou 14 números.');
2939
$tomador = new Tomador();
3040
$tomador->setCpfCnpj('12345678901234567890');
3141
}

0 commit comments

Comments
 (0)