More refactoring for PHPMD compliance

This commit is contained in:
Ivan Lanin 2014-05-04 15:13:31 +07:00
parent f6f52afa68
commit c21e28f974
37 changed files with 492 additions and 548 deletions

View File

@ -38,12 +38,11 @@ before_script:
script: script:
## PHP_CodeSniffer ## PHP_CodeSniffer
- phpcs --standard=PSR2 -n src/ --ignore=src/PhpWord/Shared/PCLZip - phpcs src/ tests/ --standard=PSR2 -n --ignore=src/PhpWord/Shared/PCLZip
- phpcs --standard=PSR2 -n tests/
## PHP Copy/Paste Detector ## PHP Copy/Paste Detector
- php phpcpd.phar --verbose src/ - phpcpd src/ tests/ --verbose
## PHP Mess Detector ## PHP Mess Detector
- phpmd src/ text phpmd.xml --exclude pclzip.lib.php - phpmd src/ text unusedcode,naming,design,controversial --exclude pclzip.lib.php
## PHPLOC ## PHPLOC
#- php phploc.phar src/ #- php phploc.phar src/
## PHPUnit ## PHPUnit

View File

@ -90,6 +90,7 @@ This release marked heavy refactorings on internal code structure with the creat
- Refactor: Apply composite pattern for Word2007 reader - @ivanlanin - Refactor: Apply composite pattern for Word2007 reader - @ivanlanin
- Refactor: Replace static classes `Footnotes`, `Endnotes`, and `TOC` with `Collections` - @ivanlanin GH-206 - Refactor: Replace static classes `Footnotes`, `Endnotes`, and `TOC` with `Collections` - @ivanlanin GH-206
- QA: Reactivate `phpcpd` and `phpmd` on Travis - @ivanlanin - QA: Reactivate `phpcpd` and `phpmd` on Travis - @ivanlanin
- Refactor: PHPMD recommendation: Change all `get...` method that returns `boolean` into `is...` or `has...` - @ivanlanin
## 0.9.1 - 27 Mar 2014 ## 0.9.1 - 27 Mar 2014

View File

@ -1,14 +0,0 @@
<?xml version="1.0"?>
<ruleset name="PHPWord mess detector ruleset"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation=" http://pmd.sf.net/ruleset_xml_schema.xsd">
<rule ref="rulesets/unusedcode.xml" />
<rule ref="rulesets/design.xml" />
<rule ref="rulesets/naming.xml/LongVariable" />
<rule ref="rulesets/naming.xml/ShortVariable" />
<rule ref="rulesets/naming.xml/ShortMethodName" />
<rule ref="rulesets/naming.xml/ConstructorWithNameAsEnclosingClass" />
<rule ref="rulesets/naming.xml/ConstantNamingConventions" />
</ruleset>

View File

