From 04a62f3255a9d99670cd70ed4dae08ae29e46daa Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Wed, 14 May 2014 19:41:44 +0700 Subject: [PATCH] QA: Code cleanup and some additional tests --- src/PhpWord/DocumentProperties.php | 6 ++- src/PhpWord/Element/AbstractContainer.php | 4 ++ src/PhpWord/Element/AbstractElement.php | 1 + src/PhpWord/Element/Image.php | 2 + src/PhpWord/Element/Object.php | 1 + src/PhpWord/Element/PreserveText.php | 2 +- src/PhpWord/Element/Section.php | 1 - src/PhpWord/PhpWord.php | 6 +-- src/PhpWord/Reader/ODText/AbstractPart.php | 2 + src/PhpWord/Reader/Word2007/AbstractPart.php | 12 ++++-- src/PhpWord/Reader/Word2007/Document.php | 8 ++++ src/PhpWord/Reader/Word2007/Numbering.php | 2 + src/PhpWord/Shared/Html.php | 6 ++- src/PhpWord/Shared/XMLReader.php | 7 ++++ src/PhpWord/Shared/ZipArchive.php | 6 ++- src/PhpWord/Style.php | 6 +-- src/PhpWord/Style/AbstractStyle.php | 5 +++ src/PhpWord/Style/Cell.php | 2 + src/PhpWord/Style/Font.php | 2 + src/PhpWord/Style/Paragraph.php | 13 +++++- src/PhpWord/Style/Section.php | 2 +- src/PhpWord/Writer/AbstractWriter.php | 2 + src/PhpWord/Writer/HTML.php | 2 +- .../Writer/HTML/Element/AbstractElement.php | 2 + src/PhpWord/Writer/HTML/Element/Container.php | 2 +- src/PhpWord/Writer/HTML/Element/Footnote.php | 4 +- src/PhpWord/Writer/HTML/Element/Image.php | 5 ++- src/PhpWord/Writer/HTML/Element/Link.php | 2 +- src/PhpWord/Writer/HTML/Element/ListItem.php | 2 +- src/PhpWord/Writer/HTML/Element/Table.php | 2 +- src/PhpWord/Writer/HTML/Element/Text.php | 8 ++-- src/PhpWord/Writer/HTML/Element/Title.php | 2 +- .../Writer/HTML/Style/AbstractStyle.php | 2 +- src/PhpWord/Writer/HTML/Style/Font.php | 2 +- src/PhpWord/Writer/HTML/Style/Image.php | 2 +- src/PhpWord/Writer/HTML/Style/Paragraph.php | 2 +- src/PhpWord/Writer/ODText/Element/Text.php | 2 + .../Writer/ODText/Part/AbstractPart.php | 2 +- src/PhpWord/Writer/ODText/Part/Content.php | 2 +- src/PhpWord/Writer/ODText/Part/Meta.php | 2 - src/PhpWord/Writer/PDF.php | 2 + src/PhpWord/Writer/PDF/AbstractRenderer.php | 3 ++ src/PhpWord/Writer/PDF/DomPDF.php | 1 + src/PhpWord/Writer/RTF.php | 2 +- .../Writer/RTF/Element/AbstractElement.php | 16 ++++---- src/PhpWord/Writer/RTF/Element/Link.php | 2 +- src/PhpWord/Writer/RTF/Element/Text.php | 4 +- src/PhpWord/Writer/RTF/Element/TextBreak.php | 2 +- src/PhpWord/Writer/RTF/Element/TextRun.php | 2 - .../Writer/RTF/Style/AbstractStyle.php | 2 - src/PhpWord/Writer/RTF/Style/Font.php | 3 +- src/PhpWord/Writer/RTF/Style/Paragraph.php | 2 +- src/PhpWord/Writer/Word2007.php | 2 + .../Word2007/Element/AbstractElement.php | 9 ++-- src/PhpWord/Writer/Word2007/Element/TOC.php | 8 +++- src/PhpWord/Writer/Word2007/Element/Text.php | 4 +- .../Writer/Word2007/Part/ContentTypes.php | 18 ++++---- .../Writer/Word2007/Part/DocPropsApp.php | 2 - .../Writer/Word2007/Part/DocPropsCore.php | 2 - src/PhpWord/Writer/Word2007/Part/Document.php | 1 - .../Writer/Word2007/Part/Footnotes.php | 2 +- .../Writer/Word2007/Part/Numbering.php | 2 +- src/PhpWord/Writer/Word2007/Part/Rels.php | 1 + .../Writer/Word2007/Part/RelsDocument.php | 2 +- src/PhpWord/Writer/Word2007/Part/Settings.php | 2 +- src/PhpWord/Writer/Word2007/Part/Styles.php | 3 +- .../Writer/Word2007/Style/AbstractStyle.php | 1 + src/PhpWord/Writer/Word2007/Style/Image.php | 1 + .../Writer/Word2007/Style/MarginBorder.php | 1 + src/PhpWord/Writer/Word2007/Style/Table.php | 1 + .../PhpWord/Tests/Writer/HTML/ElementTest.php | 10 ++--- tests/PhpWord/Tests/Writer/HTMLTest.php | 1 + .../Tests/Writer/ODText/ElementTest.php | 10 ++--- .../PhpWord/Tests/Writer/RTF/ElementTest.php | 10 ++--- tests/PhpWord/Tests/Writer/RTFTest.php | 2 +- .../Tests/Writer/Word2007/ElementTest.php | 10 ++--- .../Writer/Word2007/Part/DocumentTest.php | 17 ++++++-- .../Tests/Writer/Word2007/PartTest.php | 41 +++++++++++++++++++ 78 files changed, 234 insertions(+), 115 deletions(-) create mode 100644 tests/PhpWord/Tests/Writer/Word2007/PartTest.php diff --git a/src/PhpWord/DocumentProperties.php b/src/PhpWord/DocumentProperties.php index a2d869b0..17d57c1d 100644 --- a/src/PhpWord/DocumentProperties.php +++ b/src/PhpWord/DocumentProperties.php @@ -416,8 +416,9 @@ class DocumentProperties { if ($this->isCustomPropertySet($propertyName)) { return $this->customProperties[$propertyName]['value']; + } else { + return null; } - } /** @@ -430,8 +431,9 @@ class DocumentProperties { if ($this->isCustomPropertySet($propertyName)) { return $this->customProperties[$propertyName]['type']; + } else { + return null; } - } /** diff --git a/src/PhpWord/Element/AbstractContainer.php b/src/PhpWord/Element/AbstractContainer.php index 6caa0056..5afddc5f 100644 --- a/src/PhpWord/Element/AbstractContainer.php +++ b/src/PhpWord/Element/AbstractContainer.php @@ -313,6 +313,7 @@ abstract class AbstractContainer extends AbstractElement * * @param string $method * @return bool + * @throws \BadMethodCallException */ private function checkValidity($method) { @@ -389,6 +390,7 @@ abstract class AbstractContainer extends AbstractElement * * @param string $src * @param mixed $style + * @return \PhpOffice\PhpWord\Element\Image * @deprecated 0.9.0 * @codeCoverageIgnore */ @@ -401,6 +403,7 @@ abstract class AbstractContainer extends AbstractElement * Create textrun element * * @param mixed $paragraphStyle + * @return \PhpOffice\PhpWord\Element\TextRun * @deprecated 0.10.0 * @codeCoverageIgnore */ @@ -413,6 +416,7 @@ abstract class AbstractContainer extends AbstractElement * Create footnote element * * @param mixed $paragraphStyle + * @return \PhpOffice\PhpWord\Element\Footnote * @deprecated 0.10.0 * @codeCoverageIgnore */ diff --git a/src/PhpWord/Element/AbstractElement.php b/src/PhpWord/Element/AbstractElement.php index 40e65c12..45311364 100644 --- a/src/PhpWord/Element/AbstractElement.php +++ b/src/PhpWord/Element/AbstractElement.php @@ -220,6 +220,7 @@ abstract class AbstractElement * @param mixed $styleObject Style object * @param mixed $styleValue Style value * @param bool $returnObject Always return object + * @return mixed */ protected function setStyle($styleObject, $styleValue = null, $returnObject = false) { diff --git a/src/PhpWord/Element/Image.php b/src/PhpWord/Element/Image.php index 6cfd6176..44829ba5 100644 --- a/src/PhpWord/Element/Image.php +++ b/src/PhpWord/Element/Image.php @@ -283,6 +283,8 @@ class Image extends AbstractElement * Check memory image, supported type, image functions, and proportional width/height * * @param string $source + * @throws \PhpOffice\PhpWord\Exception\InvalidImageException + * @throws \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException */ private function checkImage($source) { diff --git a/src/PhpWord/Element/Object.php b/src/PhpWord/Element/Object.php index a87da019..a63c1869 100644 --- a/src/PhpWord/Element/Object.php +++ b/src/PhpWord/Element/Object.php @@ -58,6 +58,7 @@ class Object extends AbstractElement * * @param string $source * @param mixed $style + * @throws \PhpOffice\PhpWord\Exception\InvalidObjectException */ public function __construct($source, $style = null) { diff --git a/src/PhpWord/Element/PreserveText.php b/src/PhpWord/Element/PreserveText.php index 004ffbc3..100385c9 100644 --- a/src/PhpWord/Element/PreserveText.php +++ b/src/PhpWord/Element/PreserveText.php @@ -54,7 +54,7 @@ class PreserveText extends AbstractElement * @param string $text * @param mixed $fontStyle * @param mixed $paragraphStyle - * @return $this + * @return self */ public function __construct($text = null, $fontStyle = null, $paragraphStyle = null) { diff --git a/src/PhpWord/Element/Section.php b/src/PhpWord/Element/Section.php index 8a2b474f..cfa101cf 100644 --- a/src/PhpWord/Element/Section.php +++ b/src/PhpWord/Element/Section.php @@ -18,7 +18,6 @@ namespace PhpOffice\PhpWord\Element; use PhpOffice\PhpWord\Exception\Exception; -use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Style\Section as SectionSettings; /** diff --git a/src/PhpWord/PhpWord.php b/src/PhpWord/PhpWord.php index 50890ad3..a56578b0 100644 --- a/src/PhpWord/PhpWord.php +++ b/src/PhpWord/PhpWord.php @@ -301,13 +301,13 @@ class PhpWord /** * Adds a heading style definition to styles.xml * - * @param int $titleCount + * @param int $depth * @param mixed $fontStyle * @param mixed $paragraphStyle */ - public function addTitleStyle($titleCount, $fontStyle, $paragraphStyle = null) + public function addTitleStyle($depth, $fontStyle, $paragraphStyle = null) { - Style::addTitleStyle($titleCount, $fontStyle, $paragraphStyle); + Style::addTitleStyle($depth, $fontStyle, $paragraphStyle); } /** diff --git a/src/PhpWord/Reader/ODText/AbstractPart.php b/src/PhpWord/Reader/ODText/AbstractPart.php index 8ffb9f1b..44884922 100644 --- a/src/PhpWord/Reader/ODText/AbstractPart.php +++ b/src/PhpWord/Reader/ODText/AbstractPart.php @@ -27,6 +27,8 @@ abstract class AbstractPart extends \PhpOffice\PhpWord\Reader\Word2007\AbstractP /** * Read w:r (override) * + * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader + * @param \DOMElement $domNode * @param mixed $parent * @param string $docPart * @param mixed $paragraphStyle diff --git a/src/PhpWord/Reader/Word2007/AbstractPart.php b/src/PhpWord/Reader/Word2007/AbstractPart.php index a6efb329..34088b17 100644 --- a/src/PhpWord/Reader/Word2007/AbstractPart.php +++ b/src/PhpWord/Reader/Word2007/AbstractPart.php @@ -138,12 +138,14 @@ abstract class AbstractPart /** * Read w:pPr * + * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader + * @param \DOMElement $domNode * @return array|null */ protected function readParagraphStyle(XMLReader $xmlReader, \DOMElement $domNode) { if (!$xmlReader->elementExists('w:pPr', $domNode)) { - return; + return ''; } $style = array(); @@ -200,19 +202,21 @@ abstract class AbstractPart /** * Read w:rPr * + * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader + * @param \DOMElement $domNode * @return array|null */ protected function readFontStyle(XMLReader $xmlReader, \DOMElement $domNode) { if (is_null($domNode)) { - return; + return null; } // Hyperlink has an extra w:r child if ($domNode->nodeName == 'w:hyperlink') { $domNode = $xmlReader->getElement('w:r', $domNode); } if (!$xmlReader->elementExists('w:rPr', $domNode)) { - return; + return null; } $style = array(); @@ -272,6 +276,8 @@ abstract class AbstractPart /** * Read w:tblPr * + * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader + * @param \DOMElement $domNode * @return string|array|null * @todo Capture w:tblStylePr w:type="firstRow" */ diff --git a/src/PhpWord/Reader/Word2007/Document.php b/src/PhpWord/Reader/Word2007/Document.php index d38b3fb9..52456cf7 100644 --- a/src/PhpWord/Reader/Word2007/Document.php +++ b/src/PhpWord/Reader/Word2007/Document.php @@ -121,6 +121,8 @@ class Document extends AbstractPart /** * Read w:p * + * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader + * @param \DOMElement $domNode * @param mixed $parent * @param string $docPart * @@ -209,6 +211,8 @@ class Document extends AbstractPart /** * Read w:tbl * + * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader + * @param \DOMElement $domNode * @param mixed $parent * @param string $docPart */ @@ -266,6 +270,8 @@ class Document extends AbstractPart /** * Read w:sectPr * + * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader + * @param \DOMElement $domNode * @return array|null */ private function readSectionStyle(XMLReader $xmlReader, \DOMElement $domNode) @@ -326,6 +332,8 @@ class Document extends AbstractPart /** * Read w:tcPr * + * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader + * @param \DOMElement $domNode * @return array|null */ private function readCellStyle(XMLReader $xmlReader, \DOMElement $domNode) diff --git a/src/PhpWord/Reader/Word2007/Numbering.php b/src/PhpWord/Reader/Word2007/Numbering.php index 68a36d57..81939ae8 100644 --- a/src/PhpWord/Reader/Word2007/Numbering.php +++ b/src/PhpWord/Reader/Word2007/Numbering.php @@ -87,6 +87,8 @@ class Numbering extends AbstractPart /** * Read numbering level definition from w:abstractNum and w:num * + * @param \PhpOffice\PhpWord\Shared\XMLReader $xmlReader + * @param \DOMElement $subnode * @param integer $levelId * @return array */ diff --git a/src/PhpWord/Shared/Html.php b/src/PhpWord/Shared/Html.php index 78f1d99d..501d2404 100644 --- a/src/PhpWord/Shared/Html.php +++ b/src/PhpWord/Shared/Html.php @@ -52,6 +52,7 @@ class Html * * @param \DOMNode $node Node to check on attributes and to compile a style array * @param array $style is supplied, the inline style attributes are added to the already existing style + * @return array */ protected static function parseInlineStyle($node, $style = array()) { @@ -91,6 +92,7 @@ class Html } } } + return $style; } @@ -173,7 +175,7 @@ class Html // } break; case 'tr': - /** @var \PhpOffice\PhpWord\Element\Table $object Scrutinizer type hint */ + /** @var \PhpOffice\PhpWord\Element\Table $object Type hint */ $styles['paragraphStyle'] = self::parseInlineStyle($node, $styles['paragraphStyle']); $newobject = $object->addRow(); // if ($attributes->getNamedItem('height') !== null) { @@ -181,7 +183,7 @@ class Html // } break; case 'td': - /** @var \PhpOffice\PhpWord\Element\Row $object Scrutinizer type hint */ + /** @var \PhpOffice\PhpWord\Element\Row $object Type hint */ $styles['paragraphStyle'] = self::parseInlineStyle($node, $styles['paragraphStyle']); // if ($attributes->getNamedItem('width') !== null) { // $newobject=$object->addCell($width=$attributes->getNamedItem('width')->value); diff --git a/src/PhpWord/Shared/XMLReader.php b/src/PhpWord/Shared/XMLReader.php index 1b9553cb..6b118c56 100644 --- a/src/PhpWord/Shared/XMLReader.php +++ b/src/PhpWord/Shared/XMLReader.php @@ -47,6 +47,7 @@ class XMLReader * @param string $zipFile * @param string $xmlFile * @return \DOMDocument|false + * @throws \PhpOffice\PhpWord\Exception\Exception */ public function getDomFromZip($zipFile, $xmlFile) { @@ -76,6 +77,7 @@ class XMLReader * Get elements * * @param string $path + * @param \DOMElement $contextNode * @return \DOMNodeList */ public function getElements($path, \DOMElement $contextNode = null) @@ -94,6 +96,7 @@ class XMLReader * Get element * * @param string $path + * @param \DOMElement $contextNode * @return \DOMElement|null */ public function getElement($path, \DOMElement $contextNode = null) @@ -110,6 +113,7 @@ class XMLReader * Get element attribute * * @param string $attribute + * @param \DOMElement $contextNode * @param string $path * @return string|null */ @@ -134,6 +138,7 @@ class XMLReader * Get element value * * @param string $path + * @param \DOMElement $contextNode * @return string|null */ public function getValue($path, \DOMElement $contextNode = null) @@ -150,6 +155,7 @@ class XMLReader * Count elements * * @param string $path + * @param \DOMElement $contextNode * @return integer */ public function countElements($path, \DOMElement $contextNode = null) @@ -163,6 +169,7 @@ class XMLReader * Element exists * * @param string $path + * @param \DOMElement $contextNode * @return boolean */ public function elementExists($path, \DOMElement $contextNode = null) diff --git a/src/PhpWord/Shared/ZipArchive.php b/src/PhpWord/Shared/ZipArchive.php index 8c9f10b8..84d6ab85 100644 --- a/src/PhpWord/Shared/ZipArchive.php +++ b/src/PhpWord/Shared/ZipArchive.php @@ -84,8 +84,9 @@ class ZipArchive /** * Add a new file to the zip archive (emulate \ZipArchive) * - * @param string $filename Directory/Name of the file to add to the zip archive + * @param string $filename Directory/Name of the file to add to the zip archive * @param string $localname Directory/Name of the file added to the zip + * @return bool */ public function addFile($filename, $localname = null) { @@ -117,7 +118,8 @@ class ZipArchive * Add a new file to the zip archive from a string of raw data (emulate \ZipArchive) * * @param string $localname Directory/Name of the file to add to the zip archive - * @param string $contents String of data to add to the zip archive + * @param string $contents String of data to add to the zip archive + * @return bool */ public function addFromString($localname, $contents) { diff --git a/src/PhpWord/Style.php b/src/PhpWord/Style.php index 25e5785b..ef3310d7 100644 --- a/src/PhpWord/Style.php +++ b/src/PhpWord/Style.php @@ -83,13 +83,13 @@ class Style /** * Add title style * - * @param int $titleCount + * @param int $depth * @param array $fontStyle * @param array $paragraphStyle */ - public static function addTitleStyle($titleCount, $fontStyle, $paragraphStyle = null) + public static function addTitleStyle($depth, $fontStyle, $paragraphStyle = null) { - self::setStyleValues("Heading_{$titleCount}", new Font('title', $paragraphStyle), $fontStyle); + self::setStyleValues("Heading_{$depth}", new Font('title', $paragraphStyle), $fontStyle); } /** diff --git a/src/PhpWord/Style/AbstractStyle.php b/src/PhpWord/Style/AbstractStyle.php index 5be042bd..0ac71ab2 100644 --- a/src/PhpWord/Style/AbstractStyle.php +++ b/src/PhpWord/Style/AbstractStyle.php @@ -227,6 +227,8 @@ abstract class AbstractStyle * @param mixed $value * @param array $enum * @param mixed $default + * @return mixed + * @throws \InvalidArgumentException */ protected function setEnumVal($value = null, $enum = array(), $default = null) { @@ -245,11 +247,13 @@ abstract class AbstractStyle * @param mixed $value * @param string $styleName * @param mixed $style + * @return mixed */ protected function setObjectVal($value, $styleName, &$style) { $styleClass = substr(get_class($this), 0, strrpos(get_class($this), '\\')) . '\\' . $styleName; if (is_array($value)) { + /** @var \PhpOffice\PhpWord\Style\AbstractStyle $style Type hint */ if (!$style instanceof $styleClass) { $style = new $styleClass(); } @@ -265,6 +269,7 @@ abstract class AbstractStyle * Set style using associative array * * @param array $style + * @return self * @deprecated 0.11.0 * @codeCoverageIgnore */ diff --git a/src/PhpWord/Style/Cell.php b/src/PhpWord/Style/Cell.php index e44ffa38..95ed13b4 100644 --- a/src/PhpWord/Style/Cell.php +++ b/src/PhpWord/Style/Cell.php @@ -146,6 +146,8 @@ class Cell extends Border { if (!is_null($this->shading)) { return $this->shading->getFill(); + } else { + return null; } } diff --git a/src/PhpWord/Style/Font.php b/src/PhpWord/Style/Font.php index 4fe70068..a4d56dd4 100644 --- a/src/PhpWord/Style/Font.php +++ b/src/PhpWord/Style/Font.php @@ -562,6 +562,8 @@ class Font extends AbstractStyle { if (!is_null($this->shading)) { return $this->shading->getFill(); + } else { + return null; } } diff --git a/src/PhpWord/Style/Paragraph.php b/src/PhpWord/Style/Paragraph.php index 9c8e0c5b..8609b5ab 100644 --- a/src/PhpWord/Style/Paragraph.php +++ b/src/PhpWord/Style/Paragraph.php @@ -127,6 +127,7 @@ class Paragraph extends AbstractStyle * * @param string $key * @param mixed $value + * @return self */ public function setStyleValue($key, $value) { @@ -172,6 +173,8 @@ class Paragraph extends AbstractStyle { if (!is_null($this->spacing)) { return $this->spacing->getBefore(); + } else { + return null; } } @@ -195,6 +198,8 @@ class Paragraph extends AbstractStyle { if (!is_null($this->spacing)) { return $this->spacing->getAfter(); + } else { + return null; } } @@ -218,6 +223,8 @@ class Paragraph extends AbstractStyle { if (!is_null($this->spacing)) { return $this->spacing->getLine(); + } else { + return null; } } @@ -246,7 +253,7 @@ class Paragraph extends AbstractStyle * Set the line height * * @param int|float|string $lineHeight - * @return $this + * @return self * @throws \PhpOffice\PhpWord\Exception\InvalidStyleException */ public function setLineHeight($lineHeight) @@ -273,6 +280,8 @@ class Paragraph extends AbstractStyle { if (!is_null($this->indentation)) { return $this->indentation->getLeft(); + } else { + return null; } } @@ -296,6 +305,8 @@ class Paragraph extends AbstractStyle { if (!is_null($this->indentation)) { return $this->indentation->getHanging(); + } else { + return null; } } diff --git a/src/PhpWord/Style/Section.php b/src/PhpWord/Style/Section.php index 8a0c071d..d47703c2 100644 --- a/src/PhpWord/Style/Section.php +++ b/src/PhpWord/Style/Section.php @@ -420,7 +420,7 @@ class Section extends Border * Set page numbering start * * @param null|int $pageNumberingStart - * @return $this + * @return self */ public function setPageNumberingStart($pageNumberingStart = null) { diff --git a/src/PhpWord/Writer/AbstractWriter.php b/src/PhpWord/Writer/AbstractWriter.php index f1a30026..bc1c1bf9 100644 --- a/src/PhpWord/Writer/AbstractWriter.php +++ b/src/PhpWord/Writer/AbstractWriter.php @@ -149,6 +149,7 @@ abstract class AbstractWriter implements WriterInterface * @param bool $value * @param string $directory * @return self + * @throws \PhpOffice\PhpWord\Exception\Exception */ public function setUseDiskCaching($value = false, $directory = null) { @@ -257,6 +258,7 @@ abstract class AbstractWriter implements WriterInterface * * @param string $filename * @return mixed ZipArchive object + * @throws \PhpOffice\PhpWord\Exception\Exception */ protected function getZipArchive($filename) { diff --git a/src/PhpWord/Writer/HTML.php b/src/PhpWord/Writer/HTML.php index f871bc18..6c1a534f 100644 --- a/src/PhpWord/Writer/HTML.php +++ b/src/PhpWord/Writer/HTML.php @@ -19,9 +19,9 @@ namespace PhpOffice\PhpWord\Writer; use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\PhpWord; +use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Paragraph; -use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Writer\HTML\Element\Container; use PhpOffice\PhpWord\Writer\HTML\Element\TextRun as TextRunWriter; use PhpOffice\PhpWord\Writer\HTML\Style\Font as FontStyleWriter; diff --git a/src/PhpWord/Writer/HTML/Element/AbstractElement.php b/src/PhpWord/Writer/HTML/Element/AbstractElement.php index 8da09414..a5dee60a 100644 --- a/src/PhpWord/Writer/HTML/Element/AbstractElement.php +++ b/src/PhpWord/Writer/HTML/Element/AbstractElement.php @@ -51,6 +51,8 @@ abstract class AbstractElement /** * Create new instance * + * @param \PhpOffice\PhpWord\Writer\AbstractWriter $parentWriter + * @param \PhpOffice\PhpWord\Element\AbstractElement $element * @param bool $withoutP */ public function __construct(AbstractWriter $parentWriter, Element $element, $withoutP = false) diff --git a/src/PhpWord/Writer/HTML/Element/Container.php b/src/PhpWord/Writer/HTML/Element/Container.php index 54ec7ee6..e9b2d869 100644 --- a/src/PhpWord/Writer/HTML/Element/Container.php +++ b/src/PhpWord/Writer/HTML/Element/Container.php @@ -40,7 +40,7 @@ class Container extends AbstractElement { $container = $this->element; if (!$container instanceof \PhpOffice\PhpWord\Element\AbstractContainer) { - return; + return ''; } $containerClass = substr(get_class($container), strrpos(get_class($container), '\\') + 1); $withoutP = in_array($containerClass, array('TextRun', 'Footnote', 'Endnote')) ? true : false; diff --git a/src/PhpWord/Writer/HTML/Element/Footnote.php b/src/PhpWord/Writer/HTML/Element/Footnote.php index ba5ced56..f59545de 100644 --- a/src/PhpWord/Writer/HTML/Element/Footnote.php +++ b/src/PhpWord/Writer/HTML/Element/Footnote.php @@ -39,9 +39,9 @@ class Footnote extends AbstractElement public function write() { if (!$this->element instanceof \PhpOffice\PhpWord\Element\Footnote) { - return; + return ''; } - /** @var \PhpOffice\PhpWord\Writer\HTML $parentWriter Scrutinizer type hint */ + /** @var \PhpOffice\PhpWord\Writer\HTML $parentWriter Type hint */ $parentWriter = $this->parentWriter; $noteId = count($parentWriter->getNotes()) + 1; diff --git a/src/PhpWord/Writer/HTML/Element/Image.php b/src/PhpWord/Writer/HTML/Element/Image.php index 1d07acd7..361babf3 100644 --- a/src/PhpWord/Writer/HTML/Element/Image.php +++ b/src/PhpWord/Writer/HTML/Element/Image.php @@ -35,9 +35,9 @@ class Image extends Text public function write() { if (!$this->element instanceof \PhpOffice\PhpWord\Element\Image) { - return; + return ''; } - /** @var \PhpOffice\PhpWord\Writer\HTML $parentWriter Scrutinizer type hint */ + /** @var \PhpOffice\PhpWord\Writer\HTML $parentWriter Type hint */ $parentWriter = $this->parentWriter; $content = ''; @@ -59,6 +59,7 @@ class Image extends Text /** * Get Base64 image data * + * @param \PhpOffice\PhpWord\Element\Image $element * @return string|null */ private function getBase64ImageData(ImageElement $element) diff --git a/src/PhpWord/Writer/HTML/Element/Link.php b/src/PhpWord/Writer/HTML/Element/Link.php index 820a1526..d1256eb0 100644 --- a/src/PhpWord/Writer/HTML/Element/Link.php +++ b/src/PhpWord/Writer/HTML/Element/Link.php @@ -32,7 +32,7 @@ class Link extends Text public function write() { if (!$this->element instanceof \PhpOffice\PhpWord\Element\Link) { - return; + return ''; } $content = ''; diff --git a/src/PhpWord/Writer/HTML/Element/ListItem.php b/src/PhpWord/Writer/HTML/Element/ListItem.php index 8e302b03..79a3b393 100644 --- a/src/PhpWord/Writer/HTML/Element/ListItem.php +++ b/src/PhpWord/Writer/HTML/Element/ListItem.php @@ -32,7 +32,7 @@ class ListItem extends AbstractElement public function write() { if (!$this->element instanceof \PhpOffice\PhpWord\Element\ListItem) { - return; + return ''; } $text = htmlspecialchars($this->element->getTextObject()->getText()); diff --git a/src/PhpWord/Writer/HTML/Element/Table.php b/src/PhpWord/Writer/HTML/Element/Table.php index bd7795ef..fc5f0d30 100644 --- a/src/PhpWord/Writer/HTML/Element/Table.php +++ b/src/PhpWord/Writer/HTML/Element/Table.php @@ -32,7 +32,7 @@ class Table extends AbstractElement public function write() { if (!$this->element instanceof \PhpOffice\PhpWord\Element\Table) { - return; + return ''; } $content = ''; diff --git a/src/PhpWord/Writer/HTML/Element/Text.php b/src/PhpWord/Writer/HTML/Element/Text.php index 8ace129c..44740f72 100644 --- a/src/PhpWord/Writer/HTML/Element/Text.php +++ b/src/PhpWord/Writer/HTML/Element/Text.php @@ -53,7 +53,7 @@ class Text extends AbstractElement /** * Closing tag * - * @var strings + * @var string */ private $closingTags = ''; @@ -64,7 +64,7 @@ class Text extends AbstractElement */ public function write() { - /** @var \PhpOffice\PhpWord\Element\Text $element Scrutinizer type hint */ + /** @var \PhpOffice\PhpWord\Element\Text $element Type hint */ $element = $this->element; $this->getFontStyle(); @@ -142,7 +142,7 @@ class Text extends AbstractElement */ private function getParagraphStyle() { - /** @var \PhpOffice\PhpWord\Element\Text $element Scrutinizer type hint */ + /** @var \PhpOffice\PhpWord\Element\Text $element Type hint */ $element = $this->element; $style = ''; if (method_exists($element, 'getParagraphStyle')) { @@ -168,7 +168,7 @@ class Text extends AbstractElement */ private function getFontStyle() { - /** @var \PhpOffice\PhpWord\Element\Text $element Scrutinizer type hint */ + /** @var \PhpOffice\PhpWord\Element\Text $element Type hint */ $element = $this->element; $style = ''; $fontStyle = $element->getFontStyle(); diff --git a/src/PhpWord/Writer/HTML/Element/Title.php b/src/PhpWord/Writer/HTML/Element/Title.php index 64d47ec2..20747bf9 100644 --- a/src/PhpWord/Writer/HTML/Element/Title.php +++ b/src/PhpWord/Writer/HTML/Element/Title.php @@ -32,7 +32,7 @@ class Title extends AbstractElement public function write() { if (!$this->element instanceof \PhpOffice\PhpWord\Element\Title) { - return; + return ''; } $tag = 'h' . $this->element->getDepth(); diff --git a/src/PhpWord/Writer/HTML/Style/AbstractStyle.php b/src/PhpWord/Writer/HTML/Style/AbstractStyle.php index 3b6d99c1..cd37174a 100644 --- a/src/PhpWord/Writer/HTML/Style/AbstractStyle.php +++ b/src/PhpWord/Writer/HTML/Style/AbstractStyle.php @@ -56,7 +56,7 @@ abstract class AbstractStyle public function getStyle() { if (!$this->style instanceof Style && !is_array($this->style)) { - return; + return ''; } return $this->style; diff --git a/src/PhpWord/Writer/HTML/Style/Font.php b/src/PhpWord/Writer/HTML/Style/Font.php index 33c23f7a..dc95eb1a 100644 --- a/src/PhpWord/Writer/HTML/Style/Font.php +++ b/src/PhpWord/Writer/HTML/Style/Font.php @@ -36,7 +36,7 @@ class Font extends AbstractStyle { $style = $this->getStyle(); if (!$style instanceof \PhpOffice\PhpWord\Style\Font) { - return; + return ''; } $css = array(); diff --git a/src/PhpWord/Writer/HTML/Style/Image.php b/src/PhpWord/Writer/HTML/Style/Image.php index db6ac57b..13be3665 100644 --- a/src/PhpWord/Writer/HTML/Style/Image.php +++ b/src/PhpWord/Writer/HTML/Style/Image.php @@ -33,7 +33,7 @@ class Image extends AbstractStyle { $style = $this->getStyle(); if (!$style instanceof \PhpOffice\PhpWord\Style\Image) { - return; + return ''; } $css = array(); diff --git a/src/PhpWord/Writer/HTML/Style/Paragraph.php b/src/PhpWord/Writer/HTML/Style/Paragraph.php index cc3ad785..4a77e496 100644 --- a/src/PhpWord/Writer/HTML/Style/Paragraph.php +++ b/src/PhpWord/Writer/HTML/Style/Paragraph.php @@ -35,7 +35,7 @@ class Paragraph extends AbstractStyle { $style = $this->getStyle(); if (!$style instanceof \PhpOffice\PhpWord\Style\Paragraph) { - return; + return ''; } $css = array(); diff --git a/src/PhpWord/Writer/ODText/Element/Text.php b/src/PhpWord/Writer/ODText/Element/Text.php index 6baf3200..4fc53bfe 100644 --- a/src/PhpWord/Writer/ODText/Element/Text.php +++ b/src/PhpWord/Writer/ODText/Element/Text.php @@ -17,6 +17,8 @@ namespace PhpOffice\PhpWord\Writer\ODText\Element; +use PhpOffice\PhpWord\Exception\Exception; + /** * Text element writer * diff --git a/src/PhpWord/Writer/ODText/Part/AbstractPart.php b/src/PhpWord/Writer/ODText/Part/AbstractPart.php index c5a3b0c6..8b53f26b 100644 --- a/src/PhpWord/Writer/ODText/Part/AbstractPart.php +++ b/src/PhpWord/Writer/ODText/Part/AbstractPart.php @@ -19,8 +19,8 @@ namespace PhpOffice\PhpWord\Writer\ODText\Part; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Shared\XMLWriter; -use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style; +use PhpOffice\PhpWord\Style\Font; /** * ODText writer part abstract diff --git a/src/PhpWord/Writer/ODText/Part/Content.php b/src/PhpWord/Writer/ODText/Part/Content.php index f5ae1883..bebc5b86 100644 --- a/src/PhpWord/Writer/ODText/Part/Content.php +++ b/src/PhpWord/Writer/ODText/Part/Content.php @@ -23,8 +23,8 @@ use PhpOffice\PhpWord\Media; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Style\Font; -use PhpOffice\PhpWord\Style\Paragraph; use PhpOffice\PhpWord\Style; +use PhpOffice\PhpWord\Style\Paragraph; use PhpOffice\PhpWord\Writer\ODText\Element\Container; /** diff --git a/src/PhpWord/Writer/ODText/Part/Meta.php b/src/PhpWord/Writer/ODText/Part/Meta.php index 6ed58213..0d2a761a 100644 --- a/src/PhpWord/Writer/ODText/Part/Meta.php +++ b/src/PhpWord/Writer/ODText/Part/Meta.php @@ -17,8 +17,6 @@ namespace PhpOffice\PhpWord\Writer\ODText\Part; -use PhpOffice\PhpWord\PhpWord; - /** * ODText meta part writer: meta.xml */ diff --git a/src/PhpWord/Writer/PDF.php b/src/PhpWord/Writer/PDF.php index 45e8a412..fc4599c9 100644 --- a/src/PhpWord/Writer/PDF.php +++ b/src/PhpWord/Writer/PDF.php @@ -37,6 +37,7 @@ class PDF * Instantiate a new renderer of the configured type within this container class * * @param \PhpOffice\PhpWord\PhpWord $phpWord + * @throws \PhpOffice\PhpWord\Exception\Exception */ public function __construct(PhpWord $phpWord) { @@ -62,6 +63,7 @@ class PDF * @param string $name Renderer library method name * @param mixed[] $arguments Array of arguments to pass to the renderer method * @return mixed Returned data from the PDF renderer wrapper method + * @throws \PhpOffice\PhpWord\Exception\Exception */ public function __call($name, $arguments) { diff --git a/src/PhpWord/Writer/PDF/AbstractRenderer.php b/src/PhpWord/Writer/PDF/AbstractRenderer.php index 342cdf58..4feefdae 100644 --- a/src/PhpWord/Writer/PDF/AbstractRenderer.php +++ b/src/PhpWord/Writer/PDF/AbstractRenderer.php @@ -90,10 +90,12 @@ abstract class AbstractRenderer extends \PhpOffice\PhpWord\Writer\HTML * 'arialunicid0-japanese' * * @param string $fontName + * @return self */ public function setFont($fontName) { $this->font = $fontName; + return $this; } @@ -146,6 +148,7 @@ abstract class AbstractRenderer extends \PhpOffice\PhpWord\Writer\HTML * * @param string $pFilename Name of the file to save as * @return resource + * @throws \PhpOffice\PhpWord\Exception\Exception */ protected function prepareForSave($pFilename = null) { diff --git a/src/PhpWord/Writer/PDF/DomPDF.php b/src/PhpWord/Writer/PDF/DomPDF.php index cf18d7a5..2b8f951f 100644 --- a/src/PhpWord/Writer/PDF/DomPDF.php +++ b/src/PhpWord/Writer/PDF/DomPDF.php @@ -30,6 +30,7 @@ class DomPDF extends AbstractRenderer implements \PhpOffice\PhpWord\Writer\Write * Create new instance * * @param PhpWord $phpWord PhpWord object + * @throws \PhpOffice\PhpWord\Exception\Exception */ public function __construct(PhpWord $phpWord) { diff --git a/src/PhpWord/Writer/RTF.php b/src/PhpWord/Writer/RTF.php index 8670cb40..888166e6 100644 --- a/src/PhpWord/Writer/RTF.php +++ b/src/PhpWord/Writer/RTF.php @@ -145,7 +145,7 @@ class RTF extends AbstractWriter implements WriterInterface // Set the color tbl group $content .= '{\colortbl '; - foreach ($this->colorTable as $idx => $color) { + foreach ($this->colorTable as $color) { $arrColor = Drawing::htmlToRGB($color); $content .= ';\red' . $arrColor[0] . '\green' . $arrColor[1] . '\blue' . $arrColor[2] . ''; } diff --git a/src/PhpWord/Writer/RTF/Element/AbstractElement.php b/src/PhpWord/Writer/RTF/Element/AbstractElement.php index 89bcfd37..e04aff3c 100644 --- a/src/PhpWord/Writer/RTF/Element/AbstractElement.php +++ b/src/PhpWord/Writer/RTF/Element/AbstractElement.php @@ -18,8 +18,8 @@ namespace PhpOffice\PhpWord\Writer\RTF\Element; use PhpOffice\PhpWord\Shared\String; -use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style\Font as FontStyle; +use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle; use PhpOffice\PhpWord\Writer\RTF\Style\Font as FontStyleWriter; use PhpOffice\PhpWord\Writer\RTF\Style\Paragraph as ParagraphStyleWriter; @@ -34,14 +34,14 @@ class AbstractElement extends \PhpOffice\PhpWord\Writer\HTML\Element\AbstractEle /** * Font style * - * @var \PhpWord\PhpOffice\Style\Font + * @var \PhpOffice\PhpWord\Style\Font */ private $fontStyle; /** * Paragraph style * - * @var \PhpWord\PhpOffice\Style\Paragraph + * @var \PhpOffice\PhpWord\Style\Paragraph */ private $paragraphStyle; @@ -50,10 +50,10 @@ class AbstractElement extends \PhpOffice\PhpWord\Writer\HTML\Element\AbstractEle */ protected function getStyles() { - /** @var \PhpOffice\PhpWord\Writer\RTF $parentWriter Scrutinizer type hint */ + /** @var \PhpOffice\PhpWord\Writer\RTF $parentWriter Type hint */ $parentWriter = $this->parentWriter; - /** @var \PhpOffice\PhpWord\Element\Text $element Scrutinizer type hint */ + /** @var \PhpOffice\PhpWord\Element\Text $element Type hint */ $element = $this->element; // Font style @@ -93,7 +93,7 @@ class AbstractElement extends \PhpOffice\PhpWord\Writer\HTML\Element\AbstractEle protected function writeOpening() { if ($this->withoutP || !$this->paragraphStyle instanceof ParagraphStyle) { - return; + return ''; } $styleWriter = new ParagraphStyleWriter($this->paragraphStyle); @@ -119,7 +119,7 @@ class AbstractElement extends \PhpOffice\PhpWord\Writer\HTML\Element\AbstractEle protected function writeClosing() { if ($this->withoutP) { - return; + return ''; } return '\par' . PHP_EOL; @@ -136,7 +136,7 @@ class AbstractElement extends \PhpOffice\PhpWord\Writer\HTML\Element\AbstractEle return ''; } - /** @var \PhpOffice\PhpWord\Writer\RTF $parentWriter Scrutinizer type hint */ + /** @var \PhpOffice\PhpWord\Writer\RTF $parentWriter Type hint */ $parentWriter = $this->parentWriter; // Create style writer and set color/name index diff --git a/src/PhpWord/Writer/RTF/Element/Link.php b/src/PhpWord/Writer/RTF/Element/Link.php index 684f6e65..22b08588 100644 --- a/src/PhpWord/Writer/RTF/Element/Link.php +++ b/src/PhpWord/Writer/RTF/Element/Link.php @@ -32,7 +32,7 @@ class Link extends AbstractElement public function write() { if (!$this->element instanceof \PhpOffice\PhpWord\Element\Link) { - return; + return ''; } $this->getStyles(); diff --git a/src/PhpWord/Writer/RTF/Element/Text.php b/src/PhpWord/Writer/RTF/Element/Text.php index abdf888d..38ef4c94 100644 --- a/src/PhpWord/Writer/RTF/Element/Text.php +++ b/src/PhpWord/Writer/RTF/Element/Text.php @@ -31,11 +31,11 @@ class Text extends AbstractElement */ public function write() { - /** @var \PhpOffice\PhpWord\Element\Text $element Scrutinizer type hint */ + /** @var \PhpOffice\PhpWord\Element\Text $element Type hint */ $element = $this->element; $elementClass = str_replace('\\Writer\\RTF', '', get_class($this)); if (!$element instanceof $elementClass) { - return; + return ''; } $this->getStyles(); diff --git a/src/PhpWord/Writer/RTF/Element/TextBreak.php b/src/PhpWord/Writer/RTF/Element/TextBreak.php index ff836a88..4449be65 100644 --- a/src/PhpWord/Writer/RTF/Element/TextBreak.php +++ b/src/PhpWord/Writer/RTF/Element/TextBreak.php @@ -31,7 +31,7 @@ class TextBreak extends AbstractElement */ public function write() { - /** @var \PhpOffice\PhpWord\Writer\RTF $parentWriter Scrutinizer type hint */ + /** @var \PhpOffice\PhpWord\Writer\RTF $parentWriter Type hint */ $parentWriter = $this->parentWriter; $parentWriter->setLastParagraphStyle(); diff --git a/src/PhpWord/Writer/RTF/Element/TextRun.php b/src/PhpWord/Writer/RTF/Element/TextRun.php index 8d70366c..e7563716 100644 --- a/src/PhpWord/Writer/RTF/Element/TextRun.php +++ b/src/PhpWord/Writer/RTF/Element/TextRun.php @@ -17,8 +17,6 @@ namespace PhpOffice\PhpWord\Writer\RTF\Element; -use PhpOffice\PhpWord\Writer\RTF\Element\Container; - /** * TextRun element RTF writer * diff --git a/src/PhpWord/Writer/RTF/Style/AbstractStyle.php b/src/PhpWord/Writer/RTF/Style/AbstractStyle.php index 55d6588e..6ad31e41 100644 --- a/src/PhpWord/Writer/RTF/Style/AbstractStyle.php +++ b/src/PhpWord/Writer/RTF/Style/AbstractStyle.php @@ -17,8 +17,6 @@ namespace PhpOffice\PhpWord\Writer\RTF\Style; -use PhpOffice\PhpWord\Style\AbstractStyle as Style; - /** * Abstract RTF style writer * diff --git a/src/PhpWord/Writer/RTF/Style/Font.php b/src/PhpWord/Writer/RTF/Style/Font.php index b70c089f..e28cb691 100644 --- a/src/PhpWord/Writer/RTF/Style/Font.php +++ b/src/PhpWord/Writer/RTF/Style/Font.php @@ -17,7 +17,6 @@ namespace PhpOffice\PhpWord\Writer\RTF\Style; -use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Style\Font as FontStyle; /** @@ -46,7 +45,7 @@ class Font extends AbstractStyle { $style = $this->getStyle(); if (!$style instanceof \PhpOffice\PhpWord\Style\Font) { - return; + return ''; } $content = ''; diff --git a/src/PhpWord/Writer/RTF/Style/Paragraph.php b/src/PhpWord/Writer/RTF/Style/Paragraph.php index 26c62f02..e5f5d85e 100644 --- a/src/PhpWord/Writer/RTF/Style/Paragraph.php +++ b/src/PhpWord/Writer/RTF/Style/Paragraph.php @@ -35,7 +35,7 @@ class Paragraph extends AbstractStyle { $style = $this->getStyle(); if (!$style instanceof \PhpOffice\PhpWord\Style\Paragraph) { - return; + return ''; } $alignments = array( diff --git a/src/PhpWord/Writer/Word2007.php b/src/PhpWord/Writer/Word2007.php index 44317bd2..d55cfff5 100644 --- a/src/PhpWord/Writer/Word2007.php +++ b/src/PhpWord/Writer/Word2007.php @@ -88,6 +88,7 @@ class Word2007 extends AbstractWriter implements WriterInterface * Save document by name * * @param string $filename + * @throws \PhpOffice\PhpWord\Exception\Exception */ public function save($filename = null) { @@ -191,6 +192,7 @@ class Word2007 extends AbstractWriter implements WriterInterface /** * Add header/footer content * + * @param \PhpOffice\PhpWord\Element\Section $section * @param mixed $objZip * @param string $elmType header|footer * @param integer $rId diff --git a/src/PhpWord/Writer/Word2007/Element/AbstractElement.php b/src/PhpWord/Writer/Word2007/Element/AbstractElement.php index bbb2c83e..be3e8463 100644 --- a/src/PhpWord/Writer/Word2007/Element/AbstractElement.php +++ b/src/PhpWord/Writer/Word2007/Element/AbstractElement.php @@ -58,6 +58,8 @@ abstract class AbstractElement /** * Create new instance * + * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\PhpWord\Element\AbstractElement $element * @param bool $withoutP */ public function __construct(XMLWriter $xmlWriter, Element $element, $withoutP = false) @@ -81,14 +83,11 @@ abstract class AbstractElement * Get element * * @return \PhpOffice\PhpWord\Element\AbstractElement + * @throws \PhpOffice\PhpWord\Exception\Exception */ protected function getElement() { - if (!is_null($this->element)) { - return $this->element; - } else { - throw new Exception('No element assigned.'); - } + return $this->element; } /** diff --git a/src/PhpWord/Writer/Word2007/Element/TOC.php b/src/PhpWord/Writer/Word2007/Element/TOC.php index 88dd0dbd..00da355e 100644 --- a/src/PhpWord/Writer/Word2007/Element/TOC.php +++ b/src/PhpWord/Writer/Word2007/Element/TOC.php @@ -64,6 +64,8 @@ class TOC extends AbstractElement /** * Write title * + * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\PhpWord\Element\TOC $element * @param \PhpOffice\PhpWord\Element\Title $title * @param bool $writeFieldMark */ @@ -130,6 +132,8 @@ class TOC extends AbstractElement /** * Write style * + * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\PhpWord\Element\TOC $element * @param int $indent */ private function writeStyle(XMLWriter $xmlWriter, TOCElement $element, $indent) @@ -141,8 +145,8 @@ class TOC extends AbstractElement $xmlWriter->startElement('w:pPr'); // Paragraph - if ($isObject && !is_null($fontStyle->getParagraphStyle())) { - $styleWriter = new ParagraphStyleWriter($xmlWriter, $fontStyle->getParagraphStyle()); + if ($isObject && !is_null($fontStyle->getParagraph())) { + $styleWriter = new ParagraphStyleWriter($xmlWriter, $fontStyle->getParagraph()); $styleWriter->write(); } diff --git a/src/PhpWord/Writer/Word2007/Element/Text.php b/src/PhpWord/Writer/Word2007/Element/Text.php index 5cb33a28..87a56dd2 100644 --- a/src/PhpWord/Writer/Word2007/Element/Text.php +++ b/src/PhpWord/Writer/Word2007/Element/Text.php @@ -89,7 +89,7 @@ class Text extends AbstractElement { $xmlWriter = $this->getXmlWriter(); - /** @var \PhpOffice\PhpWord\Element\Text $element Scrutinizer type hint */ + /** @var \PhpOffice\PhpWord\Element\Text $element Type hint */ $element = $this->getElement(); $paragraphStyle = $element->getParagraphStyle(); $styleWriter = new ParagraphStyleWriter($xmlWriter, $paragraphStyle); @@ -104,7 +104,7 @@ class Text extends AbstractElement { $xmlWriter = $this->getXmlWriter(); - /** @var \PhpOffice\PhpWord\Element\Text $element Scrutinizer type hint */ + /** @var \PhpOffice\PhpWord\Element\Text $element Type hint */ $element = $this->getElement(); $fontStyle = $element->getFontStyle(); $styleWriter = new FontStyleWriter($xmlWriter, $fontStyle); diff --git a/src/PhpWord/Writer/Word2007/Part/ContentTypes.php b/src/PhpWord/Writer/Word2007/Part/ContentTypes.php index 417df64d..c97654be 100644 --- a/src/PhpWord/Writer/Word2007/Part/ContentTypes.php +++ b/src/PhpWord/Writer/Word2007/Part/ContentTypes.php @@ -32,7 +32,7 @@ class ContentTypes extends AbstractPart */ public function write() { - /** @var \PhpOffice\PhpWord\Writer\Word2007 $parentWriter Scrutinizer type hint */ + /** @var \PhpOffice\PhpWord\Writer\Word2007 $parentWriter Type hint */ $parentWriter = $this->getParentWriter(); $contentTypes = $parentWriter->getContentTypes(); @@ -82,16 +82,12 @@ class ContentTypes extends AbstractPart private function writeContentType(XMLWriter $xmlWriter, $parts, $isDefault) { foreach ($parts as $partName => $contentType) { - if ($partName != '' && $contentType != '') { - $partType = $isDefault ? 'Default' : 'Override'; - $partAttribute = $isDefault ? 'Extension' : 'PartName'; - $xmlWriter->startElement($partType); - $xmlWriter->writeAttribute($partAttribute, $partName); - $xmlWriter->writeAttribute('ContentType', $contentType); - $xmlWriter->endElement(); - } else { - throw new Exception("Invalid parameters passed."); - } + $partType = $isDefault ? 'Default' : 'Override'; + $partAttribute = $isDefault ? 'Extension' : 'PartName'; + $xmlWriter->startElement($partType); + $xmlWriter->writeAttribute($partAttribute, $partName); + $xmlWriter->writeAttribute('ContentType', $contentType); + $xmlWriter->endElement(); } } } diff --git a/src/PhpWord/Writer/Word2007/Part/DocPropsApp.php b/src/PhpWord/Writer/Word2007/Part/DocPropsApp.php index 17d38a10..1e6549c5 100644 --- a/src/PhpWord/Writer/Word2007/Part/DocPropsApp.php +++ b/src/PhpWord/Writer/Word2007/Part/DocPropsApp.php @@ -17,8 +17,6 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Part; -use PhpOffice\PhpWord\PhpWord; - /** * Word2007 extended document properties part writer: docProps/app.xml * diff --git a/src/PhpWord/Writer/Word2007/Part/DocPropsCore.php b/src/PhpWord/Writer/Word2007/Part/DocPropsCore.php index 51400846..2b3bce5a 100644 --- a/src/PhpWord/Writer/Word2007/Part/DocPropsCore.php +++ b/src/PhpWord/Writer/Word2007/Part/DocPropsCore.php @@ -17,8 +17,6 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Part; -use PhpOffice\PhpWord\PhpWord; - /** * Word2007 core document properties part writer: docProps/core.xml * diff --git a/src/PhpWord/Writer/Word2007/Part/Document.php b/src/PhpWord/Writer/Word2007/Part/Document.php index 0f8a16af..99570338 100644 --- a/src/PhpWord/Writer/Word2007/Part/Document.php +++ b/src/PhpWord/Writer/Word2007/Part/Document.php @@ -18,7 +18,6 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Part; use PhpOffice\PhpWord\Element\Section; -use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Writer\Word2007\Element\Container; use PhpOffice\PhpWord\Writer\Word2007\Style\Section as SectionStyleWriter; diff --git a/src/PhpWord/Writer/Word2007/Part/Footnotes.php b/src/PhpWord/Writer/Word2007/Part/Footnotes.php index d7a1caaa..903e5fe5 100644 --- a/src/PhpWord/Writer/Word2007/Part/Footnotes.php +++ b/src/PhpWord/Writer/Word2007/Part/Footnotes.php @@ -106,7 +106,7 @@ class Footnotes extends AbstractPart $xmlWriter->endElement(); // w:p $xmlWriter->endElement(); // $this->elementNode - /** @var array $elements Scrutinizer type hint */ + /** @var array $elements Type hint */ $elements = $this->elements; foreach ($elements as $element) { if ($element instanceof Footnote) { diff --git a/src/PhpWord/Writer/Word2007/Part/Numbering.php b/src/PhpWord/Writer/Word2007/Part/Numbering.php index 2678ac55..6310fbf1 100644 --- a/src/PhpWord/Writer/Word2007/Part/Numbering.php +++ b/src/PhpWord/Writer/Word2007/Part/Numbering.php @@ -18,9 +18,9 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Part; use PhpOffice\PhpWord\Shared\XMLWriter; -use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style\Numbering as NumberingStyle; use PhpOffice\PhpWord\Style\NumberingLevel; +use PhpOffice\PhpWord\Style; /** * Word2007 numbering part writer: word/numbering.xml diff --git a/src/PhpWord/Writer/Word2007/Part/Rels.php b/src/PhpWord/Writer/Word2007/Part/Rels.php index 44e62013..af57a768 100644 --- a/src/PhpWord/Writer/Word2007/Part/Rels.php +++ b/src/PhpWord/Writer/Word2007/Part/Rels.php @@ -97,6 +97,7 @@ class Rels extends AbstractPart * @param string $type Relationship type * @param string $target Relationship target * @param string $targetMode Relationship target mode + * @throws \PhpOffice\PhpWord\Exception\Exception */ private function writeRel(XMLWriter $xmlWriter, $relId, $type, $target, $targetMode = '') { diff --git a/src/PhpWord/Writer/Word2007/Part/RelsDocument.php b/src/PhpWord/Writer/Word2007/Part/RelsDocument.php index 2a58421c..744e14f9 100644 --- a/src/PhpWord/Writer/Word2007/Part/RelsDocument.php +++ b/src/PhpWord/Writer/Word2007/Part/RelsDocument.php @@ -41,7 +41,7 @@ class RelsDocument extends Rels ); $xmlWriter = $this->getXmlWriter(); - /** @var \PhpOffice\PhpWord\Writer\Word2007 $parentWriter Scrutinizer type hint */ + /** @var \PhpOffice\PhpWord\Writer\Word2007 $parentWriter Type hint */ $parentWriter = $this->getParentWriter(); $this->writeRels($xmlWriter, $xmlRels, $parentWriter->getRelationships()); diff --git a/src/PhpWord/Writer/Word2007/Part/Settings.php b/src/PhpWord/Writer/Word2007/Part/Settings.php index c296581f..80a1b427 100644 --- a/src/PhpWord/Writer/Word2007/Part/Settings.php +++ b/src/PhpWord/Writer/Word2007/Part/Settings.php @@ -127,7 +127,7 @@ class Settings extends AbstractPart } else { $xmlWriter->startElement($settingKey); - /** @var array $settingValue Scrutinizer type hint */ + /** @var array $settingValue Type hint */ foreach ($settingValue as $childKey => $childValue) { if ($childKey == '@attributes') { foreach ($childValue as $key => $val) { diff --git a/src/PhpWord/Writer/Word2007/Part/Styles.php b/src/PhpWord/Writer/Word2007/Part/Styles.php index 13e07e71..09ee43ed 100644 --- a/src/PhpWord/Writer/Word2007/Part/Styles.php +++ b/src/PhpWord/Writer/Word2007/Part/Styles.php @@ -19,9 +19,9 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Part; use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\Shared\XMLWriter; -use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Paragraph; +use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style\Table; use PhpOffice\PhpWord\Writer\Word2007\Style\Font as FontStyleWriter; use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter; @@ -155,6 +155,7 @@ class Styles extends AbstractPart * Write default font and other default styles * * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter + * @param \PhpOffice\PhpWord\PhpWord $phpWord * @param array $styles */ private function writeDefaultStyles(XMLWriter $xmlWriter, PhpWord $phpWord, $styles) diff --git a/src/PhpWord/Writer/Word2007/Style/AbstractStyle.php b/src/PhpWord/Writer/Word2007/Style/AbstractStyle.php index 06c35117..ae97b62e 100644 --- a/src/PhpWord/Writer/Word2007/Style/AbstractStyle.php +++ b/src/PhpWord/Writer/Word2007/Style/AbstractStyle.php @@ -49,6 +49,7 @@ abstract class AbstractStyle /** * Create new instance * + * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param string|\PhpOffice\PhpWord\Style\AbstractStyle $style */ public function __construct(XMLWriter $xmlWriter, $style = null) diff --git a/src/PhpWord/Writer/Word2007/Style/Image.php b/src/PhpWord/Writer/Word2007/Style/Image.php index ecc3fb7b..5dde00c8 100644 --- a/src/PhpWord/Writer/Word2007/Style/Image.php +++ b/src/PhpWord/Writer/Word2007/Style/Image.php @@ -136,6 +136,7 @@ class Image extends AbstractStyle /** * Get element style * + * @param \PhpOffice\PhpWord\Style\Image $style * @return array */ private function getElementStyle(ImageStyle $style) diff --git a/src/PhpWord/Writer/Word2007/Style/MarginBorder.php b/src/PhpWord/Writer/Word2007/Style/MarginBorder.php index b5c05ca9..23143ef5 100644 --- a/src/PhpWord/Writer/Word2007/Style/MarginBorder.php +++ b/src/PhpWord/Writer/Word2007/Style/MarginBorder.php @@ -71,6 +71,7 @@ class MarginBorder extends AbstractStyle /** * Write side * + * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param string $side * @param int $width * @param string $color diff --git a/src/PhpWord/Writer/Word2007/Style/Table.php b/src/PhpWord/Writer/Word2007/Style/Table.php index 590e819b..68a074ea 100644 --- a/src/PhpWord/Writer/Word2007/Style/Table.php +++ b/src/PhpWord/Writer/Word2007/Style/Table.php @@ -85,6 +85,7 @@ class Table extends AbstractStyle /** * Write width * + * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter * @param int $width * @param string $unit */ diff --git a/tests/PhpWord/Tests/Writer/HTML/ElementTest.php b/tests/PhpWord/Tests/Writer/HTML/ElementTest.php index d2ed70ea..e12193e8 100644 --- a/tests/PhpWord/Tests/Writer/HTML/ElementTest.php +++ b/tests/PhpWord/Tests/Writer/HTML/ElementTest.php @@ -28,12 +28,12 @@ class ElementTest extends \PHPUnit_Framework_TestCase */ public function testUnmatchedElements() { - $styles = array('Container', 'Footnote', 'Image', 'Link', 'ListItem', 'Table', 'Title'); - foreach ($styles as $style) { - $objectClass = 'PhpOffice\\PhpWord\\Writer\\HTML\\Element\\' . $style; + $elements = array('Container', 'Footnote', 'Image', 'Link', 'ListItem', 'Table', 'Title'); + foreach ($elements as $element) { + $objectClass = 'PhpOffice\\PhpWord\\Writer\\HTML\\Element\\' . $element; $parentWriter = new HTML(); - $element = new \PhpOffice\PhpWord\Element\PageBreak(); - $object = new $objectClass($parentWriter, $element); + $newElement = new \PhpOffice\PhpWord\Element\PageBreak(); + $object = new $objectClass($parentWriter, $newElement); $this->assertEquals('', $object->write()); } diff --git a/tests/PhpWord/Tests/Writer/HTMLTest.php b/tests/PhpWord/Tests/Writer/HTMLTest.php index 1c2a5049..34e9d2bd 100644 --- a/tests/PhpWord/Tests/Writer/HTMLTest.php +++ b/tests/PhpWord/Tests/Writer/HTMLTest.php @@ -64,6 +64,7 @@ class HTMLTest extends \PHPUnit_Framework_TestCase $docProps = $phpWord->getDocumentProperties(); $docProps->setTitle('HTML Test'); + $phpWord->addTitleStyle(1, array('bold' => true)); $phpWord->addFontStyle('Font', array('name' => 'Verdana', 'size' => 11, 'color' => 'FF0000', 'fgColor' => 'FF0000')); $phpWord->addParagraphStyle('Paragraph', array('align' => 'center')); diff --git a/tests/PhpWord/Tests/Writer/ODText/ElementTest.php b/tests/PhpWord/Tests/Writer/ODText/ElementTest.php index 6354520a..c5fdfb41 100644 --- a/tests/PhpWord/Tests/Writer/ODText/ElementTest.php +++ b/tests/PhpWord/Tests/Writer/ODText/ElementTest.php @@ -28,12 +28,12 @@ class ElementTest extends \PHPUnit_Framework_TestCase */ public function testUnmatchedElements() { - $styles = array('Image', 'Link', 'Table', 'Text'); - foreach ($styles as $style) { - $objectClass = 'PhpOffice\\PhpWord\\Writer\\ODText\\Element\\' . $style; + $elements = array('Image', 'Link', 'Table', 'Text'); + foreach ($elements as $element) { + $objectClass = 'PhpOffice\\PhpWord\\Writer\\ODText\\Element\\' . $element; $xmlWriter = new XMLWriter(); - $element = new \PhpOffice\PhpWord\Element\PageBreak(); - $object = new $objectClass($xmlWriter, $element); + $newElement = new \PhpOffice\PhpWord\Element\PageBreak(); + $object = new $objectClass($xmlWriter, $newElement); $object->write(); $this->assertEquals('', $xmlWriter->getData()); diff --git a/tests/PhpWord/Tests/Writer/RTF/ElementTest.php b/tests/PhpWord/Tests/Writer/RTF/ElementTest.php index b63c8a5e..a31117e6 100644 --- a/tests/PhpWord/Tests/Writer/RTF/ElementTest.php +++ b/tests/PhpWord/Tests/Writer/RTF/ElementTest.php @@ -28,12 +28,12 @@ class ElementTest extends \PHPUnit_Framework_TestCase */ public function testUnmatchedElements() { - $styles = array('Container', 'Text', 'Title', 'Link'); - foreach ($styles as $style) { - $objectClass = 'PhpOffice\\PhpWord\\Writer\\RTF\\Element\\' . $style; + $elements = array('Container', 'Text', 'Title', 'Link'); + foreach ($elements as $element) { + $objectClass = 'PhpOffice\\PhpWord\\Writer\\RTF\\Element\\' . $element; $parentWriter = new RTF(); - $element = new \PhpOffice\PhpWord\Element\PageBreak(); - $object = new $objectClass($parentWriter, $element); + $newElement = new \PhpOffice\PhpWord\Element\PageBreak(); + $object = new $objectClass($parentWriter, $newElement); $this->assertEquals('', $object->write()); } diff --git a/tests/PhpWord/Tests/Writer/RTFTest.php b/tests/PhpWord/Tests/Writer/RTFTest.php index ad5a13e1..a8b10bb5 100644 --- a/tests/PhpWord/Tests/Writer/RTFTest.php +++ b/tests/PhpWord/Tests/Writer/RTFTest.php @@ -59,7 +59,7 @@ class RTFTest extends \PHPUnit_Framework_TestCase $phpWord = new PhpWord(); $phpWord->addFontStyle('Font', array('name' => 'Verdana', 'size' => 11, - 'color' => 'FF0000', 'fgColor' => 'FF0000')); + 'color' => 'FF0000', 'fgColor' => '00FF00')); $phpWord->addParagraphStyle('Paragraph', array('align' => 'center')); $section = $phpWord->addSection(); $section->addText('Test 1', 'Font', 'Paragraph'); diff --git a/tests/PhpWord/Tests/Writer/Word2007/ElementTest.php b/tests/PhpWord/Tests/Writer/Word2007/ElementTest.php index 0a9eb4ce..4d1d7ce2 100644 --- a/tests/PhpWord/Tests/Writer/Word2007/ElementTest.php +++ b/tests/PhpWord/Tests/Writer/Word2007/ElementTest.php @@ -28,15 +28,15 @@ class ElementTest extends \PHPUnit_Framework_TestCase */ public function testUnmatchedElements() { - $styles = array( + $elements = array( 'CheckBox', 'Container', 'Footnote', 'Image', 'Link', 'ListItem', 'ListItemRun', 'Object', 'PreserveText', 'Table', 'Text', 'TextBox', 'TextBreak', 'Title', 'TOC' ); - foreach ($styles as $style) { - $objectClass = 'PhpOffice\\PhpWord\\Writer\\Word2007\\Element\\' . $style; + foreach ($elements as $element) { + $objectClass = 'PhpOffice\\PhpWord\\Writer\\Word2007\\Element\\' . $element; $xmlWriter = new XMLWriter(); - $element = new \PhpOffice\PhpWord\Element\PageBreak(); - $object = new $objectClass($xmlWriter, $element); + $newElement = new \PhpOffice\PhpWord\Element\PageBreak(); + $object = new $objectClass($xmlWriter, $newElement); $object->write(); $this->assertEquals('', $xmlWriter->getData()); diff --git a/tests/PhpWord/Tests/Writer/Word2007/Part/DocumentTest.php b/tests/PhpWord/Tests/Writer/Word2007/Part/DocumentTest.php index 7798f30e..ae0fe1d2 100644 --- a/tests/PhpWord/Tests/Writer/Word2007/Part/DocumentTest.php +++ b/tests/PhpWord/Tests/Writer/Word2007/Part/DocumentTest.php @@ -72,6 +72,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase $section->addListItem('List Item 1', 0); $section->addListItem('List Item 2', 0); $section->addListItem('List Item 3', 0); + $section = $phpWord->addSection(); $section->addTitle('Title 2', 2); $section->addObject($objectSrc); @@ -80,6 +81,7 @@ class DocumentTest extends \PHPUnit_Framework_TestCase 'posHorizontalRel' => 'margin', 'posVerticalRel' => 'margin', 'innerMargin' => 10, 'borderSize' => 1, 'borderColor' => '#FF0')); $section->addTextBox(array('wrappingStyle' => 'tight', 'positioning' => 'absolute', 'align' => 'center')); + $section->addListItemRun()->addText('List item run 1'); $doc = TestHelperDOCX::getDocument($phpWord); @@ -113,22 +115,27 @@ class DocumentTest extends \PHPUnit_Framework_TestCase { $objectSrc = __DIR__ . "/../../../_files/documents/sheet.xls"; + $tabs = array(new \PhpOffice\PhpWord\Style\Tab('right', 9090)); $phpWord = new PhpWord(); - $phpWord->addParagraphStyle('pStyle', array('align' => 'center')); // Style #1 + $phpWord->addParagraphStyle('pStyle', array('align' => 'center', 'tabs' => $tabs)); // Style #1 $phpWord->addFontStyle('fStyle', array('size' => '20', 'bold' => true, 'allCaps' => true)); // Style #2 $phpWord->addTitleStyle(1, array('color' => '333333', 'doubleStrikethrough' => true)); // Style #3 + $phpWord->addTableStyle('tStyle', array('borderSize' => 1)); $fontStyle = new Font('text', array('align' => 'center')); + $section = $phpWord->addSection(); - $section->addListItem('List Item', 0, null, null, 'pStyle'); // Style #4 + $section->addListItem('List Item', 0, null, null, 'pStyle'); // Style #5 $section->addObject($objectSrc, array('align' => 'center')); $section->addTOC($fontStyle); $section->addTitle('Title 1', 1); $section->addTOC('fStyle'); + $table = $section->addTable('tStyle'); + $table->setWidth(100); $doc = TestHelperDOCX::getDocument($phpWord); // List item $element = $doc->getElement('/w:document/w:body/w:p[1]/w:pPr/w:numPr/w:numId'); - $this->assertEquals(4, $element->getAttribute('w:val')); + $this->assertEquals(5, $element->getAttribute('w:val')); // Object $element = $doc->getElement('/w:document/w:body/w:p[2]/w:r/w:object/o:OLEObject'); @@ -497,6 +504,10 @@ class DocumentTest extends \PHPUnit_Framework_TestCase $table->addCell(40); $table->addCell(40); + $table->addRow(); + $cell = $table->addCell(200, array('borderRightColor' => 'FF0000')); + $cell->getStyle()->setGridSpan(5); + $doc = TestHelperDOCX::getDocument($phpWord); $element = $doc->getElement('/w:document/w:body/w:tbl/w:tr/w:tc/w:tcPr/w:gridSpan'); diff --git a/tests/PhpWord/Tests/Writer/Word2007/PartTest.php b/tests/PhpWord/Tests/Writer/Word2007/PartTest.php new file mode 100644 index 00000000..8748169d --- /dev/null +++ b/tests/PhpWord/Tests/Writer/Word2007/PartTest.php @@ -0,0 +1,41 @@ +setMedia(array(array('foo' => 'bar'))); + $object->write(); + } +}