Test Failed
Push — master ( d3c8d8...d4fc42 )
by JAIME ELMER
02:02
created

Boleta::xmlSerialize()   B

Complexity

Conditions 7
Paths 64

Size

Total Lines 102
Code Lines 63

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 63
nc 64
nop 1
dl 0
loc 102
rs 7.8739
c 0
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.1
7
 * 
8
 * Copyright 2018, 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 SunatDocument {
19
20
    /**
21
     * The xmlSerialize method is called during xml writing.
22
     *
23
     * @param Writer $writer
24
     * @return void
25
     */
26
    public function xmlSerialize(Writer $writer) {
27
        $companyRUC  = Company::getRUC();
28
        $companyName = Company::getCompanyName();
29
        // SchemaNS::EXT . 'UBLExtensions'
30
        $UBLExtensions = TemplateMgr::getTpl('UBLExtensions.xml');
31
        $Signature     = TemplateMgr::getTpl('Signature.xml', [
32
                    'ruc'         => $companyRUC,
33
                    'companyName' => $companyName
34
        ]);
35
        $this->writeLineJump($writer);
36
        $writer->writeRaw($UBLExtensions);
37
38
        $writer->write([
39
            SchemaNS::CBC . 'UBLVersionID'      => self::UBL_VERSION_ID,
40
            SchemaNS::CBC . 'CustomizationID'   => self::CUSTUMIZATION_ID,
41
            [
42
                'name' => SchemaNS::CBC . 'ProfileID',
43
                'value' => $this->ProfileID,
44
                'attributes' => [
45
                    'schemeName' => 'SUNAT:Identificador de Tipo de Operación',
46
                    'schemeAgencyName' => 'PE:SUNAT',
47
                    'schemeURI' => 'urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo17'
48
                ]
49
            ],
50
            SchemaNS::CBC . 'ID' => $this->ID,
51
            SchemaNS::CBC . 'IssueDate' => $this->IssueDate->format('Y-m-d'),
52
            SchemaNS::CBC . 'IssueTime' => $this->IssueDate->format('H:i:s')
53
        ]);
54
        if ($this->DueDate) {
55
            $writer->write([
56
                SchemaNS::CBC . 'DueDate' => $this->DueDate->format('Y-m-d')
57
            ]);
58
        }
59
        $writer->write([
60
            [
61
                'name' => SchemaNS::CBC . 'InvoiceTypeCode',
62
                'value' => $this->InvoiceTypeCode,
63
                'attributes' => [
64
                    'listAgencyName' => 'PE:SUNAT',
65
                    'listID'         => $this->ProfileID,
66
                    'listName'       => 'Tipo de Documento',
67
                    'listSchemeURI'  => 'urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo51',
68
                    'listURI'        => 'urn:pe:gob:sunat:cpe:see:gem:catalogos:catalogo01',
69
                    'name'           => 'Tipo de Operacion'
70
                ]
71
            ]
72
        ]);
73
74
        // Write notes
75
        foreach ($this->Notes as $InvoiceLine) {
76
            $writer->write($InvoiceLine);
77
        }
78
79
        $writer->write([
80
            [
81
                'name'  => SchemaNS::CBC . 'DocumentCurrencyCode',
82
                'value' => $this->DocumentCurrencyCode,
83
                'attributes' => [
84
                    'listID'            => 'ISO 4217 Alpha',
85
                    'listName'          => 'Currency',
86
                    'listAgencyName'    => 'United Nations Economic Commission for Europe'
87
                ]
88
            ],
89
            SchemaNS::CBC . 'LineCountNumeric'          => $this->LineCountNumeric
90
        ]);
91
92
        // Order Reference
93
        if($this->OrderReference){
94
            $writer->write([
95
                SchemaNS::CAC . 'OrderReference'            => $this->OrderReference
96
            ]);
97
        }
98
99
        // Despatch Document Reference
100
        if($this->DespatchDocumentReference){
101
            $writer->write([
102
                SchemaNS::CAC . 'DespatchDocumentReference' => $this->DespatchDocumentReference
103
            ]);
104
        }
105
        // cac:Signature
106
        $writer->writeRaw($Signature);
107
        $writer->write([
108
            SchemaNS::CAC . 'AccountingSupplierParty'   => $this->AccountingSupplierParty,
109
            SchemaNS::CAC . 'AccountingCustomerParty'   => $this->AccountingCustomerParty
110
        ]);
111
        // Cargos y descuentos
112
        foreach ($this->AllowanceCharges as $AllowanceCharge) {
113
            $writer->write([
114
                SchemaNS::CAC . 'AllowanceCharge' => $AllowanceCharge
115
            ]);
116
        }
117
        $writer->write([
118
            SchemaNS::CAC . 'TaxTotal' => $this->TaxTotal
119
        ]);
120
        $writer->write([
121
            SchemaNS::CAC . 'LegalMonetaryTotal' => $this->LegalMonetaryTotal
122
        ]);
123
124
        // Detalle
125
        foreach ($this->InvoiceLines as $InvoiceLine) {
126
            $writer->write([
127
                SchemaNS::CAC . 'InvoiceLine' => $InvoiceLine
128
            ]);
129
        }
130
    }
131
132
}
133