@ -9,17 +9,15 @@
namespace PhpOffice\PhpWord\Element; namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Media; use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Element\CheckBox; use PhpOffice\PhpWord\Element\CheckBox;
use PhpOffice\PhpWord\Element\Image; use PhpOffice\PhpWord\Element\Image;
use PhpOffice\PhpWord\Element\Link; use PhpOffice\PhpWord\Element\Link;
use PhpOffice\PhpWord\Element\ListItem; use PhpOffice\PhpWord\Element\ListItem;
use PhpOffice\PhpWord\Element\Object; use PhpOffice\PhpWord\Element\Object;
use PhpOffice\PhpWord\Element\PreserveText;
use PhpOffice\PhpWord\Element\Text;
use PhpOffice\PhpWord\Element\TextBreak; use PhpOffice\PhpWord\Element\TextBreak;
use PhpOffice\PhpWord\Element\TextRun; use PhpOffice\PhpWord\Element\TextRun;
use PhpOffice\PhpWord\Exception\InvalidObjectException;
/** /**
* Container abstract class * Container abstract class
@ -69,27 +67,29 @@ abstract class AbstractContainer extends AbstractElement
} }
/** /**
* Add text element * Add text/preservetext element
* *
* @param string $text * @param string $text
* @param mixed $fontStyle * @param mixed $fontStyle
* @param mixed $paragraphStyle * @param mixed $paragraphStyle
* @return \PhpOffice\PhpWord\Element\Text * @param string $elementName Text|PreserveText
* @return \PhpOffice\PhpWord\Element\Text|\PhpOffice\PhpWord\Element\PreserveText
*/ */
public function addText($text, $fontStyle = null, $paragraphStyle = null) public function addText($text, $fontStyle = null, $paragraphStyle = null, $elementName = 'Text')
{ {
$this->checkValidity('Text'); $this->checkValidity($elementName);
$elementClass = 'PhpOffice\\PhpWord\\Element\\' . $elementName;
// Reset paragraph style for footnote and textrun. They have their own // Reset paragraph style for footnote and textrun. They have their own
if (in_array($this->container, array('textrun', 'footnote', 'endnote'))) { if (in_array($this->container, array('textrun', 'footnote', 'endnote'))) {
$paragraphStyle = null; $paragraphStyle = null;
} }
$textObject = new Text($text, $fontStyle, $paragraphStyle); $element = new $elementClass($text, $fontStyle, $paragraphStyle);
$textObject->setDocPart($this->getDocPart(), $this->getDocPartId()); $element->setDocPart($this->getDocPart(), $this->getDocPartId());
$this->addElement($textObject); $this->addElement($element);
return $textObject; return $element;
} }
/** /**
@ -102,11 +102,11 @@ abstract class AbstractContainer extends AbstractElement
{ {
$this->checkValidity('Textrun'); $this->checkValidity('Textrun');
$textRun = new TextRun($paragraphStyle); $element = new TextRun($paragraphStyle);
$textRun->setDocPart($this->getDocPart(), $this->getDocPartId()); $element->setDocPart($this->getDocPart(), $this->getDocPartId());
$this->addElement($textRun); $this->addElement($element);
return $textRun; return $element;
} }
/** /**
@ -123,13 +123,15 @@ abstract class AbstractContainer extends AbstractElement
$this->checkValidity('Link'); $this->checkValidity('Link');
$elementDocPart = $this->checkElementDocPart(); $elementDocPart = $this->checkElementDocPart();
$link = new Link($target, $text, $fontStyle, $paragraphStyle); $element = new Link($target, $text, $fontStyle, $paragraphStyle);
$link->setDocPart($this->getDocPart(), $this->getDocPartId()); $element->setDocPart($this->getDocPart(), $this->getDocPartId());
$rId = Media::addElement($elementDocPart, 'link', $target);
$link->setRelationId($rId);
$this->addElement($link);
return $link; $rId = Media::addElement($elementDocPart, 'link', $target);
$element->setRelationId($rId);
$this->addElement($element);
return $element;
} }
/** /**
@ -142,13 +144,7 @@ abstract class AbstractContainer extends AbstractElement
*/ */
public function addPreserveText($text, $fontStyle = null, $paragraphStyle = null) public function addPreserveText($text, $fontStyle = null, $paragraphStyle = null)
{ {
$this->checkValidity('PreserveText'); return $this->addText($text, $fontStyle, $paragraphStyle, 'PreserveText');
$preserveText = new PreserveText($text, $fontStyle, $paragraphStyle);
$preserveText->setDocPart($this->getDocPart(), $this->getDocPartId());
$this->addElement($preserveText);
return $preserveText;
} }
/** /**
@ -163,9 +159,9 @@ abstract class AbstractContainer extends AbstractElement
$this->checkValidity('TextBreak'); $this->checkValidity('TextBreak');
for ($i = 1; $i <= $count; $i++) { for ($i = 1; $i <= $count; $i++) {
$textBreak = new TextBreak($fontStyle, $paragraphStyle); $element = new TextBreak($fontStyle, $paragraphStyle);
$textBreak->setDocPart($this->getDocPart(), $this->getDocPartId()); $element->setDocPart($this->getDocPart(), $this->getDocPartId());
$this->addElement($textBreak); $this->addElement($element);
} }
} }
@ -183,33 +179,35 @@ abstract class AbstractContainer extends AbstractElement
{ {
$this->checkValidity('ListItem'); $this->checkValidity('ListItem');
$listItem = new ListItem($text, $depth, $fontStyle, $listStyle, $paragraphStyle); $element = new ListItem($text, $depth, $fontStyle, $listStyle, $paragraphStyle);
$listItem->setDocPart($this->getDocPart(), $this->getDocPartId()); $element->setDocPart($this->getDocPart(), $this->getDocPartId());
$this->addElement($listItem); $this->addElement($element);
return $listItem; return $element;
} }
/** /**
* Add image element * Add image element
* *
* @param string $src * @param string $source
* @param mixed $style Image style * @param mixed $style Image style
* @param boolean $isWatermark * @param boolean $isWatermark
* @return \PhpOffice\PhpWord\Element\Image * @return \PhpOffice\PhpWord\Element\Image
*/ */
public function addImage($src, $style = null, $isWatermark = false) public function addImage($source, $style = null, $isWatermark = false)
{ {
$this->checkValidity('Image'); $this->checkValidity('Image');
$elementDocPart = $this->checkElementDocPart(); $elementDocPart = $this->checkElementDocPart();
$image = new Image($src, $style, $isWatermark); $element = new Image($source, $style, $isWatermark);
$image->setDocPart($this->getDocPart(), $this->getDocPartId()); $element->setDocPart($this->getDocPart(), $this->getDocPartId());
$rId = Media::addElement($elementDocPart, 'image', $src, $image);
$image->setRelationId($rId);
$this->addElement($image);
return $image; $rId = Media::addElement($elementDocPart, 'image', $source, $element);
$element->setRelationId($rId);
$this->addElement($element);
return $element;
} }
/** /**
@ -217,35 +215,27 @@ abstract class AbstractContainer extends AbstractElement
* *
* All exceptions should be handled by \PhpOffice\PhpWord\Element\Object * All exceptions should be handled by \PhpOffice\PhpWord\Element\Object
* *
* @param string $src * @param string $source
* @param mixed $style * @param mixed $style
* @return \PhpOffice\PhpWord\Element\Object * @return \PhpOffice\PhpWord\Element\Object
* @throws \PhpOffice\PhpWord\Exception\Exception * @throws \PhpOffice\PhpWord\Exception\Exception
*/ */
public function addObject($src, $style = null) public function addObject($source, $style = null)
{ {
$this->checkValidity('Object'); $this->checkValidity('Object');
$elementDocPart = $this->checkElementDocPart(); $elementDocPart = $this->checkElementDocPart();
$object = new Object($src, $style); $element = new Object($source, $style);
$object->setDocPart($this->getDocPart(), $this->getDocPartId()); $element->setDocPart($this->getDocPart(), $this->getDocPartId());
if (!is_null($object->getSource())) {
$inf = pathinfo($src);
$ext = $inf['extension'];
if (strlen($ext) == 4 && strtolower(substr($ext, -1)) == 'x') {
$ext = substr($ext, 0, -1);
}
$icon = realpath(__DIR__ . "/../resources/{$ext}.png");
$rId = Media::addElement($elementDocPart, 'object', $src);
$object->setRelationId($rId);
$rIdimg = Media::addElement($elementDocPart, 'image', $icon, new Image($icon));
$object->setImageRelationId($rIdimg);
$this->addElement($object);
return $object; $rId = Media::addElement($elementDocPart, 'object', $source);
} else { $element->setRelationId($rId);
throw new InvalidObjectException(); $rIdIcon = Media::addElement($elementDocPart, 'image', $element->getIcon(), new Image($element->getIcon()));
} $element->setImageRelationId($rIdIcon);
$this->addElement($element);
return $element;
} }
/** /**
@ -258,19 +248,19 @@ abstract class AbstractContainer extends AbstractElement
public function addFootnote($paragraphStyle = null, $elementName = 'Footnote') public function addFootnote($paragraphStyle = null, $elementName = 'Footnote')
{ {
$this->checkValidity($elementName); $this->checkValidity($elementName);
$elementClass = 'PhpOffice\\PhpWord\\Element\\' . $elementName;
$docPart = strtolower($elementName); $docPart = strtolower($elementName);
$addMethod = "add{$elementName}"; $addMethod = "add{$elementName}";
$elementClass = 'PhpOffice\\PhpWord\\Element\\' . $elementName;
$note = new $elementClass($paragraphStyle); $element = new $elementClass($paragraphStyle);
// if ($this->phpWord instanceof PhpWord) { if ($this->phpWord instanceof PhpWord) {
$rId = $this->phpWord->$addMethod($note); $rId = $this->phpWord->$addMethod($element);
// } }
$note->setDocPart($docPart, $this->getDocPartId()); $element->setDocPart($docPart, $this->getDocPartId());
$note->setRelationId($rId); $element->setRelationId($rId);
$this->addElement($note); $this->addElement($element);
return $note; return $element;
} }
/** /**
@ -297,11 +287,11 @@ abstract class AbstractContainer extends AbstractElement
{ {
$this->checkValidity('CheckBox'); $this->checkValidity('CheckBox');
$checkBox = new CheckBox($name, $text, $fontStyle, $paragraphStyle); $element = new CheckBox($name, $text, $fontStyle, $paragraphStyle);
$checkBox->setDocPart($this->getDocPart(), $this->getDocPartId()); $element->setDocPart($this->getDocPart(), $this->getDocPartId());
$this->addElement($checkBox); $this->addElement($element);
return $checkBox; return $element;
} }
/** /**

View File

@ -92,13 +92,13 @@ abstract class AbstractElement
} }
/** /**
* Set PhpWord * Set PhpWord as reference
* *
* @param \PhpOffice\PhpWord\PhpWord * @param \PhpOffice\PhpWord\PhpWord
*/ */
public function setPhpWord(PhpWord &$phpWord = null) public function setPhpWord(PhpWord &$phpWord = null)
{ {
$this->phpWord = $phpWord; $this->phpWord = &$phpWord;
} }
/** /**

View File

@ -44,7 +44,7 @@ class Footer extends AbstractContainer
* Create new instance * Create new instance
* *
* @param int $sectionId * @param int $sectionId
* @param int $footerId * @param int $containerId
* @param string $type * @param string $type
*/ */
public function __construct($sectionId, $containerId = 1, $type = self::AUTO) public function __construct($sectionId, $containerId = 1, $type = self::AUTO)

View File

