Replaced `array_key_exists` with `isset` for better performance.

This commit is contained in:
Roman Syroeshko 2014-10-10 21:10:29 +04:00
parent 9d73173dce
commit 4445fd3258
22 changed files with 64 additions and 66 deletions

View File

@ -92,7 +92,7 @@ abstract class AbstractContainer extends AbstractElement
// Run valid `add` command // Run valid `add` command
$function = strtolower($function); $function = strtolower($function);
if (array_key_exists($function, $functions)) { if (isset($functions[$function])) {
$element = $functions[$function]; $element = $functions[$function];
// Special case for TextBreak // Special case for TextBreak
@ -183,23 +183,22 @@ abstract class AbstractContainer extends AbstractElement
*/ */
private function checkValidity($method) private function checkValidity($method)
{ {
// Valid containers for each element $generalContainers = array(
$allContainers = array( 'Section', 'Header', 'Footer', 'Footnote', 'Endnote', 'Cell', 'TextRun', 'TextBox', 'ListItemRun',
'Section', 'Header', 'Footer', 'Footnote', 'Endnote',
'Cell', 'TextRun', 'TextBox', 'ListItemRun',
); );
$validContainers = array( $validContainers = array(
'Text' => $allContainers, 'Text' => $generalContainers,
'Bookmark' => $allContainers, 'Bookmark' => $generalContainers,
'Link' => $allContainers, 'Link' => $generalContainers,
'TextBreak' => $allContainers, 'TextBreak' => $generalContainers,
'Image' => $allContainers, 'Image' => $generalContainers,
'Object' => $allContainers, 'Object' => $generalContainers,
'Field' => $allContainers, 'Field' => $generalContainers,
'Line' => $allContainers, 'Line' => $generalContainers,
'Shape' => $allContainers, 'Shape' => $generalContainers,
'FormField' => $allContainers, 'FormField' => $generalContainers,
'SDT' => $allContainers, 'SDT' => $generalContainers,
'TextRun' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'), 'TextRun' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),
'ListItem' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'), 'ListItem' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),
'ListItemRun' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'), 'ListItemRun' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),
@ -214,6 +213,7 @@ abstract class AbstractContainer extends AbstractElement
'PageBreak' => array('Section'), 'PageBreak' => array('Section'),
'Chart' => array('Section'), 'Chart' => array('Section'),
); );
// Special condition, e.g. preservetext can only exists in cell when // Special condition, e.g. preservetext can only exists in cell when
// the cell is located in header or footer // the cell is located in header or footer
$validSubcontainers = array( $validSubcontainers = array(
@ -223,19 +223,20 @@ abstract class AbstractContainer extends AbstractElement
); );
// Check if a method is valid for current container // Check if a method is valid for current container
if (array_key_exists($method, $validContainers)) { if (isset($validContainers[$method])) {
if (!in_array($this->container, $validContainers[$method])) { if (!in_array($this->container, $validContainers[$method])) {
throw new \BadMethodCallException("Cannot add $method in $this->container."); throw new \BadMethodCallException("Cannot add {$method} in {$this->container}.");
} }
} }
// Check if a method is valid for current container, located in other container // Check if a method is valid for current container, located in other container
if (array_key_exists($method, $validSubcontainers)) { if (isset($validSubcontainers[$method])) {
$rules = $validSubcontainers[$method]; $rules = $validSubcontainers[$method];
$containers = $rules[0]; $containers = $rules[0];
$allowedDocParts = $rules[1]; $allowedDocParts = $rules[1];
foreach ($containers as $container) { foreach ($containers as $container) {
if ($this->container == $container && !in_array($this->getDocPart(), $allowedDocParts)) { if ($this->container == $container && !in_array($this->getDocPart(), $allowedDocParts)) {
throw new \BadMethodCallException("Cannot add $method in $this->container."); throw new \BadMethodCallException("Cannot add {$method} in {$this->container}.");
} }
} }
} }

View File

@ -100,7 +100,7 @@ class Field extends AbstractElement
public function setType($type = null) public function setType($type = null)
{ {
if (isset($type)) { if (isset($type)) {
if (array_key_exists($type, $this->fieldsArray)) { if (isset($this->fieldsArray[$type])) {
$this->type = $type; $this->type = $type;
} else { } else {
throw new \InvalidArgumentException("Invalid type"); throw new \InvalidArgumentException("Invalid type");
@ -130,7 +130,7 @@ class Field extends AbstractElement
{ {
if (is_array($properties)) { if (is_array($properties)) {
foreach (array_keys($properties) as $propkey) { foreach (array_keys($properties) as $propkey) {
if (!(array_key_exists($propkey, $this->fieldsArray[$this->type]['properties']))) { if (!(isset($this->fieldsArray[$this->type]['properties'][$propkey]))) {
throw new \InvalidArgumentException("Invalid property"); throw new \InvalidArgumentException("Invalid property");
} }
} }
@ -160,7 +160,7 @@ class Field extends AbstractElement
{ {
if (is_array($options)) { if (is_array($options)) {
foreach (array_keys($options) as $optionkey) { foreach (array_keys($options) as $optionkey) {
if (!(array_key_exists($optionkey, $this->fieldsArray[$this->type]['options']))) { if (!(isset($this->fieldsArray[$this->type]['options'][$optionkey]))) {
throw new \InvalidArgumentException("Invalid option"); throw new \InvalidArgumentException("Invalid option");
} }
} }

View File

@ -61,11 +61,10 @@ class Title extends AbstractElement
*/ */
public function __construct($text, $depth = 1) public function __construct($text, $depth = 1)
{ {
$this->text = String::toUTF8($text); $this->text = String::toUTF8($text);
$this->depth = $depth; $this->depth = $depth;
if (array_key_exists('Heading_' . $this->depth, Style::getStyles())) { if (array_key_exists("Heading_{$this->depth}", Style::getStyles())) {
$this->style = 'Heading' . $this->depth; $this->style = "Heading{$this->depth}";
} }
return $this; return $this;

View File

@ -48,12 +48,12 @@ class Media
{ {
// Assign unique media Id and initiate media container if none exists // Assign unique media Id and initiate media container if none exists
$mediaId = md5($container . $source); $mediaId = md5($container . $source);
if (!array_key_exists($container, self::$elements)) { if (!isset(self::$elements[$container])) {
self::$elements[$container] = array(); self::$elements[$container] = array();
} }
// Add media if not exists or point to existing media // Add media if not exists or point to existing media
if (!array_key_exists($mediaId, self::$elements[$container])) { if (!isset(self::$elements[$container][$mediaId])) {
$mediaCount = self::countElements($container); $mediaCount = self::countElements($container);
$mediaTypeCount = self::countElements($container, $mediaType); $mediaTypeCount = self::countElements($container, $mediaType);
$mediaTypeCount++; $mediaTypeCount++;
@ -120,7 +120,7 @@ class Media
{ {
$mediaCount = 0; $mediaCount = 0;
if (array_key_exists($container, self::$elements)) { if (isset(self::$elements[$container])) {
foreach (self::$elements[$container] as $mediaData) { foreach (self::$elements[$container] as $mediaData) {
if (!is_null($mediaType)) { if (!is_null($mediaType)) {
if ($mediaType == $mediaData['type']) { if ($mediaType == $mediaData['type']) {
@ -156,7 +156,7 @@ class Media
} }
return $elements; return $elements;
} else { } else {
if (!array_key_exists($container, self::$elements)) { if (!isset(self::$elements[$container])) {
return $elements; return $elements;
} }
return self::getElementsByType($container, $type); return self::getElementsByType($container, $type);

View File

@ -139,7 +139,7 @@ class PhpWord
/** @var \PhpOffice\PhpWord\Collection\AbstractCollection $collectionObject */ /** @var \PhpOffice\PhpWord\Collection\AbstractCollection $collectionObject */
$collectionObject = $this->collections[$key]; $collectionObject = $this->collections[$key];
return $collectionObject->addItem(array_key_exists(0, $args) ? $args[0] : null); return $collectionObject->addItem(isset($args[0]) ? $args[0] : null);
} }
// Run add style method // Run add style method

View File

@ -155,7 +155,7 @@ class Document
$char = $this->rtf[$this->offset]; $char = $this->rtf[$this->offset];
$ascii = ord($char); $ascii = ord($char);
if (array_key_exists($ascii, $markers)) { // Marker found: {, }, \, LF, or CR if (isset($markers[$ascii])) { // Marker found: {, }, \, LF, or CR
$markerFunction = $markers[$ascii]; $markerFunction = $markers[$ascii];
$this->$markerFunction(); $this->$markerFunction();
} else { } else {
@ -351,7 +351,7 @@ class Document
'fldinst' => array(self::SKIP, 'link', null), 'fldinst' => array(self::SKIP, 'link', null),
); );
if (array_key_exists($control, $controls)) { if (isset($controls[$control])) {
list($function) = $controls[$control]; list($function) = $controls[$control];
if (method_exists($this, $function)) { if (method_exists($this, $function)) {
$directives = $controls[$control]; $directives = $controls[$control];

View File

@ -63,7 +63,7 @@ class Word2007 extends AbstractReader implements ReaderInterface
$stepItems = $step['stepItems']; $stepItems = $step['stepItems'];
foreach ($relationships[$stepPart] as $relItem) { foreach ($relationships[$stepPart] as $relItem) {
$relType = $relItem['type']; $relType = $relItem['type'];
if (array_key_exists($relType, $stepItems)) { if (isset($stepItems[$relType])) {
$partName = $stepItems[$relType]; $partName = $stepItems[$relType];
$xmlFile = $relItem['target']; $xmlFile = $relItem['target'];
$this->readPart($phpWord, $relationships, $partName, $docFile, $xmlFile); $this->readPart($phpWord, $relationships, $partName, $docFile, $xmlFile);

View File

@ -107,7 +107,7 @@ abstract class AbstractPart
$headingMatches = array(); $headingMatches = array();
if ($xmlReader->elementExists('w:pPr', $domNode)) { if ($xmlReader->elementExists('w:pPr', $domNode)) {
$paragraphStyle = $this->readParagraphStyle($xmlReader, $domNode); $paragraphStyle = $this->readParagraphStyle($xmlReader, $domNode);
if (is_array($paragraphStyle) && array_key_exists('styleName', $paragraphStyle)) { if (is_array($paragraphStyle) && isset($paragraphStyle['styleName'])) {
preg_match('/Heading(\d)/', $paragraphStyle['styleName'], $headingMatches); preg_match('/Heading(\d)/', $paragraphStyle['styleName'], $headingMatches);
} }
} }
@ -505,10 +505,9 @@ abstract class AbstractPart
private function getMediaTarget($docPart, $rId) private function getMediaTarget($docPart, $rId)
{ {
$target = null; $target = null;
if (array_key_exists($docPart, $this->rels)) {
if (array_key_exists($rId, $this->rels[$docPart])) { if (isset($this->rels[$docPart]) && isset($this->rels[$docPart][$rId])) {
$target = $this->rels[$docPart][$rId]['target']; $target = $this->rels[$docPart][$rId]['target'];
}
} }
return $target; return $target;

View File

@ -67,12 +67,12 @@ class DocPropsCore extends AbstractPart
$nodes = $xmlReader->getElements('*'); $nodes = $xmlReader->getElements('*');
if ($nodes->length > 0) { if ($nodes->length > 0) {
foreach ($nodes as $node) { foreach ($nodes as $node) {
if (!array_key_exists($node->nodeName, $this->mapping)) { if (!isset($this->mapping[$node->nodeName])) {
continue; continue;
} }
$method = $this->mapping[$node->nodeName]; $method = $this->mapping[$node->nodeName];
$value = $node->nodeValue == '' ? null : $node->nodeValue; $value = $node->nodeValue == '' ? null : $node->nodeValue;
if (array_key_exists($node->nodeName, $this->callbacks)) { if (isset($this->callbacks[$node->nodeName])) {
$value = $this->callbacks[$node->nodeName]($value); $value = $this->callbacks[$node->nodeName]($value);
} }
if (method_exists($docProps, $method)) { if (method_exists($docProps, $method)) {

View File

@ -53,7 +53,7 @@ class Document extends AbstractPart
if ($nodes->length > 0) { if ($nodes->length > 0) {
$section = $this->phpWord->addSection(); $section = $this->phpWord->addSection();
foreach ($nodes as $node) { foreach ($nodes as $node) {
if (array_key_exists($node->nodeName, $readMethods)) { if (isset($readMethods[$node->nodeName])) {
$readMethod = $readMethods[$node->nodeName]; $readMethod = $readMethods[$node->nodeName];
$this->$readMethod($xmlReader, $node, $section); $this->$readMethod($xmlReader, $node, $section);
} }
@ -72,9 +72,9 @@ class Document extends AbstractPart
{ {
$readMethods = array('w:p' => 'readParagraph', 'w:tbl' => 'readTable'); $readMethods = array('w:p' => 'readParagraph', 'w:tbl' => 'readTable');
if (is_array($settings) && array_key_exists('hf', $settings)) { if (is_array($settings) && isset($settings['hf'])) {
foreach ($settings['hf'] as $rId => $hfSetting) { foreach ($settings['hf'] as $rId => $hfSetting) {
if (array_key_exists($rId, $this->rels['document'])) { if (isset($this->rels['document'][$rId])) {
list($hfType, $xmlFile, $docPart) = array_values($this->rels['document'][$rId]); list($hfType, $xmlFile, $docPart) = array_values($this->rels['document'][$rId]);
$addMethod = "add{$hfType}"; $addMethod = "add{$hfType}";
$hfObject = $section->$addMethod($hfSetting['type']); $hfObject = $section->$addMethod($hfSetting['type']);
@ -85,7 +85,7 @@ class Document extends AbstractPart
$nodes = $xmlReader->getElements('*'); $nodes = $xmlReader->getElements('*');
if ($nodes->length > 0) { if ($nodes->length > 0) {
foreach ($nodes as $node) { foreach ($nodes as $node) {
if (array_key_exists($node->nodeName, $readMethods)) { if (isset($readMethods[$node->nodeName])) {
$readMethod = $readMethods[$node->nodeName]; $readMethod = $readMethods[$node->nodeName];
$this->$readMethod($xmlReader, $node, $hfObject, $docPart); $this->$readMethod($xmlReader, $node, $hfObject, $docPart);
} }

View File

@ -62,7 +62,7 @@ class Footnotes extends AbstractPart
// Avoid w:type "separator" and "continuationSeparator" // Avoid w:type "separator" and "continuationSeparator"
// Only look for <footnote> or <endnote> without w:type attribute // Only look for <footnote> or <endnote> without w:type attribute
if (is_null($type) && array_key_exists($id, $collection)) { if (is_null($type) && isset($collection[$id])) {
$element = $collection[$id]; $element = $collection[$id];
$pNodes = $xmlReader->getElements('w:p/*', $node); $pNodes = $xmlReader->getElements('w:p/*', $node);
foreach ($pNodes as $pNode) { foreach ($pNodes as $pNode) {

View File

@ -133,8 +133,7 @@ class Html
$newElement = null; $newElement = null;
$keys = array('node', 'element', 'styles', 'data', 'argument1', 'argument2'); $keys = array('node', 'element', 'styles', 'data', 'argument1', 'argument2');
if (array_key_exists($node->nodeName, $nodes)) { if (isset($nodes[$node->nodeName])) {
// Execute method based on node mapping table and return $newElement or null // Execute method based on node mapping table and return $newElement or null
// Arguments are passed by reference // Arguments are passed by reference
$arguments = array(); $arguments = array();

View File

@ -163,7 +163,7 @@ class Style
*/ */
public static function getStyle($styleName) public static function getStyle($styleName)
{ {
if (array_key_exists($styleName, self::$styles)) { if (isset(self::$styles[$styleName])) {
return self::$styles[$styleName]; return self::$styles[$styleName];
} else { } else {
return null; return null;
@ -182,7 +182,7 @@ class Style
*/ */
private static function setStyleValues($name, $style, $value = null) private static function setStyleValues($name, $style, $value = null)
{ {
if (!array_key_exists($name, self::$styles)) { if (!isset(self::$styles[$name])) {
if ($value !== null) { if ($value !== null) {
if (is_array($value)) { if (is_array($value)) {
$style->setStyleByArray($value); $style->setStyleByArray($value);

View File

@ -343,7 +343,7 @@ abstract class AbstractWriter implements WriterInterface
$type = $element['type']; // image|object|link $type = $element['type']; // image|object|link
// Skip nonregistered types and set target // Skip nonregistered types and set target
if (!array_key_exists($type, $this->mediaPaths)) { if (!isset($this->mediaPaths[$type])) {
continue; continue;
} }
$target = $this->mediaPaths[$type] . $element['target']; $target = $this->mediaPaths[$type] . $element['target'];

View File

@ -72,7 +72,7 @@ class Body extends AbstractPart
$method = 'get' . ($noteType == 'endnote' ? 'Endnotes' : 'Footnotes'); $method = 'get' . ($noteType == 'endnote' ? 'Endnotes' : 'Footnotes');
$collection = $phpWord->$method()->getItems(); $collection = $phpWord->$method()->getItems();
if (array_key_exists($noteTypeId, $collection)) { if (isset($collection[$noteTypeId])) {
$element = $collection[$noteTypeId]; $element = $collection[$noteTypeId];
$noteAnchor = "<a name=\"note-{$noteId}\" />"; $noteAnchor = "<a name=\"note-{$noteId}\" />";
$noteAnchor .= "<a href=\"#{$noteMark}\" class=\"NoteRef\"><sup>{$noteId}</sup></a>"; $noteAnchor .= "<a href=\"#{$noteMark}\" class=\"NoteRef\"><sup>{$noteId}</sup></a>";

View File

@ -64,7 +64,7 @@ class Document extends AbstractPart
$content .= '{'; $content .= '{';
$content .= '\info'; $content .= '\info';
foreach ($properties as $property) { foreach ($properties as $property) {
$method = 'get' . (array_key_exists($property, $mapping) ? $mapping[$property] : $property); $method = 'get' . (isset($mapping[$property]) ? $mapping[$property] : $property);
$value = $docProps->$method(); $value = $docProps->$method();
$value = in_array($property, $dateFields) ? $this->getDateValue($value) : $value; $value = in_array($property, $dateFields) ? $this->getDateValue($value) : $value;
$content .= "{\\{$property} {$value}}"; $content .= "{\\{$property} {$value}}";

View File

@ -302,11 +302,11 @@ class Word2007 extends AbstractWriter implements WriterInterface
$mediumType = $medium['type']; $mediumType = $medium['type'];
if ($mediumType == 'image') { if ($mediumType == 'image') {
$extension = $medium['imageExtension']; $extension = $medium['imageExtension'];
if (!array_key_exists($extension, $this->contentTypes['default'])) { if (!isset($this->contentTypes['default'][$extension])) {
$this->contentTypes['default'][$extension] = $medium['imageType']; $this->contentTypes['default'][$extension] = $medium['imageType'];
} }
} elseif ($mediumType == 'object') { } elseif ($mediumType == 'object') {
if (!array_key_exists('bin', $this->contentTypes['default'])) { if (!isset($this->contentTypes['default']['bin'])) {
$this->contentTypes['default']['bin'] = 'application/vnd.openxmlformats-officedocument.oleObject'; $this->contentTypes['default']['bin'] = 'application/vnd.openxmlformats-officedocument.oleObject';
} }
} }

View File

@ -89,8 +89,8 @@ class Rels extends AbstractPart
$targetMapping = array('image' => 'media/', 'object' => 'embeddings/'); $targetMapping = array('image' => 'media/', 'object' => 'embeddings/');
$mediaType = $mediaRel['type']; $mediaType = $mediaRel['type'];
$type = array_key_exists($mediaType, $typeMapping) ? $typeMapping[$mediaType] : $mediaType; $type = isset($typeMapping[$mediaType]) ? $typeMapping[$mediaType] : $mediaType;
$targetPrefix = array_key_exists($mediaType, $targetMapping) ? $targetMapping[$mediaType] : ''; $targetPrefix = isset($targetMapping[$mediaType]) ? $targetMapping[$mediaType] : '';
$target = $mediaRel['target']; $target = $mediaRel['target'];
$targetMode = ($type == 'hyperlink') ? 'External' : ''; $targetMode = ($type == 'hyperlink') ? 'External' : '';

View File

@ -19,9 +19,9 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Part;
use PhpOffice\PhpWord\Settings as PhpWordSettings; use PhpOffice\PhpWord\Settings as PhpWordSettings;
use PhpOffice\PhpWord\Shared\XMLWriter; use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font as FontStyle; use PhpOffice\PhpWord\Style\Font as FontStyle;
use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle; use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Table as TableStyle; use PhpOffice\PhpWord\Style\Table as TableStyle;
use PhpOffice\PhpWord\Writer\Word2007\Style\Font as FontStyleWriter; use PhpOffice\PhpWord\Writer\Word2007\Style\Font as FontStyleWriter;
use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter; use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter;
@ -114,14 +114,14 @@ class Styles extends AbstractPart
$xmlWriter->startElement('w:name'); $xmlWriter->startElement('w:name');
$xmlWriter->writeAttribute('w:val', 'Normal'); $xmlWriter->writeAttribute('w:val', 'Normal');
$xmlWriter->endElement(); // w:name $xmlWriter->endElement(); // w:name
if (array_key_exists('Normal', $styles)) { if (isset($styles['Normal'])) {
$styleWriter = new ParagraphStyleWriter($xmlWriter, $styles['Normal']); $styleWriter = new ParagraphStyleWriter($xmlWriter, $styles['Normal']);
$styleWriter->write(); $styleWriter->write();
} }
$xmlWriter->endElement(); // w:style $xmlWriter->endElement(); // w:style
// FootnoteReference style // FootnoteReference style
if (!array_key_exists('FootnoteReference', $styles)) { if (!isset($styles['FootnoteReference'])) {
$xmlWriter->startElement('w:style'); $xmlWriter->startElement('w:style');
$xmlWriter->writeAttribute('w:type', 'character'); $xmlWriter->writeAttribute('w:type', 'character');
$xmlWriter->writeAttribute('w:styleId', 'FootnoteReference'); $xmlWriter->writeAttribute('w:styleId', 'FootnoteReference');

View File

@ -64,7 +64,7 @@ class Frame extends AbstractStyle
// zIndex for infront & behind wrap // zIndex for infront & behind wrap
$wrap = $style->getWrap(); $wrap = $style->getWrap();
if ($wrap !== null && array_key_exists($wrap, $zIndices)) { if ($wrap !== null && isset($zIndices[$wrap])) {
$styles['z-index'] = $zIndices[$wrap]; $styles['z-index'] = $zIndices[$wrap];
$wrap = null; $wrap = null;
} }
@ -124,10 +124,10 @@ class Frame extends AbstractStyle
$xmlWriter->writeAttribute('anchorx', "page"); $xmlWriter->writeAttribute('anchorx', "page");
$xmlWriter->writeAttribute('anchory', "page"); $xmlWriter->writeAttribute('anchory', "page");
} elseif ($pos == FrameStyle::POS_RELATIVE) { } elseif ($pos == FrameStyle::POS_RELATIVE) {
if (array_key_exists($hPos, $relativePositions)) { if (isset($relativePositions[$hPos])) {
$xmlWriter->writeAttribute('anchorx', $relativePositions[$hPos]); $xmlWriter->writeAttribute('anchorx', $relativePositions[$hPos]);
} }
if (array_key_exists($vPos, $relativePositions)) { if (isset($relativePositions[$vPos])) {
$xmlWriter->writeAttribute('anchory', $relativePositions[$vPos]); $xmlWriter->writeAttribute('anchory', $relativePositions[$vPos]);
} }
} }

View File

@ -58,7 +58,7 @@ class Line extends Frame
$xmlWriter->writeAttributeIf($style->getEndArrow() !== null, 'endarrow', $style->getEndArrow()); $xmlWriter->writeAttributeIf($style->getEndArrow() !== null, 'endarrow', $style->getEndArrow());
if ($dash !== null) { if ($dash !== null) {
if (array_key_exists($dash, $dashStyles)) { if (isset($dashStyles[$dash])) {
$xmlWriter->writeAttribute('dashstyle', $dashStyles[$dash]); $xmlWriter->writeAttribute('dashstyle', $dashStyles[$dash]);
} }
if ($dash == LineStyle::DASH_STYLE_ROUND_DOT) { if ($dash == LineStyle::DASH_STYLE_ROUND_DOT) {

View File

@ -83,7 +83,7 @@ class MarginBorder extends AbstractStyle
$xmlWriter->startElement('w:' . $side); $xmlWriter->startElement('w:' . $side);
if (!empty($this->colors)) { if (!empty($this->colors)) {
if ($color === null && !empty($this->attributes)) { if ($color === null && !empty($this->attributes)) {
if (array_key_exists('defaultColor', $this->attributes)) { if (isset($this->attributes['defaultColor'])) {
$color = $this->attributes['defaultColor']; $color = $this->attributes['defaultColor'];
} }
} }
@ -91,7 +91,7 @@ class MarginBorder extends AbstractStyle
$xmlWriter->writeAttribute('w:sz', $width); $xmlWriter->writeAttribute('w:sz', $width);
$xmlWriter->writeAttribute('w:color', $color); $xmlWriter->writeAttribute('w:color', $color);
if (!empty($this->attributes)) { if (!empty($this->attributes)) {
if (array_key_exists('space', $this->attributes)) { if (isset($this->attributes['space'])) {
$xmlWriter->writeAttribute('w:space', $this->attributes['space']); $xmlWriter->writeAttribute('w:space', $this->attributes['space']);
} }
} }