Boleta::xmlSerialize()   B
last analyzed

Complexity

Conditions 7
Paths 64

Size

Total Lines 102
Code Lines 63

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 63
nc 64
nop 1
dl 0
loc 102
rs 7.8739
c 1
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * MÓDULO DE EMISIÓN ELECTRÓNICA F72X
5
 * UBL 2.1
6
 * Version 1.0
7
 * 
8
 * Copyright 2019, Jaime Cruz
9
 */
10
11
namespace F72X\Sunat\Document;
12
13
use F72X\Company;
14
use F72X\Tools\TemplateMgr;
15
use F72X\UblComponent\SchemaNS;
16
use Sabre\Xml\Writer;
17
18
class Boleta extends SunatInvoice {
19
20
    protected $UBLVersionID = '2.1';
21
    protected $CustomizationID = '2.0';
22
23
    public function xmlSerialize(Writer $writer) {
24
        $companyRUC  = Company::getRUC();
25
        $companyName = Company::getCompanyName();
26
        // SchemaNS::EXT . 'UBLExtensions'
27
        $UBLExtensions = TemplateMgr::getTpl('UBLExtensions.xml');
28
        $Signature     = TemplateMgr::getTpl('Signature.xml', [
29
                    'ruc'         => $companyRUC,
30
                    'companyName' => $companyName
31
        ]);
32
        $this->writeLineJump($writer);
33
        $writer->writeRaw($UBLExtensions);
34
35
        $writer->write([
36
            SchemaNS::CBC . 'UBLVersionID'         => $this->UBLVersionID,
37
            SchemaNS::CBC . 'CustomizationID'      => $this->CustomizationID,
38
            [
39
                'name' => SchemaNS::CBC . 'ProfileID',
40
                'value' => $this->ProfileID,
41
                'attributes' => [
42
                    'schemeName' => 'SUNAT:Identificador de Tipo de Operación',
43
                    'schemeAgencyName' => 'PE:SUNAT',
44
                    'schemeURI' => 'urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo17'
45
                ]
46
            ],
47
            SchemaNS::CBC . 'ID' => $this->ID,
48
            SchemaNS::CBC . 'IssueDate' => $this->IssueDate->format('Y-m-d'),
49
            SchemaNS::CBC . 'IssueTime' => $this->IssueDate->format('H:i:s')
50
        ]);
51
        if ($this->DueDate) {
52
            $writer->write([
53
                SchemaNS::CBC . 'DueDate' => $this->DueDate->format('Y-m-d')
54
            ]);
55
        }
56
        $writer->write([
57
            [
58
                'name' => SchemaNS::CBC . 'InvoiceTypeCode',
59
                'value' => $this->InvoiceTypeCode,
60
                'attributes' => [
61
                    'listAgencyName' => 'PE:SUNAT',
62
                    'listID'         => $this->ProfileID,
63
                    'listName'       => 'Tipo de Documento',
64
                    'listSchemeURI'  => 'urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo51',
65
                    'listURI'        => 'urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo01',
66
                    'name'           => 'Tipo de Operacion'
67
                ]
68
            ]
69
        ]);
70
71
        // Write notes
72
        foreach ($this->Notes as $InvoiceLine) {
73
            $writer->write($InvoiceLine);
74
        }
75
76
        $writer->write([
77
            [
78
                'name'  => SchemaNS::CBC . 'DocumentCurrencyCode',
79
                'value' => $this->DocumentCurrencyCode,
80
                'attributes' => [
81
                    'listID'            => 'ISO 4217 Alpha',
82
                    'listName'          => 'Currency',
83
                    'listAgencyName'    => 'United Nations Economic Commission for Europe'
84
                ]
85
            ],
86
            SchemaNS::CBC . 'LineCountNumeric' => $this->LineCountNumeric
87
        ]);
88
89
        // Order Reference
90
        if ($this->OrderReference) {
91
            $writer->write([
92
                SchemaNS::CAC . 'OrderReference' => $this->OrderReference
93
            ]);
94
        }
95
96
        // Despatch Document Reference
97
        if ($this->DespatchDocumentReference) {
98
            $writer->write([
99
                SchemaNS::CAC . 'DespatchDocumentReference' => $this->DespatchDocumentReference
100
            ]);
101
        }
102
        // cac:Signature
103
        $writer->writeRaw($Signature);
104
        $writer->write([
105
            SchemaNS::CAC . 'AccountingSupplierParty'   => $this->AccountingSupplierParty,
106
            SchemaNS::CAC . 'AccountingCustomerParty'   => $this->AccountingCustomerParty
107
        ]);
108
        // Cargos y descuentos
109
        foreach ($this->AllowanceCharges as $AllowanceCharge) {
110
            $writer->write([
111
                SchemaNS::CAC . 'AllowanceCharge' => $AllowanceCharge
112
            ]);
113
        }
114
        $writer->write([
115
            SchemaNS::CAC . 'TaxTotal' => $this->TaxTotal
116
        ]);
117
        $writer->write([
118
            SchemaNS::CAC . 'LegalMonetaryTotal' => $this->LegalMonetaryTotal
119
        ]);
120
121
        // Detalle
122
        foreach ($this->InvoiceLines as $InvoiceLine) {
123
            $writer->write([
124
                SchemaNS::CAC . 'InvoiceLine' => $InvoiceLine
125
            ]);
126
        }
127
    }
128
129
}
130