Failed Conditions
Pull Request — master (#3962)
by Owen
28:46 queued 17:47
created

Metadata::writeMetadata()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 113
Code Lines 93

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 92
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 93
c 1
b 0
f 0
dl 0
loc 113
ccs 92
cts 93
cp 0.9892
rs 8.1527
cc 3
nc 3
nop 0
crap 3

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
namespace PhpOffice\PhpSpreadsheet\Writer\Xlsx;
4
5
use PhpOffice\PhpSpreadsheet\Reader\Xlsx\Namespaces;
6
use PhpOffice\PhpSpreadsheet\Shared\XMLWriter;
7
8
class Metadata extends WriterPart
9
{
10
    /**
11
     * Write content types to XML format.
12
     *
13
     * @return string XML Output
14
     */
15 342
    public function writeMetadata(): string
16
    {
17 342
        if (!$this->getParentWriter()->useDynamicArrays()) {
18 337
            return '';
19
        }
20
        // Create XML writer
21 6
        $objWriter = null;
22 6
        if ($this->getParentWriter()->getUseDiskCaching()) {
23
            $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
24
        } else {
25 6
            $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
26
        }
27
28
        // XML header
29 6
        $objWriter->startDocument('1.0', 'UTF-8', 'yes');
30
31
        // Types
32 6
        $objWriter->startElement('metadata');
33 6
        $objWriter->writeAttribute('xmlns', Namespaces::MAIN);
34 6
        $objWriter->writeAttribute('xmlns:xlrd', Namespaces::DYNAMIC_ARRAY_RICHDATA);
35 6
        $objWriter->writeAttribute('xmlns:xda', Namespaces::DYNAMIC_ARRAY);
36
37 6
        $objWriter->startElement('metadataTypes');
38 6
        $objWriter->writeAttribute('count', '2');
39
40 6
        $objWriter->startElement('metadataType');
41 6
        $objWriter->writeAttribute('name', 'XLDAPR');
42 6
        $objWriter->writeAttribute('minSupportedVersion', '120000');
43 6
        $objWriter->writeAttribute('copy', '1');
44 6
        $objWriter->writeAttribute('pasteAll', '1');
45 6
        $objWriter->writeAttribute('pasteValues', '1');
46 6
        $objWriter->writeAttribute('merge', '1');
47 6
        $objWriter->writeAttribute('splitFirst', '1');
48 6
        $objWriter->writeAttribute('rowColShift', '1');
49 6
        $objWriter->writeAttribute('clearFormats', '1');
50 6
        $objWriter->writeAttribute('clearComments', '1');
51 6
        $objWriter->writeAttribute('assign', '1');
52 6
        $objWriter->writeAttribute('coerce', '1');
53 6
        $objWriter->writeAttribute('cellMeta', '1');
54 6
        $objWriter->endElement(); // metadataType XLDAPR
55
56 6
        $objWriter->startElement('metadataType');
57 6
        $objWriter->writeAttribute('name', 'XLRICHVALUE');
58 6
        $objWriter->writeAttribute('minSupportedVersion', '120000');
59 6
        $objWriter->writeAttribute('copy', '1');
60 6
        $objWriter->writeAttribute('pasteAll', '1');
61 6
        $objWriter->writeAttribute('pasteValues', '1');
62 6
        $objWriter->writeAttribute('merge', '1');
63 6
        $objWriter->writeAttribute('splitFirst', '1');
64 6
        $objWriter->writeAttribute('rowColShift', '1');
65 6
        $objWriter->writeAttribute('clearFormats', '1');
66 6
        $objWriter->writeAttribute('clearComments', '1');
67 6
        $objWriter->writeAttribute('assign', '1');
68 6
        $objWriter->writeAttribute('coerce', '1');
69 6
        $objWriter->endElement(); // metadataType XLRICHVALUE
70
71 6
        $objWriter->endElement(); // metadataTypes
72
73 6
        $objWriter->startElement('futureMetadata');
74 6
        $objWriter->writeAttribute('name', 'XLDAPR');
75 6
        $objWriter->writeAttribute('count', '1');
76 6
        $objWriter->startElement('bk');
77 6
        $objWriter->startElement('extLst');
78 6
        $objWriter->startElement('ext');
79 6
        $objWriter->writeAttribute('uri', '{bdbb8cdc-fa1e-496e-a857-3c3f30c029c3}');
80 6
        $objWriter->startElement('xda:dynamicArrayProperties');
81 6
        $objWriter->writeAttribute('fDynamic', '1');
82 6
        $objWriter->writeAttribute('fCollapsed', '0');
83 6
        $objWriter->endElement(); // xda:dynamicArrayProperties
84 6
        $objWriter->endElement(); // ext
85 6
        $objWriter->endElement(); // extLst
86 6
        $objWriter->endElement(); // bk
87 6
        $objWriter->endElement(); // futureMetadata XLDAPR
88
89 6
        $objWriter->startElement('futureMetadata');
90 6
        $objWriter->writeAttribute('name', 'XLRICHVALUE');
91 6
        $objWriter->writeAttribute('count', '1');
92 6
        $objWriter->startElement('bk');
93 6
        $objWriter->startElement('extLst');
94 6
        $objWriter->startElement('ext');
95 6
        $objWriter->writeAttribute('uri', '{3e2802c4-a4d2-4d8b-9148-e3be6c30e623}');
96 6
        $objWriter->startElement('xlrd:rvb');
97 6
        $objWriter->writeAttribute('i', '0');
98 6
        $objWriter->endElement(); // xlrd:rvb
99 6
        $objWriter->endElement(); // ext
100 6
        $objWriter->endElement(); // extLst
101 6
        $objWriter->endElement(); // bk
102 6
        $objWriter->endElement(); // futureMetadata XLRICHVALUE
103
104 6
        $objWriter->startElement('cellMetadata');
105 6
        $objWriter->writeAttribute('count', '1');
106 6
        $objWriter->startElement('bk');
107 6
        $objWriter->startElement('rc');
108 6
        $objWriter->writeAttribute('t', '1');
109 6
        $objWriter->writeAttribute('v', '0');
110 6
        $objWriter->endElement(); // rc
111 6
        $objWriter->endElement(); // bk
112 6
        $objWriter->endElement(); // cellMetadata
113
114 6
        $objWriter->startElement('valueMetadata');
115 6
        $objWriter->writeAttribute('count', '1');
116 6
        $objWriter->startElement('bk');
117 6
        $objWriter->startElement('rc');
118 6
        $objWriter->writeAttribute('t', '2');
119 6
        $objWriter->writeAttribute('v', '0');
120 6
        $objWriter->endElement(); // rc
121 6
        $objWriter->endElement(); // bk
122 6
        $objWriter->endElement(); // valueMetadata
123
124 6
        $objWriter->endElement(); // metadata
125
126
        // Return
127 6
        return $objWriter->getData();
128
    }
129
}
130