Additional type checks in style writers

This commit is contained in:
Ivan Lanin 2014-05-11 18:57:58 +07:00
parent 7d5c62ab34
commit c243a11e57
6 changed files with 18 additions and 19 deletions

View File

@ -17,7 +17,6 @@
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Shared\String;
use PhpOffice\PhpWord\Style\ListItem as ListItemStyle;
use PhpOffice\PhpWord\Style\Paragraph;

View File

@ -153,14 +153,14 @@ class XMLWriter
/**
* Write element if ...
*
* @param bool $condition
* @param bool|null $condition
* @param string $element
* @param string $attribute
* @param string $value
*/
public function writeElementIf($condition, $element, $attribute = null, $value = null)
{
if ($condition) {
if ($condition == true) {
if (is_null($attribute)) {
$this->xmlWriter->writeElement($element, $value);
} else {
@ -174,13 +174,13 @@ class XMLWriter
/**
* Write attribute if ...
*
* @param bool $condition
* @param bool|null $condition
* @param string $attribute
* @param string $value
*/
public function writeAttributeIf($condition, $attribute, $value)
{
if ($condition) {
if ($condition == true) {
$this->xmlWriter->writeAttribute($attribute, $value);
}
}

View File

@ -651,7 +651,7 @@ class Font extends AbstractStyle
/**
* Toggle $target property to false when $source true
*
* @param bool $target Target property
* @param bool|null $target Target property
* @param bool $sourceValue
*/
private function toggleFalse(&$target, $sourceValue)

View File

@ -87,12 +87,12 @@ abstract class AbstractStyle
/**
* Get value if ...
*
* @param bool $condition
* @param bool|null $condition
* @param string $value
* @return string
*/
protected function getValueIf($condition, $value)
{
return $condition ? $value : '';
return $condition == true ? $value : '';
}
}

View File

@ -42,7 +42,7 @@ class Image extends AbstractStyle
if (!$style instanceof \PhpOffice\PhpWord\Style\Image) {
return;
}
$this->writeStyle();
$this->writeStyle($style);
}
/**
@ -65,10 +65,9 @@ class Image extends AbstractStyle
/**
* Write style attribute
*/
protected function writeStyle()
protected function writeStyle(ImageStyle $style)
{
$xmlWriter = $this->getXmlWriter();
$style = $this->getStyle();
// Default style array
$styleArray = array(
@ -77,7 +76,7 @@ class Image extends AbstractStyle
'mso-width-relative' => 'margin',
'mso-height-relative' => 'margin',
);
$styleArray = array_merge($styleArray, $this->getElementStyle());
$styleArray = array_merge($styleArray, $this->getElementStyle($style));
// Absolute/relative positioning
$positioning = $style->getPositioning();
@ -123,9 +122,8 @@ class Image extends AbstractStyle
*
* @return array
*/
private function getElementStyle()
private function getElementStyle(ImageStyle $style)
{
$style = $this->getStyle();
$styles = array();
$styleValues = array(
'width' => $style->getWidth(),

View File

@ -35,8 +35,8 @@ class TextBox extends Image
if (!$style instanceof \PhpOffice\PhpWord\Style\TextBox) {
return;
}
$this->writeStyle();
$this->writeBorder();
$this->writeStyle($style);
$this->writeBorder($style);
}
/**
@ -50,6 +50,9 @@ class TextBox extends Image
return;
}
$style = $this->getStyle();
if (!$style instanceof \PhpOffice\PhpWord\Style\TextBox) {
return;
}
$relativePositions = array(
TextBoxStyle::POSITION_RELATIVE_TO_MARGIN => 'margin',
@ -88,7 +91,7 @@ class TextBox extends Image
public function writeInnerMargin()
{
$style = $this->getStyle();
if (!$style->hasInnerMargins()) {
if (!$style instanceof \PhpOffice\PhpWord\Style\TextBox || !$style->hasInnerMargins()) {
return;
}
@ -100,10 +103,9 @@ class TextBox extends Image
/**
* Writer border
*/
private function writeBorder()
private function writeBorder(TextBoxStyle $style)
{
$xmlWriter = $this->getXmlWriter();
$style = $this->getStyle();
// Border size
$borderSize = $style->getBorderSize();