diff --git a/src/PhpWord/Element/AbstractContainer.php b/src/PhpWord/Element/AbstractContainer.php index 39193031..6caa0056 100644 --- a/src/PhpWord/Element/AbstractContainer.php +++ b/src/PhpWord/Element/AbstractContainer.php @@ -35,7 +35,7 @@ abstract class AbstractContainer extends AbstractElement protected $elements = array(); /** - * Container type section|header|footer|footnote|endnote|cell|textrun|textbox + * Container type Section|Header|Footer|Footnote|Endnote|Cell|TextRun|TextBox|ListItemRun * * @var string */ @@ -63,9 +63,7 @@ abstract class AbstractContainer extends AbstractElement } // Create element - if ($argsCount == 1) { // Page Break - $element = new $elementClass(); - } elseif ($argsCount == 2) { // TextRun, TextBox, Table, Footnote, Endnote + if ($argsCount == 2) { // TextRun, TextBox, Table, Footnote, Endnote $element = new $elementClass($args[1]); } elseif ($argsCount == 3) { // Object, TextBreak, Title $element = new $elementClass($args[1], $args[2]); @@ -75,11 +73,13 @@ abstract class AbstractContainer extends AbstractElement $element = new $elementClass($args[1], $args[2], $args[3], $args[4]); } elseif ($argsCount == 6) { // ListItem $element = new $elementClass($args[1], $args[2], $args[3], $args[4], $args[5]); + } else { // Page Break + $element = new $elementClass(); } // Set relation Id for media collection + $mediaContainer = $this->getMediaContainer(); if (in_array($elementName, array('Link', 'Image', 'Object'))) { - $mediaContainer = $this->getMediaContainer(); if ($elementName == 'Image') { $rId = Media::addElement($mediaContainer, strtolower($elementName), $args[1], $element); } else { @@ -228,7 +228,6 @@ abstract class AbstractContainer extends AbstractElement * * @param mixed $style * @return \PhpOffice\PhpWord\Element\Table - * @todo Merge with the same function on Footer */ public function addTable($style = null) { diff --git a/src/PhpWord/Writer/HTML/Element/Footnote.php b/src/PhpWord/Writer/HTML/Element/Footnote.php index 30398b17..ba5ced56 100644 --- a/src/PhpWord/Writer/HTML/Element/Footnote.php +++ b/src/PhpWord/Writer/HTML/Element/Footnote.php @@ -41,12 +41,14 @@ class Footnote extends AbstractElement if (!$this->element instanceof \PhpOffice\PhpWord\Element\Footnote) { return; } + /** @var \PhpOffice\PhpWord\Writer\HTML $parentWriter Scrutinizer type hint */ + $parentWriter = $this->parentWriter; - $noteId = count($this->parentWriter->getNotes()) + 1; + $noteId = count($parentWriter->getNotes()) + 1; $noteMark = $this->noteType . '-' . $this->element->getRelationId(); $content = "{$noteId}"; - $this->parentWriter->addNote($noteId, $noteMark); + $parentWriter->addNote($noteId, $noteMark); return $content; } diff --git a/src/PhpWord/Writer/HTML/Element/Image.php b/src/PhpWord/Writer/HTML/Element/Image.php index 5c2edbb2..1d07acd7 100644 --- a/src/PhpWord/Writer/HTML/Element/Image.php +++ b/src/PhpWord/Writer/HTML/Element/Image.php @@ -37,9 +37,11 @@ class Image extends Text if (!$this->element instanceof \PhpOffice\PhpWord\Element\Image) { return; } + /** @var \PhpOffice\PhpWord\Writer\HTML $parentWriter Scrutinizer type hint */ + $parentWriter = $this->parentWriter; $content = ''; - if (!$this->parentWriter->isPdf()) { + if (!$parentWriter->isPdf()) { $imageData = $this->getBase64ImageData($this->element); if (!is_null($imageData)) { $styleWriter = new ImageStyleWriter($this->element->getStyle()); diff --git a/src/PhpWord/Writer/HTML/Element/Text.php b/src/PhpWord/Writer/HTML/Element/Text.php index 883a8cd3..8ace129c 100644 --- a/src/PhpWord/Writer/HTML/Element/Text.php +++ b/src/PhpWord/Writer/HTML/Element/Text.php @@ -64,12 +64,14 @@ class Text extends AbstractElement */ public function write() { + /** @var \PhpOffice\PhpWord\Element\Text $element Scrutinizer type hint */ + $element = $this->element; $this->getFontStyle(); $content = ''; $content .= $this->writeOpening(); $content .= $this->openingTags; - $content .= htmlspecialchars($this->element->getText()); + $content .= htmlspecialchars($element->getText()); $content .= $this->closingTags; $content .= $this->closingText; $content .= $this->writeClosing(); @@ -140,12 +142,14 @@ class Text extends AbstractElement */ private function getParagraphStyle() { + /** @var \PhpOffice\PhpWord\Element\Text $element Scrutinizer type hint */ + $element = $this->element; $style = ''; - if (method_exists($this->element, 'getParagraphStyle')) { + if (method_exists($element, 'getParagraphStyle')) { return $style; } - $paragraphStyle = $this->element->getParagraphStyle(); + $paragraphStyle = $element->getParagraphStyle(); $pStyleIsObject = ($paragraphStyle instanceof Paragraph); if ($pStyleIsObject) { $styleWriter = new ParagraphStyleWriter($paragraphStyle); @@ -164,8 +168,10 @@ class Text extends AbstractElement */ private function getFontStyle() { + /** @var \PhpOffice\PhpWord\Element\Text $element Scrutinizer type hint */ + $element = $this->element; $style = ''; - $fontStyle = $this->element->getFontStyle(); + $fontStyle = $element->getFontStyle(); $fStyleIsObject = ($fontStyle instanceof Font); if ($fStyleIsObject) { $styleWriter = new FontStyleWriter($fontStyle); diff --git a/src/PhpWord/Writer/HTML/Style/Image.php b/src/PhpWord/Writer/HTML/Style/Image.php index fcf18395..db6ac57b 100644 --- a/src/PhpWord/Writer/HTML/Style/Image.php +++ b/src/PhpWord/Writer/HTML/Style/Image.php @@ -37,8 +37,10 @@ class Image extends AbstractStyle } $css = array(); - $css['width'] = $this->getValueIf($style->getWidth(), $style->getWidth() . 'px'); - $css['height'] = $this->getValueIf($style->getHeight(), $style->getHeight() . 'px'); + $width = $style->getWidth(); + $height = $style->getHeight(); + $css['width'] = $this->getValueIf(is_numeric($width), $width . 'px'); + $css['height'] = $this->getValueIf(is_numeric($height), $height . 'px'); return $this->assembleCss($css); } diff --git a/src/PhpWord/Writer/RTF/Element/Text.php b/src/PhpWord/Writer/RTF/Element/Text.php index 701a5be1..27172df3 100644 --- a/src/PhpWord/Writer/RTF/Element/Text.php +++ b/src/PhpWord/Writer/RTF/Element/Text.php @@ -39,12 +39,15 @@ class Text extends AbstractElement return; } + /** @var \PhpOffice\PhpWord\Style\Font $fontStyle Scrutinizer type hint */ $fontStyle = $this->getFontStyle($this->element); + /** @var \PhpOffice\PhpWord\Writer\RTF $parentWriter Scrutinizer type hint */ + $parentWriter = $this->parentWriter; $content = ''; $content .= $this->writeParagraphStyle($this->element); $content .= $this->writeFontStyleBegin($fontStyle); - if ($this->parentWriter->getLastParagraphStyle() != '' || $fontStyle) { + if ($parentWriter->getLastParagraphStyle() != '' || $fontStyle) { $content .= ' '; } $content .= $this->element->getText(); @@ -64,6 +67,8 @@ class Text extends AbstractElement */ private function writeParagraphStyle(TextElement $element) { + /** @var \PhpOffice\PhpWord\Writer\RTF $parentWriter Scrutinizer type hint */ + $parentWriter = $this->parentWriter; $content = ''; // Get paragraph style @@ -74,15 +79,15 @@ class Text extends AbstractElement // Write style when applicable if ($paragraphStyle && !$this->withoutP) { - if ($this->parentWriter->getLastParagraphStyle() != $element->getParagraphStyle()) { + if ($parentWriter->getLastParagraphStyle() != $element->getParagraphStyle()) { $styleWriter = new ParagraphStyleWriter($paragraphStyle); $content = $styleWriter->write(); - $this->parentWriter->setLastParagraphStyle($element->getParagraphStyle()); + $parentWriter->setLastParagraphStyle($element->getParagraphStyle()); } else { - $this->parentWriter->setLastParagraphStyle(); + $parentWriter->setLastParagraphStyle(); } } else { - $this->parentWriter->setLastParagraphStyle(); + $parentWriter->setLastParagraphStyle(); } return $content; @@ -91,7 +96,7 @@ class Text extends AbstractElement /** * Write font style beginning * - * @param \PhpOffice\PhpWord\Style\Font $style + * @param mixed $style * @return string */ private function writeFontStyleBegin($style) @@ -100,16 +105,19 @@ class Text extends AbstractElement return ''; } + /** @var \PhpOffice\PhpWord\Writer\RTF $parentWriter Scrutinizer type hint */ + $parentWriter = $this->parentWriter; + // Create style writer and set color/name index $styleWriter = new FontStyleWriter($style); if ($style->getColor() != null) { - $colorIndex = array_search($style->getColor(), $this->parentWriter->getColorTable()); + $colorIndex = array_search($style->getColor(), $parentWriter->getColorTable()); if ($colorIndex !== false) { $styleWriter->setColorIndex($colorIndex + 1); } } if ($style->getName() != null) { - $fontIndex = array_search($style->getName(), $this->parentWriter->getFontTable()); + $fontIndex = array_search($style->getName(), $parentWriter->getFontTable()); if ($fontIndex !== false) { $styleWriter->setNameIndex($fontIndex + 1); } diff --git a/src/PhpWord/Writer/RTF/Element/TextBreak.php b/src/PhpWord/Writer/RTF/Element/TextBreak.php index 760f34e8..ff836a88 100644 --- a/src/PhpWord/Writer/RTF/Element/TextBreak.php +++ b/src/PhpWord/Writer/RTF/Element/TextBreak.php @@ -31,7 +31,9 @@ class TextBreak extends AbstractElement */ public function write() { - $this->parentWriter->setLastParagraphStyle(); + /** @var \PhpOffice\PhpWord\Writer\RTF $parentWriter Scrutinizer type hint */ + $parentWriter = $this->parentWriter; + $parentWriter->setLastParagraphStyle(); return '\par' . PHP_EOL; } diff --git a/src/PhpWord/Writer/RTF/Style/Font.php b/src/PhpWord/Writer/RTF/Style/Font.php index 5c14eb3a..49c9889c 100644 --- a/src/PhpWord/Writer/RTF/Style/Font.php +++ b/src/PhpWord/Writer/RTF/Style/Font.php @@ -53,7 +53,9 @@ class Font extends AbstractStyle $content .= '\f' . $this->nameIndex; $content .= $this->getValueIf($style->isBold(), '\b'); $content .= $this->getValueIf($style->isItalic(), '\i'); - $content .= $this->getValueIf($style->getSize(), '\fs' . ($style->getSize() * 2)); + + $size = $style->getSize(); + $content .= $this->getValueIf(is_numeric($size), '\fs' . ($size * 2)); return $content; } @@ -75,7 +77,9 @@ class Font extends AbstractStyle $content .= '\f0'; $content .= $this->getValueIf($style->isBold(), '\b0'); $content .= $this->getValueIf($style->isItalic(), '\i0'); - $content .= $this->getValueIf($style->getSize(), '\fs' . (PhpWord::DEFAULT_FONT_SIZE * 2)); + + $size = $style->getSize(); + $content .= $this->getValueIf(is_numeric($size), '\fs' . (PhpWord::DEFAULT_FONT_SIZE * 2)); return $content; } diff --git a/src/PhpWord/Writer/Word2007/Element/Text.php b/src/PhpWord/Writer/Word2007/Element/Text.php index 1385e6e6..e06bde6b 100644 --- a/src/PhpWord/Writer/Word2007/Element/Text.php +++ b/src/PhpWord/Writer/Word2007/Element/Text.php @@ -92,8 +92,9 @@ class Text extends AbstractElement protected function writeParagraphStyle() { $xmlWriter = $this->getXmlWriter(); - $element = $this->getElement(); + /** @var \PhpOffice\PhpWord\Element\Text $element Scrutinizer type hint */ + $element = $this->getElement(); $paragraphStyle = $element->getParagraphStyle(); $styleWriter = new ParagraphStyleWriter($xmlWriter, $paragraphStyle); $styleWriter->setIsInline(true); @@ -106,8 +107,9 @@ class Text extends AbstractElement protected function writeFontStyle() { $xmlWriter = $this->getXmlWriter(); - $element = $this->getElement(); + /** @var \PhpOffice\PhpWord\Element\Text $element Scrutinizer type hint */ + $element = $this->getElement(); $fontStyle = $element->getFontStyle(); $styleWriter = new FontStyleWriter($xmlWriter, $fontStyle); $styleWriter->setIsInline(true); diff --git a/src/PhpWord/Writer/Word2007/Part/ContentTypes.php b/src/PhpWord/Writer/Word2007/Part/ContentTypes.php index 3af62a44..417df64d 100644 --- a/src/PhpWord/Writer/Word2007/Part/ContentTypes.php +++ b/src/PhpWord/Writer/Word2007/Part/ContentTypes.php @@ -32,7 +32,9 @@ class ContentTypes extends AbstractPart */ public function write() { - $contentTypes = $this->getParentWriter()->getContentTypes(); + /** @var \PhpOffice\PhpWord\Writer\Word2007 $parentWriter Scrutinizer type hint */ + $parentWriter = $this->getParentWriter(); + $contentTypes = $parentWriter->getContentTypes(); $openXMLPrefix = 'application/vnd.openxmlformats-'; $wordMLPrefix = $openXMLPrefix . 'officedocument.wordprocessingml.'; diff --git a/src/PhpWord/Writer/Word2007/Part/Footnotes.php b/src/PhpWord/Writer/Word2007/Part/Footnotes.php index 1eeabc9c..d7a1caaa 100644 --- a/src/PhpWord/Writer/Word2007/Part/Footnotes.php +++ b/src/PhpWord/Writer/Word2007/Part/Footnotes.php @@ -106,8 +106,9 @@ class Footnotes extends AbstractPart $xmlWriter->endElement(); // w:p $xmlWriter->endElement(); // $this->elementNode - // Content - foreach ($this->elements as $element) { + /** @var array $elements Scrutinizer type hint */ + $elements = $this->elements; + foreach ($elements as $element) { if ($element instanceof Footnote) { $this->writeNote($xmlWriter, $element); } diff --git a/src/PhpWord/Writer/Word2007/Part/RelsDocument.php b/src/PhpWord/Writer/Word2007/Part/RelsDocument.php index e0773a4a..2a58421c 100644 --- a/src/PhpWord/Writer/Word2007/Part/RelsDocument.php +++ b/src/PhpWord/Writer/Word2007/Part/RelsDocument.php @@ -40,7 +40,10 @@ class RelsDocument extends Rels 'fontTable.xml' => 'officeDocument/2006/relationships/fontTable', ); $xmlWriter = $this->getXmlWriter(); - $this->writeRels($xmlWriter, $xmlRels, $this->getParentWriter()->getRelationships()); + + /** @var \PhpOffice\PhpWord\Writer\Word2007 $parentWriter Scrutinizer type hint */ + $parentWriter = $this->getParentWriter(); + $this->writeRels($xmlWriter, $xmlRels, $parentWriter->getRelationships()); return $xmlWriter->getData(); } diff --git a/src/PhpWord/Writer/Word2007/Part/Settings.php b/src/PhpWord/Writer/Word2007/Part/Settings.php index 862e419e..c296581f 100644 --- a/src/PhpWord/Writer/Word2007/Part/Settings.php +++ b/src/PhpWord/Writer/Word2007/Part/Settings.php @@ -126,6 +126,8 @@ class Settings extends AbstractPart $xmlWriter->writeElement($settingKey); } else { $xmlWriter->startElement($settingKey); + + /** @var array $settingValue Scrutinizer type hint */ foreach ($settingValue as $childKey => $childValue) { if ($childKey == '@attributes') { foreach ($childValue as $key => $val) {