Completed
Pull Request — develop (#565)
by
unknown
07:15
created

DocPropsCore::render()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 61

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 29
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 61
ccs 29
cts 29
cp 1
rs 8.8509
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\PhpPresentation\Writer\PowerPoint2007;
4
5
use PhpOffice\Common\XMLWriter;
6
7
class DocPropsCore extends AbstractDecoratorWriter
8
{
9
    /**
10
     * @return \PhpOffice\Common\Adapter\Zip\ZipInterface
11
     * @throws \Exception
12
     */
13 113
    public function render()
14
    {
15
        // Create XML writer
16 113
        $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
17
18
        // XML header
19 113
        $objWriter->startDocument('1.0', 'UTF-8', 'yes');
20
21
        // cp:coreProperties
22 113
        $objWriter->startElement('cp:coreProperties');
23 113
        $objWriter->writeAttribute('xmlns:cp', 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties');
24 113
        $objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
25 113
        $objWriter->writeAttribute('xmlns:dcterms', 'http://purl.org/dc/terms/');
26 113
        $objWriter->writeAttribute('xmlns:dcmitype', 'http://purl.org/dc/dcmitype/');
27 113
        $objWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
28
29
        // dc:creator
30 113
        $objWriter->writeElement('dc:creator', $this->oPresentation->getDocumentProperties()->getCreator());
31
32
        // cp:lastModifiedBy
33 113
        $objWriter->writeElement('cp:lastModifiedBy', $this->oPresentation->getDocumentProperties()->getLastModifiedBy());
34
35
        // dcterms:created
36 113
        $objWriter->startElement('dcterms:created');
37 113
        $objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
38 113
        $objWriter->writeRaw(gmdate("Y-m-d\TH:i:s\Z", $this->oPresentation->getDocumentProperties()->getCreated()));
39 113
        $objWriter->endElement();
40
41
        // dcterms:modified
42 113
        $objWriter->startElement('dcterms:modified');
43 113
        $objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
44 113
        $objWriter->writeRaw(gmdate("Y-m-d\TH:i:s\Z", $this->oPresentation->getDocumentProperties()->getModified()));
45 113
        $objWriter->endElement();
46
47
        // dc:title
48 113
        $objWriter->writeElement('dc:title', $this->oPresentation->getDocumentProperties()->getTitle());
49
50
        // dc:description
51 113
        $objWriter->writeElement('dc:description', $this->oPresentation->getDocumentProperties()->getDescription());
52
53
        // dc:subject
54 113
        $objWriter->writeElement('dc:subject', $this->oPresentation->getDocumentProperties()->getSubject());
55
56
        // cp:keywords
57 113
        $objWriter->writeElement('cp:keywords', $this->oPresentation->getDocumentProperties()->getKeywords());
58
59
        // cp:category
60 113
        $objWriter->writeElement('cp:category', $this->oPresentation->getDocumentProperties()->getCategory());
61
62 113
        if ($this->oPresentation->getPresentationProperties()->isMarkedAsFinal()) {
63
            // cp:contentStatus = Final
64 2
            $objWriter->writeElement('cp:contentStatus', 'Final');
65
        }
66
67 113
        $objWriter->endElement();
68
69 113
        $this->oZip->addFromString('docProps/core.xml', $objWriter->getData());
70
71
        // Return
72 113
        return $this->oZip;
73
    }
74
}
75