Completed
Pull Request — master (#83)
by
unknown
11:11
created

QRCode   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 1
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A putQRTag() 0 18 1
1
<?php
2
3
namespace NFePHP\MDFe\Factories;
4
5
/**
6
 * Class QRCode create a string to make a QRCode string
7
 *
8
 * @author    Cleiton Perin <cperin20 at gmail dot com>
9
 * @package   NFePHP\MDFe\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
 * @category  NFePHP
15
 * @link      http://github.com/nfephp-org/sped-mdfe for the canonical source repository
16
 */
17
18
use DOMDocument;
19
use NFePHP\MDFe\Exception\DocumentsException;
20
21
class QRCode
22
{
23
    /**
24
     * putQRTag
25
     * @param DOMDocument $dom MDFe
26
     * @return string
27
     * @throws DocumentsException
28
     */
29
    public static function putQRTag(
30
        \DOMDocument $dom
31
    ) {
32
33
        $mdfe = $dom->getElementsByTagName('MDFe')->item(0);
34
        $infMDFe = $dom->getElementsByTagName('infMDFe')->item(0);
35
        $ide = $dom->getElementsByTagName('ide')->item(0);
36
        $chMDFe = preg_replace('/[^0-9]/', '', $infMDFe->getAttribute("Id"));
37
        $tpAmb = $ide->getElementsByTagName('tpAmb')->item(0)->nodeValue;
38
        $urlQRCode = "https://dfe-portal.svrs.rs.gov.br/mdfe/qrCode?chMDFe=$chMDFe&tpAmb=$tpAmb";
39
        $infMDFeSupl = $dom->createElement("infMDFeSupl");
40
        $qrCode = $infMDFeSupl->appendChild($dom->createElement('qrCodMDFe'));
41
        $qrCode->appendChild($dom->createCDATASection($urlQRCode));
42
        $signature = $dom->getElementsByTagName('Signature')->item(0);
43
        $mdfe->insertBefore($infMDFeSupl, $signature);
44
        $dom->formatOutput = false;
45
        return $dom->saveXML();
46
    }
47
}
48