QA: Scrutinizer dedup

This commit is contained in:
Ivan Lanin 2014-05-15 14:41:08 +07:00
parent 1c3735fc08
commit 4d9e4062c3
36 changed files with 136 additions and 173 deletions

View File

@ -54,47 +54,47 @@ abstract class AbstractReader implements ReaderInterface
/** /**
* Set read data only * Set read data only
* *
* @param bool $pValue * @param bool $value
* @return self * @return self
*/ */
public function setReadDataOnly($pValue = true) public function setReadDataOnly($value = true)
{ {
$this->readDataOnly = $pValue; $this->readDataOnly = $value;
return $this; return $this;
} }
/** /**
* Open file for reading * Open file for reading
* *
* @param string $pFilename * @param string $filename
* @return resource * @return resource
* @throws \PhpOffice\PhpWord\Exception\Exception * @throws \PhpOffice\PhpWord\Exception\Exception
*/ */
protected function openFile($pFilename) protected function openFile($filename)
{ {
// Check if file exists // Check if file exists
if (!file_exists($pFilename) || !is_readable($pFilename)) { if (!file_exists($filename) || !is_readable($filename)) {
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist."); throw new Exception("Could not open " . $filename . " for reading! File does not exist.");
} }
// Open file // Open file
$this->fileHandle = fopen($pFilename, 'r'); $this->fileHandle = fopen($filename, 'r');
if ($this->fileHandle === false) { if ($this->fileHandle === false) {
throw new Exception("Could not open file " . $pFilename . " for reading."); throw new Exception("Could not open file " . $filename . " for reading.");
} }
} }
/** /**
* Can the current ReaderInterface read the file? * Can the current ReaderInterface read the file?
* *
* @param string $pFilename * @param string $filename
* @return bool * @return bool
*/ */
public function canRead($pFilename) public function canRead($filename)
{ {
// Check if file exists // Check if file exists
try { try {
$this->openFile($pFilename); $this->openFile($filename);
} catch (Exception $e) { } catch (Exception $e) {
return false; return false;
} }

View File

@ -18,11 +18,12 @@
namespace PhpOffice\PhpWord\Reader\ODText; namespace PhpOffice\PhpWord\Reader\ODText;
use PhpOffice\PhpWord\Shared\XMLReader; use PhpOffice\PhpWord\Shared\XMLReader;
use PhpOffice\PhpWord\Reader\Word2007\AbstractPart as Word2007AbstractPart;
/** /**
* Abstract part reader * Abstract part reader
*/ */
abstract class AbstractPart extends \PhpOffice\PhpWord\Reader\Word2007\AbstractPart abstract class AbstractPart extends Word2007AbstractPart
{ {
/** /**
* Read w:r (override) * Read w:r (override)

View File

@ -25,15 +25,15 @@ interface ReaderInterface
/** /**
* Can the current ReaderInterface read the file? * Can the current ReaderInterface read the file?
* *
* @param string $pFilename * @param string $filename
* @return boolean * @return boolean
*/ */
public function canRead($pFilename); public function canRead($filename);
/** /**
* Loads PhpWord from file * Loads PhpWord from file
* *
* @param string $pFilename * @param string $filename
*/ */
public function load($pFilename); public function load($filename);
} }

View File

@ -633,7 +633,7 @@ class Font extends AbstractStyle
* Set $property value and set $pairProperty = false when $value = true * Set $property value and set $pairProperty = false when $value = true
* *
* @param bool $property * @param bool $property
* @param bool $pair * @param bool $pairProperty
* @param bool $value * @param bool $value
* @return self * @return self
*/ */

View File

@ -29,12 +29,19 @@ class Table extends Border
const WIDTH_PERCENT = 'pct'; // Width in fiftieths (1/50) of a percent (1% = 50 unit) const WIDTH_PERCENT = 'pct'; // Width in fiftieths (1/50) of a percent (1% = 50 unit)
const WIDTH_TWIP = 'dxa'; // Width in twentieths (1/20) of a point (twip) const WIDTH_TWIP = 'dxa'; // Width in twentieths (1/20) of a point (twip)
/**
* Is this a first row style?
*
* @var bool
*/
private $isFirstRow = false;
/** /**
* Style for first row * Style for first row
* *
* @var \PhpOffice\PhpWord\Style\Table * @var \PhpOffice\PhpWord\Style\Table
*/ */
private $firstRow; private $firstRowStyle;
/** /**
* Cell margin top * Cell margin top
@ -126,17 +133,18 @@ class Table extends Border
// Clone first row from table style, but with certain properties disabled // Clone first row from table style, but with certain properties disabled
if ($firstRowStyle !== null && is_array($firstRowStyle)) { if ($firstRowStyle !== null && is_array($firstRowStyle)) {
$this->firstRow = clone $this; $this->firstRowStyle = clone $this;
unset($this->firstRow->firstRow); $this->firstRowStyle->isFirstRow = true;
unset($this->firstRow->borderInsideHSize); unset($this->firstRowStyle->firstRowStyle);
unset($this->firstRow->borderInsideHColor); unset($this->firstRowStyle->borderInsideHSize);
unset($this->firstRow->borderInsideVSize); unset($this->firstRowStyle->borderInsideHColor);
unset($this->firstRow->borderInsideVColor); unset($this->firstRowStyle->borderInsideVSize);
unset($this->firstRow->cellMarginTop); unset($this->firstRowStyle->borderInsideVColor);
unset($this->firstRow->cellMarginLeft); unset($this->firstRowStyle->cellMarginTop);
unset($this->firstRow->cellMarginRight); unset($this->firstRowStyle->cellMarginLeft);
unset($this->firstRow->cellMarginBottom); unset($this->firstRowStyle->cellMarginRight);
$this->firstRow->setStyleByArray($firstRowStyle); unset($this->firstRowStyle->cellMarginBottom);
$this->firstRowStyle->setStyleByArray($firstRowStyle);
} }
if ($tableStyle !== null && is_array($tableStyle)) { if ($tableStyle !== null && is_array($tableStyle)) {
@ -145,13 +153,13 @@ class Table extends Border
} }
/** /**
* Get First Row Style * Set first row
* *
* @return \PhpOffice\PhpWord\Style\Table * @return \PhpOffice\PhpWord\Style\Table
*/ */
public function getFirstRow() public function getFirstRow()
{ {
return $this->firstRow; return $this->firstRowStyle;
} }
/** /**
@ -556,7 +564,7 @@ class Table extends Border
} }
/** /**
* Get table style only property by checking if firstRow is set * Get table style only property by checking if it's a firstRow
* *
* This is necessary since firstRow style is cloned from table style but * This is necessary since firstRow style is cloned from table style but
* without certain properties activated, e.g. margins * without certain properties activated, e.g. margins
@ -566,7 +574,7 @@ class Table extends Border
*/ */
private function getTableOnlyProperty($property) private function getTableOnlyProperty($property)
{ {
if (isset($this->firstRow)) { if ($this->isFirstRow === false) {
return $this->$property; return $this->$property;
} }
@ -574,7 +582,7 @@ class Table extends Border
} }
/** /**
* Set table style only property by checking if firstRow is set * Set table style only property by checking if it's a firstRow
* *
* This is necessary since firstRow style is cloned from table style but * This is necessary since firstRow style is cloned from table style but
* without certain properties activated, e.g. margins * without certain properties activated, e.g. margins
@ -586,8 +594,8 @@ class Table extends Border
*/ */
private function setTableOnlyProperty($property, $value, $isNumeric = true) private function setTableOnlyProperty($property, $value, $isNumeric = true)
{ {
if (isset($this->firstRow)) { if ($this->isFirstRow === false) {
if ($isNumeric) { if ($isNumeric === true) {
$this->$property = $this->setNumericVal($value, $this->$property); $this->$property = $this->setNumericVal($value, $this->$property);
} else { } else {
$this->$property = $value; $this->$property = $value;

View File

@ -335,7 +335,7 @@ abstract class AbstractWriter implements WriterInterface
$source = substr($source, 6); $source = substr($source, 6);
list($zipFilename, $imageFilename) = explode('#', $source); list($zipFilename, $imageFilename) = explode('#', $source);
$zipClass = \PhpOffice\PhpWord\Settings::getZipClass(); $zipClass = Settings::getZipClass();
$zip = new $zipClass(); $zip = new $zipClass();
if ($zip->open($zipFilename) !== false) { if ($zip->open($zipFilename) !== false) {
if ($zip->locateName($imageFilename)) { if ($zip->locateName($imageFilename)) {

View File

@ -62,14 +62,10 @@ class HTML extends AbstractWriter implements WriterInterface
* Save PhpWord to file * Save PhpWord to file
* *
* @param string $filename * @param string $filename
* @throws Exception * @throws \PhpOffice\PhpWord\Exception\Exception
*/ */
public function save($filename = null) public function save($filename = null)
{ {
if (is_null($this->phpWord)) {
throw new Exception('PhpWord object unassigned.');
}
$this->setTempDir(sys_get_temp_dir() . '/PHPWordWriter/'); $this->setTempDir(sys_get_temp_dir() . '/PHPWordWriter/');
$hFile = fopen($filename, 'w'); $hFile = fopen($filename, 'w');
if ($hFile !== false) { if ($hFile !== false) {
@ -111,7 +107,8 @@ class HTML extends AbstractWriter implements WriterInterface
*/ */
private function writeHead() private function writeHead()
{ {
$properties = $this->getPhpWord()->getDocumentProperties(); $phpWord = $this->getPhpWord();
$properties = $phpWord->getDocumentProperties();
$propertiesMapping = array( $propertiesMapping = array(
'creator' => 'author', 'creator' => 'author',
'title' => '', 'title' => '',
@ -171,13 +168,14 @@ class HTML extends AbstractWriter implements WriterInterface
*/ */
private function writeStyles() private function writeStyles()
{ {
$phpWord = $this->getPhpWord();
$css = '<style>' . PHP_EOL; $css = '<style>' . PHP_EOL;
// Default styles // Default styles
$defaultStyles = array( $defaultStyles = array(
'*' => array( '*' => array(
'font-family' => $this->getPhpWord()->getDefaultFontName(), 'font-family' => $phpWord->getDefaultFontName(),
'font-size' => $this->getPhpWord()->getDefaultFontSize() . 'pt', 'font-size' => $phpWord->getDefaultFontSize() . 'pt',
), ),
'a.NoteRef' => array( 'a.NoteRef' => array(
'text-decoration' => 'none', 'text-decoration' => 'none',

View File

@ -17,6 +17,8 @@
namespace PhpOffice\PhpWord\Writer\HTML\Element; namespace PhpOffice\PhpWord\Writer\HTML\Element;
use PhpOffice\PhpWord\Element\AbstractContainer as ContainerElement;
/** /**
* Container element HTML writer * Container element HTML writer
* *
@ -39,7 +41,7 @@ class Container extends AbstractElement
public function write() public function write()
{ {
$container = $this->element; $container = $this->element;
if (!$container instanceof \PhpOffice\PhpWord\Element\AbstractContainer) { if (!$container instanceof ContainerElement) {
return ''; return '';
} }
$containerClass = substr(get_class($container), strrpos(get_class($container), '\\') + 1); $containerClass = substr(get_class($container), strrpos(get_class($container), '\\') + 1);

View File

@ -18,6 +18,7 @@
namespace PhpOffice\PhpWord\Writer\HTML\Element; namespace PhpOffice\PhpWord\Writer\HTML\Element;
use PhpOffice\PhpWord\Element\Image as ImageElement; use PhpOffice\PhpWord\Element\Image as ImageElement;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Writer\HTML\Style\Image as ImageStyleWriter; use PhpOffice\PhpWord\Writer\HTML\Style\Image as ImageStyleWriter;
/** /**
@ -34,7 +35,7 @@ class Image extends Text
*/ */
public function write() public function write()
{ {
if (!$this->element instanceof \PhpOffice\PhpWord\Element\Image) { if (!$this->element instanceof ImageElement) {
return ''; return '';
} }
/** @var \PhpOffice\PhpWord\Writer\HTML $parentWriter Type hint */ /** @var \PhpOffice\PhpWord\Writer\HTML $parentWriter Type hint */
@ -76,7 +77,7 @@ class Image extends Text
$source = substr($source, 6); $source = substr($source, 6);
list($zipFilename, $imageFilename) = explode('#', $source); list($zipFilename, $imageFilename) = explode('#', $source);
$zipClass = \PhpOffice\PhpWord\Settings::getZipClass(); $zipClass = Settings::getZipClass();
$zip = new $zipClass(); $zip = new $zipClass();
if ($zip->open($zipFilename) !== false) { if ($zip->open($zipFilename) !== false) {
if ($zip->locateName($imageFilename)) { if ($zip->locateName($imageFilename)) {

View File

@ -35,7 +35,7 @@ class Font extends AbstractStyle
public function write() public function write()
{ {
$style = $this->getStyle(); $style = $this->getStyle();
if (!$style instanceof \PhpOffice\PhpWord\Style\Font) { if (!$style instanceof FontStyle) {
return ''; return '';
} }
$css = array(); $css = array();

View File

@ -67,10 +67,6 @@ class ODText extends AbstractWriter implements WriterInterface
*/ */
public function save($filename = null) public function save($filename = null)
{ {
if (is_null($this->phpWord)) {
throw new Exception('PhpWord object unassigned.');
}
$filename = $this->getTempFile($filename); $filename = $this->getTempFile($filename);
$objZip = $this->getZipArchive($filename); $objZip = $this->getZipArchive($filename);

View File

@ -17,11 +17,13 @@
namespace PhpOffice\PhpWord\Writer\ODText\Element; namespace PhpOffice\PhpWord\Writer\ODText\Element;
use PhpOffice\PhpWord\Writer\Word2007\Element\AbstractElement as Word2007AbstractElement;
/** /**
* Abstract element writer * Abstract element writer
* *
* @since 0.11.0 * @since 0.11.0
*/ */
abstract class AbstractElement extends \PhpOffice\PhpWord\Writer\Word2007\Element\AbstractElement abstract class AbstractElement extends Word2007AbstractElement
{ {
} }

View File

@ -17,12 +17,14 @@
namespace PhpOffice\PhpWord\Writer\ODText\Element; namespace PhpOffice\PhpWord\Writer\ODText\Element;
use PhpOffice\PhpWord\Writer\Word2007\Element\Container as Word2007Container;
/** /**
* Container element writer (section, textrun, header, footnote, cell, etc.) * Container element writer (section, textrun, header, footnote, cell, etc.)
* *
* @since 0.11.0 * @since 0.11.0
*/ */
class Container extends \PhpOffice\PhpWord\Writer\Word2007\Element\Container class Container extends Word2007Container
{ {
/** /**
* Namespace; Can't use __NAMESPACE__ in inherited class (ODText) * Namespace; Can't use __NAMESPACE__ in inherited class (ODText)

View File

@ -21,11 +21,12 @@ use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font; use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Writer\Word2007\Part\AbstractPart as Word2007AbstractPart;
/** /**
* ODText writer part abstract * ODText writer part abstract
*/ */
abstract class AbstractPart extends \PhpOffice\PhpWord\Writer\Word2007\Part\AbstractPart abstract class AbstractPart extends Word2007AbstractPart
{ {
/** /**
* Write common root attributes * Write common root attributes

View File

@ -17,11 +17,13 @@
namespace PhpOffice\PhpWord\Writer\ODText\Style; namespace PhpOffice\PhpWord\Writer\ODText\Style;
use PhpOffice\PhpWord\Writer\Word2007\Style\AbstractStyle as Word2007AbstractStyle;
/** /**
* Style writer * Style writer
* *
* @since 0.10.0 * @since 0.10.0
*/ */
abstract class AbstractStyle extends \PhpOffice\PhpWord\Writer\Word2007\Style\AbstractStyle abstract class AbstractStyle extends Word2007AbstractStyle
{ {
} }

View File

@ -19,11 +19,12 @@ namespace PhpOffice\PhpWord\Writer\PDF;
use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Writer\HTML;
/** /**
* Abstract PDF renderer * Abstract PDF renderer
*/ */
abstract class AbstractRenderer extends \PhpOffice\PhpWord\Writer\HTML abstract class AbstractRenderer extends HTML
{ {
/** /**
* Temporary storage directory * Temporary storage directory
@ -112,12 +113,12 @@ abstract class AbstractRenderer extends \PhpOffice\PhpWord\Writer\HTML
/** /**
* Set Paper Size * Set Paper Size
* *
* @param int $pValue Paper size = PAPERSIZE_A4 * @param int $value Paper size = PAPERSIZE_A4
* @return self * @return self
*/ */
public function setPaperSize($pValue = 9) public function setPaperSize($value = 9)
{ {
$this->paperSize = $pValue; $this->paperSize = $value;
return $this; return $this;
} }
@ -134,27 +135,27 @@ abstract class AbstractRenderer extends \PhpOffice\PhpWord\Writer\HTML
/** /**
* Set Orientation * Set Orientation
* *
* @param string $pValue Page orientation ORIENTATION_DEFAULT * @param string $value Page orientation ORIENTATION_DEFAULT
* @return self * @return self
*/ */
public function setOrientation($pValue = 'default') public function setOrientation($value = 'default')
{ {
$this->orientation = $pValue; $this->orientation = $value;
return $this; return $this;
} }
/** /**
* Save PhpWord to PDF file, pre-save * Save PhpWord to PDF file, pre-save
* *
* @param string $pFilename Name of the file to save as * @param string $filename Name of the file to save as
* @return resource * @return resource
* @throws \PhpOffice\PhpWord\Exception\Exception * @throws \PhpOffice\PhpWord\Exception\Exception
*/ */
protected function prepareForSave($pFilename = null) protected function prepareForSave($filename = null)
{ {
$fileHandle = fopen($pFilename, 'w'); $fileHandle = fopen($filename, 'w');
if ($fileHandle === false) { if ($fileHandle === false) {
throw new Exception("Could not open file $pFilename for writing."); throw new Exception("Could not open file $filename for writing.");
} }
$this->isPdf = true; $this->isPdf = true;

View File

@ -20,11 +20,12 @@ namespace PhpOffice\PhpWord\Writer\PDF;
use PhpOffice\PhpWord\Exception\Exception; use PhpOffice\PhpWord\Exception\Exception;
use PhpOffice\PhpWord\PhpWord; use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Settings; use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Writer\WriterInterface;
/** /**
* DomPDF writer * DomPDF writer
*/ */
class DomPDF extends AbstractRenderer implements \PhpOffice\PhpWord\Writer\WriterInterface class DomPDF extends AbstractRenderer implements WriterInterface
{ {
/** /**
* Create new instance * Create new instance
@ -46,12 +47,12 @@ class DomPDF extends AbstractRenderer implements \PhpOffice\PhpWord\Writer\Write
/** /**
* Save PhpWord to file * Save PhpWord to file
* *
* @param string $pFilename Name of the file to save as * @param string $filename Name of the file to save as
* @throws Exception * @throws Exception
*/ */
public function save($pFilename = null) public function save($filename = null)
{ {
$fileHandle = parent::prepareForSave($pFilename); $fileHandle = parent::prepareForSave($filename);
// Default PDF paper size // Default PDF paper size
$paperSize = 'A4'; $paperSize = 'A4';

View File

@ -58,7 +58,6 @@ class RTF extends AbstractWriter implements WriterInterface
*/ */
public function __construct(PhpWord $phpWord = null) public function __construct(PhpWord $phpWord = null)
{ {
// Assign PhpWord
$this->setPhpWord($phpWord); $this->setPhpWord($phpWord);
} }
@ -70,10 +69,6 @@ class RTF extends AbstractWriter implements WriterInterface
*/ */
public function save($filename = null) public function save($filename = null)
{ {
if (is_null($this->phpWord)) {
throw new Exception('PhpWord object unassigned.');
}
$filename = $this->getTempFile($filename); $filename = $this->getTempFile($filename);
$hFile = fopen($filename, 'w'); $hFile = fopen($filename, 'w');
if ($hFile !== false) { if ($hFile !== false) {
@ -194,12 +189,9 @@ class RTF extends AbstractWriter implements WriterInterface
*/ */
private function populateFontTable() private function populateFontTable()
{ {
$phpWord = $this->phpWord; $phpWord = $this->getPhpWord();
$fontTable = array();
$arrFonts = array(); $fontTable[] = PhpWord::DEFAULT_FONT_NAME;
// Default font : PhpWord::DEFAULT_FONT_NAME
$arrFonts[] = PhpWord::DEFAULT_FONT_NAME;
// PhpWord object : $this->phpWord
// Browse styles // Browse styles
$styles = Style::getStyles(); $styles = Style::getStyles();
@ -207,8 +199,8 @@ class RTF extends AbstractWriter implements WriterInterface
foreach ($styles as $style) { foreach ($styles as $style) {
// Font // Font
if ($style instanceof Font) { if ($style instanceof Font) {
if (in_array($style->getName(), $arrFonts) == false) { if (in_array($style->getName(), $fontTable) == false) {
$arrFonts[] = $style->getName(); $fontTable[] = $style->getName();
} }
} }
} }
@ -218,19 +210,14 @@ class RTF extends AbstractWriter implements WriterInterface
$sections = $phpWord->getSections(); $sections = $phpWord->getSections();
$countSections = count($sections); $countSections = count($sections);
if ($countSections > 0) { if ($countSections > 0) {
$pSection = 0;
foreach ($sections as $section) { foreach ($sections as $section) {
$pSection++;
$elements = $section->getElements(); $elements = $section->getElements();
foreach ($elements as $element) { foreach ($elements as $element) {
if (method_exists($element, 'getFontStyle')) { if (method_exists($element, 'getFontStyle')) {
$fontStyle = $element->getFontStyle(); $fontStyle = $element->getFontStyle();
if ($fontStyle instanceof Font) { if ($fontStyle instanceof Font) {
if (in_array($fontStyle->getName(), $arrFonts) == false) { if (in_array($fontStyle->getName(), $fontTable) == false) {
$arrFonts[] = $fontStyle->getName(); $fontTable[] = $fontStyle->getName();
} }
} }
} }
@ -238,7 +225,7 @@ class RTF extends AbstractWriter implements WriterInterface
} }
} }
return $arrFonts; return $fontTable;
} }
/** /**
@ -248,11 +235,9 @@ class RTF extends AbstractWriter implements WriterInterface
*/ */
private function populateColorTable() private function populateColorTable()
{ {
$phpWord = $this->phpWord; $phpWord = $this->getPhpWord();
$defaultFontColor = PhpWord::DEFAULT_FONT_COLOR; $defaultFontColor = PhpWord::DEFAULT_FONT_COLOR;
$colorTable = array();
$arrColors = array();
// PhpWord object : $this->phpWord
// Browse styles // Browse styles
$styles = Style::getStyles(); $styles = Style::getStyles();
@ -262,11 +247,11 @@ class RTF extends AbstractWriter implements WriterInterface
if ($style instanceof Font) { if ($style instanceof Font) {
$color = $style->getColor(); $color = $style->getColor();
$fgcolor = $style->getFgColor(); $fgcolor = $style->getFgColor();
if (!in_array($color, $arrColors) && $color != $defaultFontColor && !empty($color)) { if (!in_array($color, $colorTable) && $color != $defaultFontColor && !empty($color)) {
$arrColors[] = $color; $colorTable[] = $color;
} }
if (!in_array($fgcolor, $arrColors) && $fgcolor != $defaultFontColor && !empty($fgcolor)) { if (!in_array($fgcolor, $colorTable) && $fgcolor != $defaultFontColor && !empty($fgcolor)) {
$arrColors[] = $fgcolor; $colorTable[] = $fgcolor;
} }
} }
} }
@ -276,22 +261,17 @@ class RTF extends AbstractWriter implements WriterInterface
$sections = $phpWord->getSections(); $sections = $phpWord->getSections();
$countSections = count($sections); $countSections = count($sections);
if ($countSections > 0) { if ($countSections > 0) {
$pSection = 0;
foreach ($sections as $section) { foreach ($sections as $section) {
$pSection++;
$elements = $section->getElements(); $elements = $section->getElements();
foreach ($elements as $element) { foreach ($elements as $element) {
if (method_exists($element, 'getFontStyle')) { if (method_exists($element, 'getFontStyle')) {
$fontStyle = $element->getFontStyle(); $fontStyle = $element->getFontStyle();
if ($fontStyle instanceof Font) { if ($fontStyle instanceof Font) {
if (in_array($fontStyle->getColor(), $arrColors) == false) { if (in_array($fontStyle->getColor(), $colorTable) == false) {
$arrColors[] = $fontStyle->getColor(); $colorTable[] = $fontStyle->getColor();
} }
if (in_array($fontStyle->getFgColor(), $arrColors) == false) { if (in_array($fontStyle->getFgColor(), $colorTable) == false) {
$arrColors[] = $fontStyle->getFgColor(); $colorTable[] = $fontStyle->getFgColor();
} }
} }
} }
@ -299,6 +279,6 @@ class RTF extends AbstractWriter implements WriterInterface
} }
} }
return $arrColors; return $colorTable;
} }
} }

View File

@ -23,13 +23,14 @@ use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle; use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle;
use PhpOffice\PhpWord\Writer\RTF\Style\Font as FontStyleWriter; use PhpOffice\PhpWord\Writer\RTF\Style\Font as FontStyleWriter;
use PhpOffice\PhpWord\Writer\RTF\Style\Paragraph as ParagraphStyleWriter; use PhpOffice\PhpWord\Writer\RTF\Style\Paragraph as ParagraphStyleWriter;
use PhpOffice\PhpWord\Writer\HTML\Element\AbstractElement as HTMLAbstractElement;
/** /**
* Abstract RTF element writer * Abstract RTF element writer
* *
* @since 0.11.0 * @since 0.11.0
*/ */
class AbstractElement extends \PhpOffice\PhpWord\Writer\HTML\Element\AbstractElement class AbstractElement extends HTMLAbstractElement
{ {
/** /**
* Font style * Font style

View File

@ -17,12 +17,14 @@
namespace PhpOffice\PhpWord\Writer\RTF\Element; namespace PhpOffice\PhpWord\Writer\RTF\Element;
use PhpOffice\PhpWord\Writer\HTML\Element\Container as HTMLContainer;
/** /**
* Container element RTF writer * Container element RTF writer
* *
* @since 0.11.0 * @since 0.11.0
*/ */
class Container extends \PhpOffice\PhpWord\Writer\HTML\Element\Container class Container extends HTMLContainer
{ {
/** /**
* Namespace; Can't use __NAMESPACE__ in inherited class (RTF) * Namespace; Can't use __NAMESPACE__ in inherited class (RTF)

View File

@ -17,11 +17,13 @@
namespace PhpOffice\PhpWord\Writer\RTF\Style; namespace PhpOffice\PhpWord\Writer\RTF\Style;
use PhpOffice\PhpWord\Writer\HTML\Style\AbstractStyle as HTMLAbstractStyle;
/** /**
* Abstract RTF style writer * Abstract RTF style writer
* *
* @since 0.11.0 * @since 0.11.0
*/ */
abstract class AbstractStyle extends \PhpOffice\PhpWord\Writer\HTML\Style\AbstractStyle abstract class AbstractStyle extends HTMLAbstractStyle
{ {
} }

View File

@ -44,7 +44,7 @@ class Font extends AbstractStyle
public function write() public function write()
{ {
$style = $this->getStyle(); $style = $this->getStyle();
if (!$style instanceof \PhpOffice\PhpWord\Style\Font) { if (!$style instanceof FontStyle) {
return ''; return '';
} }

View File

@ -92,10 +92,7 @@ class Word2007 extends AbstractWriter implements WriterInterface
*/ */
public function save($filename = null) public function save($filename = null)
{ {
if (is_null($this->phpWord)) { $phpWord = $this->getPhpWord();
throw new Exception('PhpWord object unassigned.');
}
$filename = $this->getTempFile($filename); $filename = $this->getTempFile($filename);
$objZip = $this->getZipArchive($filename); $objZip = $this->getZipArchive($filename);
@ -121,7 +118,7 @@ class Word2007 extends AbstractWriter implements WriterInterface
// Add header/footer contents // Add header/footer contents
$rId = Media::countElements('section') + 6; // @see Rels::writeDocRels for 6 first elements $rId = Media::countElements('section') + 6; // @see Rels::writeDocRels for 6 first elements
$sections = $this->phpWord->getSections(); $sections = $phpWord->getSections();
foreach ($sections as $section) { foreach ($sections as $section) {
$this->addHeaderFooterContent($section, $objZip, 'header', $rId); $this->addHeaderFooterContent($section, $objZip, 'header', $rId);
$this->addHeaderFooterContent($section, $objZip, 'footer', $rId); $this->addHeaderFooterContent($section, $objZip, 'footer', $rId);
@ -223,10 +220,11 @@ class Word2007 extends AbstractWriter implements WriterInterface
*/ */
private function addNotes($objZip, &$rId, $noteType = 'footnote') private function addNotes($objZip, &$rId, $noteType = 'footnote')
{ {
$phpWord = $this->getPhpWord();
$noteType = ($noteType == 'endnote') ? 'endnote' : 'footnote'; $noteType = ($noteType == 'endnote') ? 'endnote' : 'footnote';
$partName = "{$noteType}s"; $partName = "{$noteType}s";
$method = 'get' . $partName; $method = 'get' . $partName;
$collection = $this->phpWord->$method(); $collection = $phpWord->$method();
// Add footnotes media files, relations, and contents // Add footnotes media files, relations, and contents
if ($collection->countItems() > 0) { if ($collection->countItems() > 0) {

View File

@ -18,6 +18,7 @@
namespace PhpOffice\PhpWord\Writer\Word2007\Element; namespace PhpOffice\PhpWord\Writer\Word2007\Element;
use PhpOffice\PhpWord\Element\TextBreak as TextBreakElement; use PhpOffice\PhpWord\Element\TextBreak as TextBreakElement;
use PhpOffice\PhpWord\Element\AbstractContainer as ContainerElement;
/** /**
* Container element writer (section, textrun, header, footnote, cell, etc.) * Container element writer (section, textrun, header, footnote, cell, etc.)
@ -39,7 +40,7 @@ class Container extends AbstractElement
public function write() public function write()
{ {
$container = $this->getElement(); $container = $this->getElement();
if (!$container instanceof \PhpOffice\PhpWord\Element\AbstractContainer) { if (!$container instanceof ContainerElement) {
return; return;
} }
$containerClass = substr(get_class($container), strrpos(get_class($container), '\\') + 1); $containerClass = substr(get_class($container), strrpos(get_class($container), '\\') + 1);

View File

@ -35,7 +35,7 @@ class Image extends AbstractElement
{ {
$xmlWriter = $this->getXmlWriter(); $xmlWriter = $this->getXmlWriter();
$element = $this->getElement(); $element = $this->getElement();
if (!$element instanceof \PhpOffice\PhpWord\Element\Image) { if (!$element instanceof ImageElement) {
return; return;
} }

View File

@ -38,7 +38,7 @@ class TOC extends AbstractElement
{ {
$xmlWriter = $this->getXmlWriter(); $xmlWriter = $this->getXmlWriter();
$element = $this->getElement(); $element = $this->getElement();
if (!$element instanceof \PhpOffice\PhpWord\Element\TOC) { if (!$element instanceof TOCElement) {
return; return;
} }

View File

@ -41,7 +41,7 @@ class Table extends AbstractElement
{ {
$xmlWriter = $this->getXmlWriter(); $xmlWriter = $this->getXmlWriter();
$element = $this->getElement(); $element = $this->getElement();
if (!$element instanceof \PhpOffice\PhpWord\Element\Table) { if (!$element instanceof TableElement) {
return; return;
} }

View File

@ -37,7 +37,7 @@ class Cell extends AbstractStyle
public function write() public function write()
{ {
$style = $this->getStyle(); $style = $this->getStyle();
if (!$style instanceof \PhpOffice\PhpWord\Style\Cell) { if (!$style instanceof CellStyle) {
return; return;
} }
$xmlWriter = $this->getXmlWriter(); $xmlWriter = $this->getXmlWriter();

View File

@ -40,7 +40,7 @@ class Image extends AbstractStyle
public function write() public function write()
{ {
$style = $this->getStyle(); $style = $this->getStyle();
if (!$style instanceof \PhpOffice\PhpWord\Style\Image) { if (!$style instanceof ImageStyle) {
return; return;
} }
$this->writeStyle($style); $this->writeStyle($style);
@ -107,7 +107,7 @@ class Image extends AbstractStyle
public function writeAlignment() public function writeAlignment()
{ {
$style = $this->getStyle(); $style = $this->getStyle();
if (!$style instanceof \PhpOffice\PhpWord\Style\Image) { if (!$style instanceof ImageStyle) {
return; return;
} }

View File

@ -32,7 +32,7 @@ class Section extends AbstractStyle
public function write() public function write()
{ {
$style = $this->getStyle(); $style = $this->getStyle();
if (!$style instanceof \PhpOffice\PhpWord\Style\Section) { if (!$style instanceof SectionStyle) {
return; return;
} }
$xmlWriter = $this->getXmlWriter(); $xmlWriter = $this->getXmlWriter();

View File

@ -41,7 +41,7 @@ class Table extends AbstractStyle
$style = $this->getStyle(); $style = $this->getStyle();
$xmlWriter = $this->getXmlWriter(); $xmlWriter = $this->getXmlWriter();
if ($style instanceof \PhpOffice\PhpWord\Style\Table) { if ($style instanceof TableStyle) {
$this->writeStyle($xmlWriter, $style); $this->writeStyle($xmlWriter, $style);
} elseif (is_string($style)) { } elseif (is_string($style)) {
$xmlWriter->startElement('w:tblPr'); $xmlWriter->startElement('w:tblPr');
@ -77,7 +77,7 @@ class Table extends AbstractStyle
// First row style // First row style
$firstRow = $style->getFirstRow(); $firstRow = $style->getFirstRow();
if ($firstRow instanceof \PhpOffice\PhpWord\Style\Table) { if ($firstRow instanceof TableStyle) {
$this->writeFirstRow($xmlWriter, $firstRow); $this->writeFirstRow($xmlWriter, $firstRow);
} }
} }

View File

@ -32,7 +32,7 @@ class TextBox extends Image
public function write() public function write()
{ {
$style = $this->getStyle(); $style = $this->getStyle();
if (!$style instanceof \PhpOffice\PhpWord\Style\TextBox) { if (!$style instanceof TextBoxStyle) {
return; return;
} }
$this->writeStyle($style); $this->writeStyle($style);
@ -50,7 +50,7 @@ class TextBox extends Image
return; return;
} }
$style = $this->getStyle(); $style = $this->getStyle();
if (!$style instanceof \PhpOffice\PhpWord\Style\TextBox) { if (!$style instanceof TextBoxStyle) {
return; return;
} }
@ -91,7 +91,7 @@ class TextBox extends Image
public function writeInnerMargin() public function writeInnerMargin()
{ {
$style = $this->getStyle(); $style = $this->getStyle();
if (!$style instanceof \PhpOffice\PhpWord\Style\TextBox || !$style->hasInnerMargins()) { if (!$style instanceof TextBoxStyle || !$style->hasInnerMargins()) {
return; return;
} }

View File

@ -25,7 +25,7 @@ interface WriterInterface
/** /**
* Save PhpWord to file * Save PhpWord to file
* *
* @param string $pFilename * @param string $filename
*/ */
public function save($pFilename = null); public function save($filename = null);
} }

View File

@ -109,18 +109,6 @@ class ODTextTest extends \PHPUnit_Framework_TestCase
$writer->save('php://output'); $writer->save('php://output');
} }
/**
* Save with no PhpWord object assigned
*
* @expectedException \PhpOffice\PhpWord\Exception\Exception
* @expectedExceptionMessage PhpWord object unassigned.
*/
public function testSaveException()
{
$writer = new ODText();
$writer->save();
}
/** /**
* Get writer part return null value * Get writer part return null value
*/ */

View File

@ -98,16 +98,4 @@ class RTFTest extends \PHPUnit_Framework_TestCase
$writer = new RTF($phpWord); $writer = new RTF($phpWord);
$writer->save('php://output'); $writer->save('php://output');
} }
/**
* Save with no PhpWord object assigned
*
* @expectedException \PhpOffice\PhpWord\Exception\Exception
* @expectedExceptionMessage PhpWord object unassigned.
*/
public function testSaveException()
{
$writer = new RTF();
$writer->save();
}
} }

View File

@ -122,18 +122,6 @@ class Word2007Test extends \PHPUnit_Framework_TestCase
unlink($file); unlink($file);
} }
/**
* Save with no PhpWord object assigned
*
* @expectedException \PhpOffice\PhpWord\Exception\Exception
* @expectedExceptionMessage PhpWord object unassigned.
*/
public function testSaveException()
{
$writer = new Word2007();
$writer->save();
}
/** /**
* Check content types * Check content types
*/ */