Test Setup Failed
Push — master ( 947c79...20ba58 )
by
unknown
34s queued 10s
created

QRCode::putQRTag()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace NFePHP\CTe\Factories;
4
5
/**
6
 * Class QRCode create a string to make a QRCode string
7
 *
8
 * @category  NFePHP
9
 * @package   NFePHP\CTe\Factories\QRCode
10
 * @copyright NFePHP Copyright (c) 2008-2019
11
 * @license   http://www.gnu.org/licenses/lgpl.txt LGPLv3+
12
 * @license   https://opensource.org/licenses/MIT MIT
13
 * @license   http://www.gnu.org/licenses/gpl.txt GPLv3+
14
 * @author    Cleiton Perin <cperin20 at gmail dot com>
15
 * @link      http://github.com/nfephp-org/sped-cte for the canonical source repository
16
 */
17
18
use DOMDocument;
19
use NFePHP\CTe\Exception\DocumentsException;
20
21
class QRCode
22
{
23
    /**
24
     * putQRTag
25
     * @param DOMDocument $dom CTe
26
     * @return string
27
     * @throws DocumentsException
28
     */
29
    public static function putQRTag(
30
        \DOMDocument $dom
31
    )
32
    {
33
        $cte = $dom->getElementsByTagName('CTe')->item(0);
34
        $infCte = $dom->getElementsByTagName('infCte')->item(0);
35
        $ide = $dom->getElementsByTagName('ide')->item(0);
36
        $chCTe = preg_replace('/[^0-9]/', '', $infCte->getAttribute("Id"));
37
        $tpAmb = $ide->getElementsByTagName('tpAmb')->item(0)->nodeValue;
38
        $qrcode = "https://dfe-portal.svrs.rs.gov.br/cte/qrCode?chCTe=$chCTe&tpAmb=$tpAmb";
39
        $infCTeSupl = $dom->createElement("infCTeSupl");
40
        $infCTeSupl->appendChild($dom->createElement('qrCodCTe', $qrcode));
41
        $signature = $dom->getElementsByTagName('Signature')->item(0);
42
        $cte->insertBefore($infCTeSupl, $signature);
43
        $dom->formatOutput = false;
44
        return $dom->saveXML();
45
    }
46
47
}
48