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

PptPresentation::render()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 74
Code Lines 42

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 42
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 74
ccs 42
cts 42
cp 1
rs 8.6628
cc 4
eloc 42
nc 8
nop 0
crap 4

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
use PhpOffice\PhpPresentation\DocumentLayout;
7
use PhpOffice\PhpPresentation\Writer\PowerPoint2007\LayoutPack\PackDefault;
8
9
class PptPresentation extends AbstractDecoratorWriter
10
{
11 75
    public function render()
12
    {
13
        // Create XML writer
14 75
        $objWriter = new XMLWriter(XMLWriter::STORAGE_MEMORY);
15
16
        // XML header
17 75
        $objWriter->startDocument('1.0', 'UTF-8', 'yes');
18
19
        // p:presentation
20 75
        $objWriter->startElement('p:presentation');
21 75
        $objWriter->writeAttribute('xmlns:a', 'http://schemas.openxmlformats.org/drawingml/2006/main');
22 75
        $objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
23 75
        $objWriter->writeAttribute('xmlns:p', 'http://schemas.openxmlformats.org/presentationml/2006/main');
24
25
        // p:sldMasterIdLst
26 75
        $objWriter->startElement('p:sldMasterIdLst');
27
28
        // Add slide masters
29 75
        $relationId    = 1;
30 75
        $slideMasterId = 2147483648;
31 75
        $oLayoutPack = new PackDefault();
32 75
        $masterSlides  = $oLayoutPack->getMasterSlides();
33 75
        $masterSlidesCount = count($masterSlides);
34
        // @todo foreach ($masterSlides as $masterSlide)
35 75
        for ($i = 0; $i < $masterSlidesCount; $i++) {
36
            // p:sldMasterId
37 75
            $objWriter->startElement('p:sldMasterId');
38 75
            $objWriter->writeAttribute('id', $slideMasterId);
39 75
            $objWriter->writeAttribute('r:id', 'rId' . $relationId++);
40 75
            $objWriter->endElement();
41
42
            // Increase identifier
43 75
            $slideMasterId += 12;
44
        }
45 75
        $objWriter->endElement();
46
47
        // theme
48 75
        $relationId++;
49
50
        // p:sldIdLst
51 75
        $objWriter->startElement('p:sldIdLst');
52
        // Write slides
53 75
        $slideCount = $this->oPresentation->getSlideCount();
54 75
        for ($i = 0; $i < $slideCount; ++$i) {
55
            // p:sldId
56 75
            $objWriter->startElement('p:sldId');
57 75
            $objWriter->writeAttribute('id', ($i + 256));
58 75
            $objWriter->writeAttribute('r:id', 'rId' . ($i + $relationId));
59 75
            $objWriter->endElement();
60
        }
61 75
        $objWriter->endElement();
62
63
        // p:sldSz
64 75
        $objWriter->startElement('p:sldSz');
65 75
        $objWriter->writeAttribute('cx', $this->oPresentation->getLayout()->getCX());
66 75
        $objWriter->writeAttribute('cy', $this->oPresentation->getLayout()->getCY());
67 75
        if ($this->oPresentation->getLayout()->getDocumentLayout() != DocumentLayout::LAYOUT_CUSTOM) {
68 75
            $objWriter->writeAttribute('type', $this->oPresentation->getLayout()->getDocumentLayout());
69
        }
70 75
        $objWriter->endElement();
71
72
        // p:notesSz
73 75
        $objWriter->startElement('p:notesSz');
74 75
        $objWriter->writeAttribute('cx', '6858000');
75 75
        $objWriter->writeAttribute('cy', '9144000');
76 75
        $objWriter->endElement();
77
78 75
        $objWriter->endElement();
79
80 75
        $this->oZip->addFromString('ppt/presentation.xml', $objWriter->getData());
81
82
        // Return
83 75
        return $this->oZip;
84
    }
85
}
86