Skip to content

Commit

Permalink
Merge pull request #187 from robmachado/master
Browse files Browse the repository at this point in the history
 [UPD] Keys::class inclusão do método random()
  • Loading branch information
robmachado committed Jun 29, 2018
2 parents 98aed2e + acb8e1f commit 0b76ec1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
16 changes: 13 additions & 3 deletions src/Keys.php
Expand Up @@ -37,10 +37,10 @@ public static function build(
$serie,
$numero,
$tpEmis,
$codigo = ''
$codigo = null
) {
if ($codigo == '') {
$codigo = $numero;
if (empty($codigo)) {
$codigo = self::random();
}
$format = "%02d%02d%02d%s%02d%03d%09d%01d%08d";
$key = sprintf(
Expand Down Expand Up @@ -101,4 +101,14 @@ public static function verifyingDigit($key)
}
return (string) $vdigit;
}

/**
* Generate and return a 8 digits random number
* for cNF tag
* @return string
*/
public static function random()
{
return str_pad(mt_rand(0, 99999999), 8, '0', STR_PAD_LEFT);
}
}
14 changes: 0 additions & 14 deletions tests/KeysTest.php
Expand Up @@ -21,20 +21,6 @@ public function testBuildWithCod()
$this->assertEquals($key, '35170458716523000119550010000000121000123458');
}

public function testBuildWithOutCod()
{
$cUF = 35;
$ano = 17;
$mes = 4;
$cnpj = '58716523000119';
$mod = 55;
$serie = 1;
$numero = 12;
$tpEmis = 1;
$key = Keys::build($cUF, $ano, $mes, $cnpj, $mod, $serie, $numero, $tpEmis);
$this->assertEquals($key, '35170458716523000119550010000000121000000127');
}

public function testIsValidTrue()
{
$key = "35170358716523000119550010000000301000000300";
Expand Down

0 comments on commit 0b76ec1

Please sign in to comment.