Completed
Pull Request — develop (#186)
by
unknown
07:55
created

DocPropsCore::render()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 61
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 29
CRAP Score 2

Importance

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