Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ parameters:

-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
count: 1
count: 2
path: src/Convert.php

-
Expand Down
3 changes: 2 additions & 1 deletion src/Common/ValidTXT.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ValidTXT
public const LOCAL_V12 = "LOCAL_V12";
public const LOCAL_V13 = "LOCAL_V13";
public const SEBRAE = "SEBRAE";
public const RTC = "RTC";

/**
* Loads structure of txt from json file in storage folder
Expand All @@ -31,7 +32,7 @@ public static function loadStructure(float $version = 4.00, string $baselayout =
{
$path = realpath(__DIR__ . "/../../storage");
$comp = '';
if (strtoupper($baselayout) === 'SEBRAE') {
if (strtoupper($baselayout) === self::SEBRAE) {
$comp = '_sebrae';
} elseif (strtoupper($baselayout) === self::LOCAL_V12) {
$comp = '_v1.2';
Expand Down
41 changes: 41 additions & 0 deletions src/Convert.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Convert
{
public const LOCAL = "LOCAL";
public const LOCAL_V12 = "LOCAL_V12";
public const LOCAL_V13 = "LOCAL_V13";
public const SEBRAE = "SEBRAE";

protected $txt;
Expand Down Expand Up @@ -54,6 +55,15 @@ public static function parse(string $txt, string $baselayout = self::LOCAL): arr
return $conv->toXml();
}

/**
* Static method to convert Txt to Xml
*/
public static function parseDump(string $txt, string $baselayout = self::LOCAL): array
{
$conv = new static($txt, $baselayout);
return $conv->dump();
}

/**
* Convert all nfe in XML, one by one
* @throws \NFePHP\NFe\Exception\DocumentsException
Expand Down Expand Up @@ -91,6 +101,37 @@ public function toXml(): array
return $this->xmls;
}

/**
* Convert all nfe in XML, one by one
* @throws \NFePHP\NFe\Exception\DocumentsException
*/
public function dump(): array
{
if (!$this->isNFe($this->txt)) {
throw DocumentsException::wrongDocument(12, '');
}
$this->notas = $this->sliceNotas($this->dados);
$this->checkQtdNFe();
$this->validNotas();
$i = 0;
$aDumps = [];
foreach ($this->notas as $nota) {
$version = $this->layouts[$i];
$parser = new Parser($version, $this->baselayout);
try {
$aDumps[] = $parser->dump($nota);
} catch (\Throwable $e) {
if ($errors = $parser->getErrors()) {
throw new ParserException(implode(', ', $errors));
} else {
throw new RuntimeException($e->getMessage());
}
}
$i++;
}
return $aDumps;
}

/**
* Check if it is an NFe in TXT format
* @return boolean
Expand Down
Loading