@ -52,7 +52,7 @@ class Image extends AbstractElement
* *
* @var boolean * @var boolean
*/ */
private $isWatermark; private $watermark;
/** /**
* Image type * Image type
@ -87,7 +87,7 @@ class Image extends AbstractElement
* *
* @var boolean * @var boolean
*/ */
private $isMemImage; private $memoryImage;
/** /**
* Image target file name * Image target file name
@ -108,14 +108,14 @@ class Image extends AbstractElement
* *
* @param string $source * @param string $source
* @param mixed $style * @param mixed $style
* @param boolean $isWatermark * @param boolean $watermark
* @throws \PhpOffice\PhpWord\Exception\InvalidImageException * @throws \PhpOffice\PhpWord\Exception\InvalidImageException
* @throws \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException * @throws \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException
*/ */
public function __construct($source, $style = null, $isWatermark = false) public function __construct($source, $style = null, $watermark = false)
{ {
$this->source = $source; $this->source = $source;
$this->setIsWatermark($isWatermark); $this->setIsWatermark($watermark);
$this->style = $this->setStyle(new ImageStyle(), $style, true); $this->style = $this->setStyle(new ImageStyle(), $style, true);
$this->checkImage($source); $this->checkImage($source);
@ -166,19 +166,19 @@ class Image extends AbstractElement
* *
* @return boolean * @return boolean
*/ */
public function getIsWatermark() public function isWatermark()
{ {
return $this->isWatermark; return $this->watermark;
} }
/** /**
* Set is watermark * Set is watermark
* *
* @param boolean $pValue * @param boolean $value
*/ */
public function setIsWatermark($pValue) public function setIsWatermark($value)
{ {
$this->isWatermark = $pValue; $this->watermark = $value;
} }
/** /**
@ -226,9 +226,9 @@ class Image extends AbstractElement
* *
* @return boolean * @return boolean
*/ */
public function getIsMemImage() public function isMemImage()
{ {
return $this->isMemImage; return $this->memoryImage;
} }
/** /**
@ -314,14 +314,14 @@ class Image extends AbstractElement
private function setSourceType($source) private function setSourceType($source)
{ {
if (stripos(strrev($source), strrev('.php')) === 0) { if (stripos(strrev($source), strrev('.php')) === 0) {
$this->isMemImage = true; $this->memoryImage = true;
$this->sourceType = self::SOURCE_GD; $this->sourceType = self::SOURCE_GD;
} elseif (strpos($source, 'zip://') !== false) { } elseif (strpos($source, 'zip://') !== false) {
$this->isMemImage = false; $this->memoryImage = false;
$this->sourceType = self::SOURCE_ARCHIVE; $this->sourceType = self::SOURCE_ARCHIVE;
} else { } else {
$this->isMemImage = (filter_var($source, FILTER_VALIDATE_URL) !== false); $this->memoryImage = (filter_var($source, FILTER_VALIDATE_URL) !== false);
$this->sourceType = $this->isMemImage ? self::SOURCE_GD : self::SOURCE_LOCAL; $this->sourceType = $this->memoryImage ? self::SOURCE_GD : self::SOURCE_LOCAL;
} }
} }
@ -409,4 +409,26 @@ class Image extends AbstractElement
} }
} }
} }
/**
* Get is watermark
*
* @deprecated 0.10.0
* @codeCoverageIgnore
*/
public function getIsWatermark()
{
return $this->isWatermark();
}
/**
* Get is memory image
*
* @deprecated 0.10.0
* @codeCoverageIgnore
*/
public function getIsMemImage()
{
return $this->isMemImage();
}
} }

View File

@ -10,6 +10,7 @@
namespace PhpOffice\PhpWord\Element; namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Image as ImageStyle; use PhpOffice\PhpWord\Style\Image as ImageStyle;
use PhpOffice\PhpWord\Exception\InvalidObjectException;
/** /**
* Object element * Object element
@ -30,6 +31,13 @@ class Object extends AbstractElement
*/ */
private $style; private $style;
/**
* Icon
*
* @var string
*/
private $icon;
/** /**
* Image Relation ID * Image Relation ID
* *
@ -40,35 +48,32 @@ class Object extends AbstractElement
/** /**
* Create a new Ole-Object Element * Create a new Ole-Object Element
* *
* @param string $src * @param string $source
* @param mixed $style * @param mixed $style
*/ */
public function __construct($src, $style = null) public function __construct($source, $style = null)
{ {
$supportedTypes = array('xls', 'doc', 'ppt', 'xlsx', 'docx', 'pptx'); $supportedTypes = array('xls', 'doc', 'ppt', 'xlsx', 'docx', 'pptx');
$inf = pathinfo($src); $pathInfo = pathinfo($source);
if (file_exists($src) && in_array($inf['extension'], $supportedTypes)) { if (file_exists($source) && in_array($pathInfo['extension'], $supportedTypes)) {
$this->source = $src; $ext = $pathInfo['extension'];
if (strlen($ext) == 4 && strtolower(substr($ext, -1)) == 'x') {
$ext = substr($ext, 0, -1);
}
$this->source = $source;
$this->style = $this->setStyle(new ImageStyle(), $style, true); $this->style = $this->setStyle(new ImageStyle(), $style, true);
$this->icon = realpath(__DIR__ . "/../resources/{$ext}.png");
return $this; return $this;
} else { } else {
return false; throw new InvalidObjectException();
} }
} }
/** /**
* Get Image style * Get object source
*
* @return \PhpOffice\PhpWord\Style\Image
*/
public function getStyle()
{
return $this->style;
}
/**
* Get Source
* *
* @return string * @return string
*/ */
@ -78,7 +83,27 @@ class Object extends AbstractElement
} }
/** /**
* Get Image Relation ID * Get object style
*
* @return \PhpOffice\PhpWord\Style\Image
*/
public function getStyle()
{
return $this->style;
}
/**
* Get object icon
*
* @return string
*/
public function getIcon()
{
return $this->icon;
}
/**
* Get image relation ID
* *
* @return int * @return int
*/ */

View File

@ -29,14 +29,7 @@ class Title extends AbstractElement
* *
* @var int * @var int
*/ */
private $depth; private $depth = 1;
/**
* Title anchor
*
* @var int
*/
private $anchor;
/** /**
* Title Bookmark ID * Title Bookmark ID
@ -52,13 +45,19 @@ class Title extends AbstractElement
*/ */
private $style; private $style;
/**
* Title anchor
*
* @var int
* @deprecated 0.10.0
*/
private $anchor;
/** /**
* Create a new Title Element * Create a new Title Element
* *
* @param string $text * @param string $text
* @param int $depth * @param int $depth
* @param string $style
*/ */
public function __construct($text, $depth = 1) public function __construct($text, $depth = 1)
{ {

View File

@ -1,151 +0,0 @@
<?php
/**
* PHPWord
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord;
/**
* Footnote collection
*
* This static class has been deprecated and replaced by Collection\Footnotes.
* File maintained for backward compatibility and will be removed on 1.0.
*
* @deprecated 0.10.0
* @codeCoverageIgnore
*/
class Footnotes
{
/**
* Elements
*
* @var array
*/
private static $elements = array();
/**
* Add new element
*
* @param \PhpOffice\PhpWord\Element\Footnote $element
* @return integer Reference ID
*/
public static function addElement($element)
{
$rId = self::countElements() + 1;
self::$elements[$rId] = $element;
return $rId;
}
/**
* Set element
*
* @param integer $index
* @param \PhpOffice\PhpWord\Element\Footnote $element
*/
public static function setElement($index, $element)
{
if (array_key_exists($index, self::$elements)) {
self::$elements[$index] = $element;
}
}
/**
* Get element by index
*
* @param integer $index
* @return \PhpOffice\PhpWord\Element\Footnote
*/
public static function getElement($index)
{
if (array_key_exists($index, self::$elements)) {
return self::$elements[$index];
} else {
return null;
}
}
/**
* Get elements
*
* @return array
*/
public static function getElements()
{
return self::$elements;
}
/**
* Get element count
*
* @return integer
*/
public static function countElements()
{
return count(self::$elements);
}
/**
* Reset elements
*/
public static function resetElements()
{
self::$elements = array();
}
/**
* Add new footnote
*
* @param \PhpOffice\PhpWord\Element\Footnote $element
* @return integer Reference ID
*/
public static function addFootnoteElement($element)
{
return self::addElement($element);
}
/**
* Get Footnote Elements
*
* @return array
*/
public static function getFootnoteElements()
{
return self::getElements();
}
/**
* Get Footnote Elements Count
*
* @return integer
*/
public static function countFootnoteElements()
{
return self::countElements();
}
/**
* Add new Footnote Link Element
*
* @param string $linkSrc
* @return integer Reference ID
*/
public static function addFootnoteLinkElement($linkSrc)
{
return Media::addElement('footnotes', 'link', $linkSrc);
}
/**
* Get Footnote Link Elements
*
* @return array
*/
public static function getFootnoteLinkElements()
{
return Media::getElements('footnotes', 'link');
}
}

View File

@ -59,7 +59,7 @@ class Media
if (is_null($image)) { if (is_null($image)) {
throw new Exception('Image object not assigned.'); throw new Exception('Image object not assigned.');
} }
$isMemImage = $image->getIsMemImage(); $isMemImage = $image->isMemImage();
$extension = $image->getImageExtension(); $extension = $image->getImageExtension();
$mediaData['imageExtension'] = $extension; $mediaData['imageExtension'] = $extension;
$mediaData['imageType'] = $image->getImageType(); $mediaData['imageType'] = $image->getImageType();

View File

@ -37,7 +37,7 @@ abstract class AbstractReader implements ReaderInterface
* *
* @return bool * @return bool
*/ */
public function getReadDataOnly() public function isReadDataOnly()
{ {
// return $this->readDataOnly; // return $this->readDataOnly;
return true; return true;
@ -96,4 +96,15 @@ abstract class AbstractReader implements ReaderInterface
return true; return true;
} }
/**
* Read data only?
*
* @deprecated 0.10.0
* @codeCoverageIgnore
*/
public function getReadDataOnly()
{
return $this->isReadDataOnly();
}
} }

