Passed
Pull Request — master (#4266)
by Owen
23:18 queued 12:31
created

Styles::write()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 59
Code Lines 50

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 49
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 50
dl 0
loc 59
ccs 49
cts 50
cp 0.98
rs 9.0909
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2

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\Ods;
4
5
use PhpOffice\PhpSpreadsheet\Shared\XMLWriter;
6
7
class Styles extends WriterPart
8
{
9
    /**
10
     * Write styles.xml to XML format.
11
     *
12
     * @return string XML Output
13
     */
14 32
    public function write(): string
15
    {
16 32
        $objWriter = null;
17 32
        if ($this->getParentWriter()->getUseDiskCaching()) {
18
            $objWriter = new XMLWriter(XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
19
        } else {
20 32
            $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
21
        }
22
23
        // XML header
24 32
        $objWriter->startDocument('1.0', 'UTF-8');
25
26
        // Content
27 32
        $objWriter->startElement('office:document-styles');
28 32
        $objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
29 32
        $objWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
30 32
        $objWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
31 32
        $objWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
32 32
        $objWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
33 32
        $objWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
34 32
        $objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
35 32
        $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
36 32
        $objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
37 32
        $objWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
38 32
        $objWriter->writeAttribute('xmlns:presentation', 'urn:oasis:names:tc:opendocument:xmlns:presentation:1.0');
39 32
        $objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
40 32
        $objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
41 32
        $objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
42 32
        $objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
43 32
        $objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
44 32
        $objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
45 32
        $objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
46 32
        $objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
47 32
        $objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
48 32
        $objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
49 32
        $objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
50 32
        $objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
51 32
        $objWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
52 32
        $objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
53 32
        $objWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
54 32
        $objWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
55 32
        $objWriter->writeAttribute('office:version', '1.2');
56
57 32
        $objWriter->writeElement('office:font-face-decls');
58 32
        $objWriter->writeElement('office:styles');
59 32
        $objWriter->startElement('office:automatic-styles');
60 32
        $objWriter->startElement('style:page-layout');
61 32
        $objWriter->writeAttribute('style:name', 'Mpm1');
62 32
        $objWriter->endElement(); // style:page-layout
63 32
        $objWriter->endElement(); // office:automatic-styles
64 32
        $objWriter->startElement('office:master-styles');
65 32
        $objWriter->startElement('style:master-page');
66 32
        $objWriter->writeAttribute('style:name', 'Default');
67 32
        $objWriter->writeAttribute('style:page-layout-name', 'Mpm1');
68 32
        $objWriter->endElement(); //style:master-page
69 32
        $objWriter->endElement(); //office:master-styles
70 32
        $objWriter->endElement();
71
72 32
        return $objWriter->getData();
73
    }
74
}
75