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