View File

@ -91,6 +91,16 @@ class Settings
*/ */
private static $measurementUnit = self::UNIT_TWIP; private static $measurementUnit = self::UNIT_TWIP;
/**
* Return the compatibility option used by the XMLWriter
*
* @return bool Compatibility
*/
public static function hasCompatibility()
{
return self::$xmlWriterCompatibility;
}
/** /**
* Set the compatibility option used by the XMLWriter * Set the compatibility option used by the XMLWriter
* *
@ -110,13 +120,13 @@ class Settings
} }
/** /**
* Return the compatibility option used by the XMLWriter * Get zip handler class
* *
* @return bool Compatibility * @return string
*/ */
public static function getCompatibility() public static function getZipClass()
{ {
return self::$xmlWriterCompatibility; return self::$zipClass;
} }
/** /**
@ -136,16 +146,6 @@ class Settings
return false; return false;
} }
/**
* Get zip handler class
*
* @return string
*/
public static function getZipClass()
{
return self::$zipClass;
}
/** /**
* Set details of the external library for rendering PDF files * Set details of the external library for rendering PDF files
* *
@ -237,4 +237,15 @@ class Settings
return true; return true;
} }
/**
* Return the compatibility option used by the XMLWriter
*
* @deprecated 0.10.0
* @codeCoverageIgnore
*/
public static function getCompatibility()
{
return self::hasCompatibility();
}
} }

View File

@ -17,24 +17,24 @@ class Drawing
/** /**
* Convert pixels to EMU * Convert pixels to EMU
* *
* @param integer $pValue Value in pixels * @param integer $value Value in pixels
* @return double Value in EMU * @return double Value in EMU
*/ */
public static function pixelsToEMU($pValue = 0) public static function pixelsToEMU($value = 0)
{ {
return round($pValue * 9525); return round($value * 9525);
} }
/** /**
* Convert EMU to pixels * Convert EMU to pixels
* *
* @param integer $pValue Value in EMU * @param integer $value Value in EMU
* @return integer Value in pixels * @return integer Value in pixels
*/ */
public static function EMUToPixels($pValue = 0) public static function emuToPixels($value = 0)
{ {
if ($pValue != 0) { if ($value != 0) {
return round($pValue / 9525); return round($value / 9525);
} else { } else {
return 0; return 0;
} }
@ -43,24 +43,24 @@ class Drawing
/** /**
* Convert pixels to points * Convert pixels to points
* *
* @param integer $pValue Value in pixels * @param integer $value Value in pixels
* @return double Value in points * @return double Value in points
*/ */
public static function pixelsToPoints($pValue = 0) public static function pixelsToPoints($value = 0)
{ {
return $pValue * 0.67777777; return $value * 0.67777777;
} }
/** /**
* Convert points width to pixels * Convert points width to pixels
* *
* @param integer $pValue Value in points * @param integer $value Value in points
* @return integer Value in pixels * @return integer Value in pixels
*/ */
public static function pointsToPixels($pValue = 0) public static function pointsToPixels($value = 0)
{ {
if ($pValue != 0) { if ($value != 0) {
return $pValue * 1.333333333; return $value * 1.333333333;
} else { } else {
return 0; return 0;
} }
@ -69,24 +69,24 @@ class Drawing
/** /**
* Convert degrees to angle * Convert degrees to angle
* *
* @param integer $pValue Degrees * @param integer $value Degrees
* @return integer Angle * @return integer Angle
*/ */
public static function degreesToAngle($pValue = 0) public static function degreesToAngle($value = 0)
{ {
return (integer)round($pValue * 60000); return (integer)round($value * 60000);
} }
/** /**
* Convert angle to degrees * Convert angle to degrees
* *
* @param integer $pValue Angle * @param integer $value Angle
* @return integer Degrees * @return integer Degrees
*/ */
public static function angleToDegrees($pValue = 0) public static function angleToDegrees($value = 0)
{ {
if ($pValue != 0) { if ($value != 0) {
return round($pValue / 60000); return round($value / 60000);
} else { } else {
return 0; return 0;
} }
@ -95,24 +95,24 @@ class Drawing
/** /**
* Convert pixels to centimeters * Convert pixels to centimeters
* *
* @param integer $pValue Value in pixels * @param integer $value Value in pixels
* @return double Value in centimeters * @return double Value in centimeters
*/ */
public static function pixelsToCentimeters($pValue = 0) public static function pixelsToCentimeters($value = 0)
{ {
return $pValue * 0.028; return $value * 0.028;
} }
/** /**
* Convert centimeters width to pixels * Convert centimeters width to pixels
* *
* @param integer $pValue Value in centimeters * @param integer $value Value in centimeters
* @return integer Value in pixels * @return integer Value in pixels
*/ */
public static function centimetersToPixels($pValue = 0) public static function centimetersToPixels($value = 0)
{ {
if ($pValue != 0) { if ($value != 0) {
return $pValue / 0.028; return $value / 0.028;
} else { } else {
return 0; return 0;
} }
@ -121,27 +121,27 @@ class Drawing
/** /**
* Convert HTML hexadecimal to RGB * Convert HTML hexadecimal to RGB
* *
* @param string $pValue HTML Color in hexadecimal * @param string $value HTML Color in hexadecimal
* @return array Value in RGB * @return array Value in RGB
*/ */
public static function htmlToRGB($pValue) public static function htmlToRGB($value)
{ {
if ($pValue[0] == '#') { if ($value[0] == '#') {
$pValue = substr($pValue, 1); $value = substr($value, 1);
} }
if (strlen($pValue) == 6) { if (strlen($value) == 6) {
list($color_R, $color_G, $color_B) = array($pValue[0] . $pValue[1], $pValue[2] . $pValue[3], $pValue[4] . $pValue[5]); list($red, $green, $blue) = array($value[0] . $value[1], $value[2] . $value[3], $value[4] . $value[5]);
} elseif (strlen($pValue) == 3) { } elseif (strlen($value) == 3) {
list($color_R, $color_G, $color_B) = array($pValue[0] . $pValue[0], $pValue[1] . $pValue[1], $pValue[2] . $pValue[2]); list($red, $green, $blue) = array($value[0] . $value[0], $value[1] . $value[1], $value[2] . $value[2]);
} else { } else {
return false; return false;
} }
$color_R = hexdec($color_R); $red = hexdec($red);
$color_G = hexdec($color_G); $green = hexdec($green);
$color_B = hexdec($color_B); $blue = hexdec($blue);
return array($color_R, $color_G, $color_B); return array($red, $green, $blue);
} }
} }

View File

@ -73,7 +73,7 @@ class XMLWriter
} }
// Set xml Compatibility // Set xml Compatibility
$compatibility = Settings::getCompatibility(); $compatibility = Settings::hasCompatibility();
if ($compatibility) { if ($compatibility) {
$this->xmlWriter->setIndent(false); $this->xmlWriter->setIndent(false);
$this->xmlWriter->setIndentString(''); $this->xmlWriter->setIndentString('');

View File

@ -288,7 +288,7 @@ class Font extends AbstractStyle
* *
* @return bool * @return bool
*/ */
public function getBold() public function isBold()
{ {
return $this->bold; return $this->bold;
} }
@ -311,7 +311,7 @@ class Font extends AbstractStyle
* *
* @return bool * @return bool
*/ */
public function getItalic() public function isItalic()
{ {
return $this->italic; return $this->italic;
} }
@ -334,7 +334,7 @@ class Font extends AbstractStyle
* *
* @return bool * @return bool
*/ */
public function getSuperScript() public function isSuperScript()
{ {
return $this->superScript; return $this->superScript;
} }
@ -360,7 +360,7 @@ class Font extends AbstractStyle
* *
* @return bool * @return bool
*/ */
public function getSubScript() public function isSubScript()
{ {
return $this->subScript; return $this->subScript;
} }
@ -409,7 +409,7 @@ class Font extends AbstractStyle
* *
* @return bool * @return bool
*/ */
public function getStrikethrough() public function isStrikethrough()
{ {
return $this->strikethrough; return $this->strikethrough;
} }
@ -435,7 +435,7 @@ class Font extends AbstractStyle
* *
* @return bool * @return bool
*/ */
public function getDoubleStrikethrough() public function isDoubleStrikethrough()
{ {
return $this->doubleStrikethrough; return $this->doubleStrikethrough;
} }
@ -605,7 +605,7 @@ class Font extends AbstractStyle
* *
* @return bool * @return bool
*/ */
public function getSmallCaps() public function isSmallCaps()
{ {
return $this->smallCaps; return $this->smallCaps;
} }
@ -631,7 +631,7 @@ class Font extends AbstractStyle
* *
* @return bool * @return bool
*/ */
public function getAllCaps() public function isAllCaps()
{ {
return $this->allCaps; return $this->allCaps;
} }
@ -681,4 +681,59 @@ class Font extends AbstractStyle
return $this; return $this;
} }
/**
* Get bold
*
* @deprecated 0.10.0
* @codeCoverageIgnore
*/
public function getBold()
{
return $this->isBold();
}
/**
* Get italic
*
* @deprecated 0.10.0
* @codeCoverageIgnore
*/
public function getItalic()
{
return $this->isItalic();
}
/**
* Get superscript
*
* @deprecated 0.10.0
* @codeCoverageIgnore
*/
public function getSuperScript()
{
return $this->isSuperScript();
}
/**
* Get subscript
*
* @deprecated 0.10.0
* @codeCoverageIgnore
*/
public function getSubScript()
{
return $this->isSubScript();
}
/**
* Get strikethrough
*
* @deprecated 0.10.0
* @codeCoverageIgnore
*/
public function getStrikethrough()
{
return $this->isStrikethrough();
}
} }

View File

@ -340,7 +340,7 @@ class Paragraph extends AbstractStyle
/** /**
* Get parent style ID * Get parent style ID
* *
* @return string * @return string
*/ */
public function getBasedOn() public function getBasedOn()
{ {
@ -350,8 +350,8 @@ class Paragraph extends AbstractStyle
/** /**
* Set parent style ID * Set parent style ID
* *
* @param string $value * @param string $value
* @return self * @return self
*/ */
public function setBasedOn($value = 'Normal') public function setBasedOn($value = 'Normal')
{ {
@ -372,8 +372,8 @@ class Paragraph extends AbstractStyle
/** /**
* Set style for next paragraph * Set style for next paragraph
* *
* @param string $value * @param string $value
* @return self * @return self
*/ */
public function setNext($value = null) public function setNext($value = null)
{ {
@ -384,9 +384,9 @@ class Paragraph extends AbstractStyle
/** /**
* Get allow first/last line to display on a separate page setting * Get allow first/last line to display on a separate page setting
* *
* @return bool * @return bool
*/ */
public function getWidowControl() public function hasWidowControl()
{ {
return $this->widowControl; return $this->widowControl;
} }
@ -394,8 +394,8 @@ class Paragraph extends AbstractStyle
/** /**
* Set keep paragraph with next paragraph setting * Set keep paragraph with next paragraph setting
* *
* @param bool $value * @param bool $value
* @return self * @return self
*/ */
public function setWidowControl($value = true) public function setWidowControl($value = true)
{ {
@ -409,9 +409,9 @@ class Paragraph extends AbstractStyle
/** /**
* Get keep paragraph with next paragraph setting * Get keep paragraph with next paragraph setting
* *
* @return bool * @return bool
*/ */
public function getKeepNext() public function isKeepNext()
{ {
return $this->keepNext; return $this->keepNext;
} }
@ -419,8 +419,8 @@ class Paragraph extends AbstractStyle
/** /**
* Set keep paragraph with next paragraph setting * Set keep paragraph with next paragraph setting
* *
* @param bool $value * @param bool $value
* @return self * @return self
*/ */
public function setKeepNext($value = false) public function setKeepNext($value = false)
{ {
@ -434,9 +434,9 @@ class Paragraph extends AbstractStyle
/** /**
* Get keep all lines on one page setting * Get keep all lines on one page setting
* *
* @return bool * @return bool
*/ */
public function getKeepLines() public function isKeepLines()
{ {
return $this->keepLines; return $this->keepLines;
} }
@ -444,8 +444,8 @@ class Paragraph extends AbstractStyle
/** /**
* Set keep all lines on one page setting * Set keep all lines on one page setting
* *
* @param bool $value * @param bool $value
* @return self * @return self
*/ */
public function setKeepLines($value = false) public function setKeepLines($value = false)
{ {
@ -461,7 +461,7 @@ class Paragraph extends AbstractStyle
* *
* @return bool * @return bool
*/ */
public function getPageBreakBefore() public function hasPageBreakBefore()
{ {
return $this->pageBreakBefore; return $this->pageBreakBefore;
} }
@ -469,8 +469,8 @@ class Paragraph extends AbstractStyle
/** /**
* Set start paragraph on next page setting * Set start paragraph on next page setting
* *
* @param bool $value * @param bool $value
* @return self * @return self
*/ */
public function setPageBreakBefore($value = false) public function setPageBreakBefore($value = false)
{ {
@ -542,4 +542,48 @@ class Paragraph extends AbstractStyle
return $this; return $this;
} }
/**
* Get allow first/last line to display on a separate page setting
*
* @deprecated 0.10.0
* @codeCoverageIgnore
*/
public function getWidowControl()
{
return $this->hasWidowControl();
}
/**
* Get keep paragraph with next paragraph setting
*
* @deprecated 0.10.0
* @codeCoverageIgnore
*/
public function getKeepNext()
{
return $this->isKeepNext();
}
/**
* Get keep all lines on one page setting
*
* @deprecated 0.10.0
* @codeCoverageIgnore
*/
public function getKeepLines()
{
return $this->isKeepLines();
}
/**
* Get start paragraph on next page setting
*
* @deprecated 0.10.0
* @codeCoverageIgnore
*/
public function getPageBreakBefore()
{
return $this->hasPageBreakBefore();
}
} }

View File

@ -45,9 +45,19 @@ class Row extends AbstractStyle
} }
/** /**
* Set tblHeader * Is tblHeader
* *
* @param boolean $value * @return bool
*/
public function isTblHeader()
{
return $this->tblHeader;
}
/**
* Is tblHeader
*
* @param bool $value
* @return self * @return self
*/ */
public function setTblHeader($value = false) public function setTblHeader($value = false)
@ -56,19 +66,19 @@ class Row extends AbstractStyle
} }
/** /**
* Get tblHeader * Is cantSplit
* *
* @return boolean * @return bool
*/ */
public function getTblHeader() public function isCantSplit()
{ {
return $this->tblHeader; return $this->cantSplit;
} }
/** /**
* Set cantSplit * Is cantSplit
* *
* @param boolean $value * @param bool $value
* @return self * @return self
*/ */
public function setCantSplit($value = false) public function setCantSplit($value = false)
@ -77,13 +87,13 @@ class Row extends AbstractStyle
} }
/** /**
* Get cantSplit * Is exactHeight
* *
* @return boolean * @return bool
*/ */
public function getCantSplit() public function isExactHeight()
{ {
return $this->cantSplit; return $this->exactHeight;
} }
/** /**
@ -98,13 +108,36 @@ class Row extends AbstractStyle
return $this; return $this;
} }
/**
* Get tblHeader
*
* @deprecated 0.10.0
* @codeCoverageIgnore
*/
public function getTblHeader()
{
return $this->isTblHeader();
}
/**
* Get cantSplit
*
* @deprecated 0.10.0
* @codeCoverageIgnore
*/
public function getCantSplit()
{
return $this->isCantSplit();
}
/** /**
* Get exactHeight * Get exactHeight
* *
* @return boolean * @deprecated 0.10.0
* @codeCoverageIgnore
*/ */
public function getExactHeight() public function getExactHeight()
{ {
return $this->exactHeight; return $this->isExactHeight();
} }
} }

View File

@ -53,7 +53,7 @@ class TOC extends Tab
*/ */
public function setTabPos($value) public function setTabPos($value)
{ {
$this->position = $value; $this->setPosition($value);
} }
/** /**
@ -73,7 +73,7 @@ class TOC extends Tab
*/ */
public function setTabLeader($value = self::TABLEADER_DOT) public function setTabLeader($value = self::TABLEADER_DOT)
{ {
$this->leader = $value; $this->setLeader($value);
} }
/** /**

View File

@ -224,7 +224,7 @@ class Table extends Border
/** /**
* Set border size inside horizontal * Set border size inside horizontal
* *
* @param $value * @param int $value
*/ */
public function setBorderInsideHSize($value = null) public function setBorderInsideHSize($value = null)
{ {
@ -234,7 +234,7 @@ class Table extends Border
/** /**
* Get border size inside horizontal * Get border size inside horizontal
* *
* @return * @return int
*/ */
public function getBorderInsideHSize() public function getBorderInsideHSize()
{ {
@ -244,7 +244,7 @@ class Table extends Border
/** /**
* Set border size inside vertical * Set border size inside vertical
* *
* @param $value * @param int $value
*/ */
public function setBorderInsideVSize($value = null) public function setBorderInsideVSize($value = null)
{ {
@ -254,7 +254,7 @@ class Table extends Border
/** /**
* Get border size inside vertical * Get border size inside vertical
* *
* @return * @return int
*/ */
public function getBorderInsideVSize() public function getBorderInsideVSize()
{ {
@ -264,7 +264,7 @@ class Table extends Border
/** /**
* Set border color inside horizontal * Set border color inside horizontal
* *
* @param $value * @param string $value
*/ */
public function setBorderInsideHColor($value = null) public function setBorderInsideHColor($value = null)
{ {
@ -274,7 +274,7 @@ class Table extends Border
/** /**
* Get border color inside horizontal * Get border color inside horizontal
* *
* @return * @return string
*/ */
public function getBorderInsideHColor() public function getBorderInsideHColor()
{ {
@ -284,7 +284,7 @@ class Table extends Border
/** /**
* Set border color inside vertical * Set border color inside vertical
* *
* @param $value * @param string $value
*/ */
public function setBorderInsideVColor($value = null) public function setBorderInsideVColor($value = null)
{ {
@ -294,7 +294,7 @@ class Table extends Border
/** /**
* Get border color inside vertical * Get border color inside vertical
* *
* @return * @return string
*/ */
public function getBorderInsideVColor() public function getBorderInsideVColor()
{ {

View File

@ -1,84 +0,0 @@
<?php
/**
* PHPWord
*
* @link https://github.com/PHPOffice/PHPWord
* @copyright 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
namespace PhpOffice\PhpWord;
/**
* Table of contents
*
* This static class has been deprecated and replaced by Collection\Titles.
* File maintained for backward compatibility and will be removed on 1.0.
*
* @deprecated 0.10.0
* @codeCoverageIgnore
*/
class TOC
{
/**
* Title elements
*
* @var array
*/
private static $titles = array();
/**
* Title anchor
*
* @var int
*/
private static $anchor = 252634154;
/**
* Title bookmark
*
* @var int
*/
private static $bookmarkId = 0;
/**
* Add a Title
*
* @param string $text
* @param int $depth
* @return array
*/
public static function addTitle($text, $depth = 0)
{
$anchor = '_Toc' . ++self::$anchor;
$bookmarkId = self::$bookmarkId++;
$title = array();
$title['text'] = $text;
$title['depth'] = $depth;
$title['anchor'] = $anchor;
$title['bookmarkId'] = $bookmarkId;
self::$titles[] = $title;
return array($anchor, $bookmarkId);
}
/**
* Get all titles
*
* @return array
*/
public static function getTitles()
{
return self::$titles;
}
/**
* Reset titles
*/
public static function resetTitles()
{
self::$titles = array();
}
}

View File

@ -44,7 +44,7 @@ abstract class AbstractWriter implements WriterInterface
/** /**
* Use disk caching * Use disk caching
* *
* @var boolean * @var bool
*/ */
private $useDiskCaching = false; private $useDiskCaching = false;
@ -121,9 +121,9 @@ abstract class AbstractWriter implements WriterInterface
/** /**
* Get use disk caching status * Get use disk caching status
* *
* @return boolean * @return bool
*/ */
public function getUseDiskCaching() public function isUseDiskCaching()
{ {
return $this->useDiskCaching; return $this->useDiskCaching;
} }
@ -131,7 +131,7 @@ abstract class AbstractWriter implements WriterInterface
/** /**
* Set use disk caching status * Set use disk caching status
* *
* @param boolean $pValue * @param bool $pValue
* @param string $pDirectory * @param string $pDirectory
* @return self * @return self
*/ */
@ -356,4 +356,15 @@ abstract class AbstractWriter implements WriterInterface
rmdir($dir); rmdir($dir);
} }
/**
* Get use disk caching status
*
* @deprecated 0.10.0
* @codeCoverageIgnore
*/
public function getUseDiskCaching()
{
return $this->isUseDiskCaching();
}
} }

View File

@ -41,22 +41,22 @@ class Font extends AbstractStyle
$css['color'] = '#' . $this->style->getColor(); $css['color'] = '#' . $this->style->getColor();
} }
$css['background'] = $this->style->getFgColor(); $css['background'] = $this->style->getFgColor();
if ($this->style->getBold()) { if ($this->style->isBold()) {
$css['font-weight'] = 'bold'; $css['font-weight'] = 'bold';
} }
if ($this->style->getItalic()) { if ($this->style->isItalic()) {
$css['font-style'] = 'italic'; $css['font-style'] = 'italic';
} }
if ($this->style->getSuperScript()) { if ($this->style->isSuperScript()) {
$css['vertical-align'] = 'super'; $css['vertical-align'] = 'super';
} elseif ($this->style->getSubScript()) { } elseif ($this->style->isSubScript()) {
$css['vertical-align'] = 'sub'; $css['vertical-align'] = 'sub';
} }
$css['text-decoration'] = ''; $css['text-decoration'] = '';
if ($this->style->getUnderline() != FontStyle::UNDERLINE_NONE) { if ($this->style->getUnderline() != FontStyle::UNDERLINE_NONE) {
$css['text-decoration'] .= 'underline '; $css['text-decoration'] .= 'underline ';
} }
if ($this->style->getStrikethrough()) { if ($this->style->isStrikethrough()) {
$css['text-decoration'] .= 'line-through '; $css['text-decoration'] .= 'line-through ';
} }

View File

@ -25,12 +25,12 @@ class Text extends Element
$paragraphStyle = $this->element->getParagraphStyle(); $paragraphStyle = $this->element->getParagraphStyle();
// @todo Commented for TextRun. Should really checkout this value // @todo Commented for TextRun. Should really checkout this value
// $SfIsObject = ($fontStyle instanceof Font) ? true : false; // $fStyleIsObject = ($fontStyle instanceof Font) ? true : false;
$SfIsObject = false; $fStyleIsObject = false;
if ($SfIsObject) { if ($fStyleIsObject) {
// Don't never be the case, because I browse all sections for cleaning all styles not declared // Don't never be the case, because I browse all sections for cleaning all styles not declared
throw new Exception('PhpWord : $SfIsObject wouldn\'t be an object'); throw new Exception('PhpWord : $fStyleIsObject wouldn\'t be an object');
} else { } else {
if (!$this->withoutP) { if (!$this->withoutP) {
$this->xmlWriter->startElement('text:p'); // text:p $this->xmlWriter->startElement('text:p'); // text:p

View File

@ -48,12 +48,12 @@ class Font extends AbstractStyle
if ($this->style->getColor()) { if ($this->style->getColor()) {
$this->xmlWriter->writeAttribute('fo:color', '#' . $this->style->getColor()); $this->xmlWriter->writeAttribute('fo:color', '#' . $this->style->getColor());
} }
if ($this->style->getItalic()) { if ($this->style->isItalic()) {
$this->xmlWriter->writeAttribute('fo:font-style', 'italic'); $this->xmlWriter->writeAttribute('fo:font-style', 'italic');
$this->xmlWriter->writeAttribute('style:font-style-asian', 'italic'); $this->xmlWriter->writeAttribute('style:font-style-asian', 'italic');
$this->xmlWriter->writeAttribute('style:font-style-complex', 'italic'); $this->xmlWriter->writeAttribute('style:font-style-complex', 'italic');
} }
if ($this->style->getBold()) { if ($this->style->isBold()) {
$this->xmlWriter->writeAttribute('fo:font-weight', 'bold'); $this->xmlWriter->writeAttribute('fo:font-weight', 'bold');
$this->xmlWriter->writeAttribute('style:font-weight-asian', 'bold'); $this->xmlWriter->writeAttribute('style:font-weight-asian', 'bold');
} }

View File

@ -73,10 +73,10 @@ class Text extends Element
} else { } else {
$rtfText .= '\f0'; $rtfText .= '\f0';
} }
if ($fontStyle->getBold()) { if ($fontStyle->isBold()) {
$rtfText .= '\b'; $rtfText .= '\b';
} }
if ($fontStyle->getItalic()) { if ($fontStyle->isItalic()) {
$rtfText .= '\i'; $rtfText .= '\i';
} }
if ($fontStyle->getSize()) { if ($fontStyle->getSize()) {
@ -92,10 +92,10 @@ class Text extends Element
$rtfText .= '\cf0'; $rtfText .= '\cf0';
$rtfText .= '\f0'; $rtfText .= '\f0';
if ($fontStyle->getBold()) { if ($fontStyle->isBold()) {
$rtfText .= '\b0'; $rtfText .= '\b0';
} }
if ($fontStyle->getItalic()) { if ($fontStyle->isItalic()) {
$rtfText .= '\i0'; $rtfText .= '\i0';
} }
if ($fontStyle->getSize()) { if ($fontStyle->getSize()) {

View File

@ -23,7 +23,7 @@ class Image extends Element
*/ */
public function write() public function write()
{ {
if ($this->element->getIsWatermark()) { if ($this->element->isWatermark()) {
$this->writeWatermark(); $this->writeWatermark();
} else { } else {
$this->writeImage(); $this->writeImage();

View File

@ -84,25 +84,22 @@ class Table extends Element
$row = $rows[$i]; $row = $rows[$i];
$height = $row->getHeight(); $height = $row->getHeight();
$rowStyle = $row->getStyle(); $rowStyle = $row->getStyle();
$tblHeader = $rowStyle->getTblHeader();
$cantSplit = $rowStyle->getCantSplit();
$exactHeight = $rowStyle->getExactHeight();
$this->xmlWriter->startElement('w:tr'); $this->xmlWriter->startElement('w:tr');
if (!is_null($height) || !is_null($tblHeader) || !is_null($cantSplit)) { if (!is_null($height) || $rowStyle->isTblHeader() || $rowStyle->isCantSplit()) {
$this->xmlWriter->startElement('w:trPr'); $this->xmlWriter->startElement('w:trPr');
if (!is_null($height)) { if (!is_null($height)) {
$this->xmlWriter->startElement('w:trHeight'); $this->xmlWriter->startElement('w:trHeight');
$this->xmlWriter->writeAttribute('w:val', $height); $this->xmlWriter->writeAttribute('w:val', $height);
$this->xmlWriter->writeAttribute('w:hRule', ($exactHeight ? 'exact' : 'atLeast')); $this->xmlWriter->writeAttribute('w:hRule', ($rowStyle->isExactHeight() ? 'exact' : 'atLeast'));
$this->xmlWriter->endElement(); $this->xmlWriter->endElement();
} }
if ($tblHeader) { if ($rowStyle->isTblHeader()) {
$this->xmlWriter->startElement('w:tblHeader'); $this->xmlWriter->startElement('w:tblHeader');
$this->xmlWriter->writeAttribute('w:val', '1'); $this->xmlWriter->writeAttribute('w:val', '1');
$this->xmlWriter->endElement(); $this->xmlWriter->endElement();
} }
if ($cantSplit) { if ($rowStyle->isCantSplit()) {
$this->xmlWriter->startElement('w:cantSplit'); $this->xmlWriter->startElement('w:cantSplit');
$this->xmlWriter->writeAttribute('w:val', '1'); $this->xmlWriter->writeAttribute('w:val', '1');
$this->xmlWriter->endElement(); $this->xmlWriter->endElement();

View File

@ -63,7 +63,7 @@ abstract class AbstractPart
{ {
$useDiskCaching = false; $useDiskCaching = false;
if (!is_null($this->parentWriter)) { if (!is_null($this->parentWriter)) {
if ($this->parentWriter->getUseDiskCaching()) { if ($this->parentWriter->isUseDiskCaching()) {
$useDiskCaching = true; $useDiskCaching = true;
} }
} }

View File

@ -24,24 +24,24 @@ class ContentTypes extends AbstractPart
*/ */
public function writeContentTypes($contentTypes) public function writeContentTypes($contentTypes)
{ {
$OpenXMLPrefix = 'application/vnd.openxmlformats-'; $openXMLPrefix = 'application/vnd.openxmlformats-';
$WordMLPrefix = $OpenXMLPrefix . 'officedocument.wordprocessingml.'; $wordMLPrefix = $openXMLPrefix . 'officedocument.wordprocessingml.';
$overrides = array( $overrides = array(
'/docProps/core.xml' => $OpenXMLPrefix . 'package.core-properties+xml', '/docProps/core.xml' => $openXMLPrefix . 'package.core-properties+xml',
'/docProps/app.xml' => $OpenXMLPrefix . 'officedocument.extended-properties+xml', '/docProps/app.xml' => $openXMLPrefix . 'officedocument.extended-properties+xml',
'/word/document.xml' => $WordMLPrefix . 'document.main+xml', '/word/document.xml' => $wordMLPrefix . 'document.main+xml',
'/word/styles.xml' => $WordMLPrefix . 'styles+xml', '/word/styles.xml' => $wordMLPrefix . 'styles+xml',
'/word/numbering.xml' => $WordMLPrefix . 'numbering+xml', '/word/numbering.xml' => $wordMLPrefix . 'numbering+xml',
'/word/settings.xml' => $WordMLPrefix . 'settings+xml', '/word/settings.xml' => $wordMLPrefix . 'settings+xml',
'/word/theme/theme1.xml' => $OpenXMLPrefix . 'officedocument.theme+xml', '/word/theme/theme1.xml' => $openXMLPrefix . 'officedocument.theme+xml',
'/word/webSettings.xml' => $WordMLPrefix . 'webSettings+xml', '/word/webSettings.xml' => $wordMLPrefix . 'webSettings+xml',
'/word/fontTable.xml' => $WordMLPrefix . 'fontTable+xml', '/word/fontTable.xml' => $wordMLPrefix . 'fontTable+xml',
); );
$defaults = $contentTypes['default']; $defaults = $contentTypes['default'];
if (!empty($contentTypes['override'])) { if (!empty($contentTypes['override'])) {
foreach ($contentTypes['override'] as $key => $val) { foreach ($contentTypes['override'] as $key => $val) {
$overrides[$key] = $WordMLPrefix . $val . '+xml'; $overrides[$key] = $wordMLPrefix . $val . '+xml';
} }
} }

View File

@ -89,12 +89,12 @@ class Font extends AbstractStyle
} }
// Bold // Bold
if ($this->style->getBold()) { if ($this->style->isBold()) {
$this->xmlWriter->writeElement('w:b', null); $this->xmlWriter->writeElement('w:b', null);
} }
// Italic // Italic
if ($this->style->getItalic()) { if ($this->style->isItalic()) {
$this->xmlWriter->writeElement('w:i', null); $this->xmlWriter->writeElement('w:i', null);
$this->xmlWriter->writeElement('w:iCs', null); $this->xmlWriter->writeElement('w:iCs', null);
} }
@ -107,12 +107,12 @@ class Font extends AbstractStyle
} }
// Strikethrough // Strikethrough
if ($this->style->getStrikethrough()) { if ($this->style->isStrikethrough()) {
$this->xmlWriter->writeElement('w:strike', null); $this->xmlWriter->writeElement('w:strike', null);
} }
// Double strikethrough // Double strikethrough
if ($this->style->getDoubleStrikethrough()) { if ($this->style->isDoubleStrikethrough()) {
$this->xmlWriter->writeElement('w:dstrike', null); $this->xmlWriter->writeElement('w:dstrike', null);
} }
@ -130,19 +130,19 @@ class Font extends AbstractStyle
} }
// Superscript/subscript // Superscript/subscript
if ($this->style->getSuperScript() || $this->style->getSubScript()) { if ($this->style->isSuperScript() || $this->style->isSubScript()) {
$this->xmlWriter->startElement('w:vertAlign'); $this->xmlWriter->startElement('w:vertAlign');
$this->xmlWriter->writeAttribute('w:val', $this->style->getSuperScript() ? 'superscript' : 'subscript'); $this->xmlWriter->writeAttribute('w:val', $this->style->isSuperScript() ? 'superscript' : 'subscript');
$this->xmlWriter->endElement(); $this->xmlWriter->endElement();
} }
// Small caps // Small caps
if ($this->style->getSmallCaps()) { if ($this->style->isSmallCaps()) {
$this->xmlWriter->writeElement('w:smallCaps', null); $this->xmlWriter->writeElement('w:smallCaps', null);
} }
// All caps // All caps
if ($this->style->getAllCaps()) { if ($this->style->isAllCaps()) {
$this->xmlWriter->writeElement('w:caps', null); $this->xmlWriter->writeElement('w:caps', null);
} }

View File

@ -64,11 +64,6 @@ class Paragraph extends AbstractStyle
return; return;
} }
$widowControl = $this->style->getWidowControl();
$keepNext = $this->style->getKeepNext();
$keepLines = $this->style->getKeepLines();
$pageBreakBefore = $this->style->getPageBreakBefore();
if (!$this->withoutPPR) { if (!$this->withoutPPR) {
$this->xmlWriter->startElement('w:pPr'); $this->xmlWriter->startElement('w:pPr');
} }
@ -93,22 +88,22 @@ class Paragraph extends AbstractStyle
} }
// Pagination // Pagination
if (!$widowControl) { if (!$this->style->hasWidowControl()) {
$this->xmlWriter->startElement('w:widowControl'); $this->xmlWriter->startElement('w:widowControl');
$this->xmlWriter->writeAttribute('w:val', '0'); $this->xmlWriter->writeAttribute('w:val', '0');
$this->xmlWriter->endElement(); $this->xmlWriter->endElement();
} }
if ($keepNext) { if ($this->style->isKeepNext()) {
$this->xmlWriter->startElement('w:keepNext'); $this->xmlWriter->startElement('w:keepNext');
$this->xmlWriter->writeAttribute('w:val', '1'); $this->xmlWriter->writeAttribute('w:val', '1');
$this->xmlWriter->endElement(); $this->xmlWriter->endElement();
} }
if ($keepLines) { if ($this->style->isKeepLines()) {
$this->xmlWriter->startElement('w:keepLines'); $this->xmlWriter->startElement('w:keepLines');
$this->xmlWriter->writeAttribute('w:val', '1'); $this->xmlWriter->writeAttribute('w:val', '1');
$this->xmlWriter->endElement(); $this->xmlWriter->endElement();
} }
if ($pageBreakBefore) { if ($this->style->hasPageBreakBefore()) {
$this->xmlWriter->startElement('w:pageBreakBefore'); $this->xmlWriter->startElement('w:pageBreakBefore');
$this->xmlWriter->writeAttribute('w:val', '1'); $this->xmlWriter->writeAttribute('w:val', '1');
$this->xmlWriter->endElement(); $this->xmlWriter->endElement();

View File

@ -29,7 +29,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $oImage); $this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $oImage);
$this->assertEquals($oImage->getSource(), $src); $this->assertEquals($oImage->getSource(), $src);
$this->assertEquals($oImage->getMediaId(), md5($src)); $this->assertEquals($oImage->getMediaId(), md5($src));
$this->assertEquals($oImage->getIsWatermark(), false); $this->assertEquals($oImage->isWatermark(), false);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle()); $this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oImage->getStyle());
} }
@ -72,7 +72,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($image->getImageExtension(), $extension); $this->assertEquals($image->getImageExtension(), $extension);
$this->assertEquals($image->getImageCreateFunction(), $createFunction); $this->assertEquals($image->getImageCreateFunction(), $createFunction);
$this->assertEquals($image->getImageFunction(), $imageFunction); $this->assertEquals($image->getImageFunction(), $imageFunction);
$this->assertFalse($image->getIsMemImage()); $this->assertFalse($image->isMemImage());
} }
} }

View File

@ -23,9 +23,9 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
*/ */
public function testSetGetCompatibility() public function testSetGetCompatibility()
{ {
$this->assertTrue(Settings::getCompatibility()); $this->assertTrue(Settings::hasCompatibility());
$this->assertTrue(Settings::setCompatibility(false)); $this->assertTrue(Settings::setCompatibility(false));
$this->assertFalse(Settings::getCompatibility()); $this->assertFalse(Settings::hasCompatibility());
$this->assertFalse(Settings::setCompatibility('Non boolean')); $this->assertFalse(Settings::setCompatibility('Non boolean'));
} }

View File

@ -32,7 +32,7 @@ class DrawingTest extends \PHPUnit_Framework_TestCase
$result = Drawing::pixelsToEMU($value); $result = Drawing::pixelsToEMU($value);
$this->assertEquals(round($value * 9525), $result); $this->assertEquals(round($value * 9525), $result);
$result = Drawing::EMUToPixels($value); $result = Drawing::emuToPixels($value);
$this->assertEquals(round($value / 9525), $result); $this->assertEquals(round($value / 9525), $result);
$result = Drawing::pixelsToPoints($value); $result = Drawing::pixelsToPoints($value);

View File

@ -129,7 +129,7 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
{ {
$object = new ODText(); $object = new ODText();
$object->setUseDiskCaching(true, PHPWORD_TESTS_BASE_DIR); $object->setUseDiskCaching(true, PHPWORD_TESTS_BASE_DIR);
$this->assertTrue($object->getUseDiskCaching()); $this->assertTrue($object->isUseDiskCaching());
$this->assertEquals(PHPWORD_TESTS_BASE_DIR, $object->getDiskCachingDirectory()); $this->assertEquals(PHPWORD_TESTS_BASE_DIR, $object->getDiskCachingDirectory());
} }

View File

@ -177,7 +177,7 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
$writer = new Word2007($phpWord); $writer = new Word2007($phpWord);
$writer->save('php://output'); $writer->save('php://output');
$this->assertTrue($object->getUseDiskCaching()); $this->assertTrue($object->isUseDiskCaching());
} }
/** /**