From 4445fd3258084f855d044f4ed8f1d92a62229dc6 Mon Sep 17 00:00:00 2001 From: Roman Syroeshko Date: Fri, 10 Oct 2014 21:10:29 +0400 Subject: [PATCH] Replaced `array_key_exists` with `isset` for better performance. --- src/PhpWord/Element/AbstractContainer.php | 41 ++++++++++--------- src/PhpWord/Element/Field.php | 6 +-- src/PhpWord/Element/Title.php | 5 +-- src/PhpWord/Media.php | 8 ++-- src/PhpWord/PhpWord.php | 2 +- src/PhpWord/Reader/RTF/Document.php | 4 +- src/PhpWord/Reader/Word2007.php | 2 +- src/PhpWord/Reader/Word2007/AbstractPart.php | 9 ++-- src/PhpWord/Reader/Word2007/DocPropsCore.php | 4 +- src/PhpWord/Reader/Word2007/Document.php | 8 ++-- src/PhpWord/Reader/Word2007/Footnotes.php | 2 +- src/PhpWord/Shared/Html.php | 3 +- src/PhpWord/Style.php | 4 +- src/PhpWord/Writer/AbstractWriter.php | 2 +- src/PhpWord/Writer/HTML/Part/Body.php | 2 +- src/PhpWord/Writer/RTF/Part/Document.php | 2 +- src/PhpWord/Writer/Word2007.php | 4 +- src/PhpWord/Writer/Word2007/Part/Rels.php | 4 +- src/PhpWord/Writer/Word2007/Part/Styles.php | 6 +-- src/PhpWord/Writer/Word2007/Style/Frame.php | 6 +-- src/PhpWord/Writer/Word2007/Style/Line.php | 2 +- .../Writer/Word2007/Style/MarginBorder.php | 4 +- 22 files changed, 64 insertions(+), 66 deletions(-) diff --git a/src/PhpWord/Element/AbstractContainer.php b/src/PhpWord/Element/AbstractContainer.php index 6a26c15f..57d646a0 100644 --- a/src/PhpWord/Element/AbstractContainer.php +++ b/src/PhpWord/Element/AbstractContainer.php @@ -92,7 +92,7 @@ abstract class AbstractContainer extends AbstractElement // Run valid `add` command $function = strtolower($function); - if (array_key_exists($function, $functions)) { + if (isset($functions[$function])) { $element = $functions[$function]; // Special case for TextBreak @@ -183,23 +183,22 @@ abstract class AbstractContainer extends AbstractElement */ private function checkValidity($method) { - // Valid containers for each element - $allContainers = array( - 'Section', 'Header', 'Footer', 'Footnote', 'Endnote', - 'Cell', 'TextRun', 'TextBox', 'ListItemRun', + $generalContainers = array( + 'Section', 'Header', 'Footer', 'Footnote', 'Endnote', 'Cell', 'TextRun', 'TextBox', 'ListItemRun', ); + $validContainers = array( - 'Text' => $allContainers, - 'Bookmark' => $allContainers, - 'Link' => $allContainers, - 'TextBreak' => $allContainers, - 'Image' => $allContainers, - 'Object' => $allContainers, - 'Field' => $allContainers, - 'Line' => $allContainers, - 'Shape' => $allContainers, - 'FormField' => $allContainers, - 'SDT' => $allContainers, + 'Text' => $generalContainers, + 'Bookmark' => $generalContainers, + 'Link' => $generalContainers, + 'TextBreak' => $generalContainers, + 'Image' => $generalContainers, + 'Object' => $generalContainers, + 'Field' => $generalContainers, + 'Line' => $generalContainers, + 'Shape' => $generalContainers, + 'FormField' => $generalContainers, + 'SDT' => $generalContainers, 'TextRun' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'), 'ListItem' => 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'), 'Chart' => array('Section'), ); + // Special condition, e.g. preservetext can only exists in cell when // the cell is located in header or footer $validSubcontainers = array( @@ -223,19 +223,20 @@ abstract class AbstractContainer extends AbstractElement ); // 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])) { - 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 - if (array_key_exists($method, $validSubcontainers)) { + if (isset($validSubcontainers[$method])) { $rules = $validSubcontainers[$method]; $containers = $rules[0]; $allowedDocParts = $rules[1]; foreach ($containers as $container) { 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}."); } } } diff --git a/src/PhpWord/Element/Field.php b/src/PhpWord/Element/Field.php index 50f0522f..1eaa6f24 100644 --- a/src/PhpWord/Element/Field.php +++ b/src/PhpWord/Element/Field.php @@ -100,7 +100,7 @@ class Field extends AbstractElement public function setType($type = null) { if (isset($type)) { - if (array_key_exists($type, $this->fieldsArray)) { + if (isset($this->fieldsArray[$type])) { $this->type = $type; } else { throw new \InvalidArgumentException("Invalid type"); @@ -130,7 +130,7 @@ class Field extends AbstractElement { if (is_array($properties)) { 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"); } } @@ -160,7 +160,7 @@ class Field extends AbstractElement { if (is_array($options)) { 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"); } } diff --git a/src/PhpWord/Element/Title.php b/src/PhpWord/Element/Title.php index 8d385845..cf1d49c8 100644 --- a/src/PhpWord/Element/Title.php +++ b/src/PhpWord/Element/Title.php @@ -61,11 +61,10 @@ class Title extends AbstractElement */ public function __construct($text, $depth = 1) { - $this->text = String::toUTF8($text); $this->depth = $depth; - if (array_key_exists('Heading_' . $this->depth, Style::getStyles())) { - $this->style = 'Heading' . $this->depth; + if (array_key_exists("Heading_{$this->depth}", Style::getStyles())) { + $this->style = "Heading{$this->depth}"; } return $this; diff --git a/src/PhpWord/Media.php b/src/PhpWord/Media.php index 4bea57ac..59735cea 100644 --- a/src/PhpWord/Media.php +++ b/src/PhpWord/Media.php @@ -48,12 +48,12 @@ class Media { // Assign unique media Id and initiate media container if none exists $mediaId = md5($container . $source); - if (!array_key_exists($container, self::$elements)) { + if (!isset(self::$elements[$container])) { self::$elements[$container] = array(); } // 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); $mediaTypeCount = self::countElements($container, $mediaType); $mediaTypeCount++; @@ -120,7 +120,7 @@ class Media { $mediaCount = 0; - if (array_key_exists($container, self::$elements)) { + if (isset(self::$elements[$container])) { foreach (self::$elements[$container] as $mediaData) { if (!is_null($mediaType)) { if ($mediaType == $mediaData['type']) { @@ -156,7 +156,7 @@ class Media } return $elements; } else { - if (!array_key_exists($container, self::$elements)) { + if (!isset(self::$elements[$container])) { return $elements; } return self::getElementsByType($container, $type); diff --git a/src/PhpWord/PhpWord.php b/src/PhpWord/PhpWord.php index aba1ee38..7568d81b 100644 --- a/src/PhpWord/PhpWord.php +++ b/src/PhpWord/PhpWord.php @@ -139,7 +139,7 @@ class PhpWord /** @var \PhpOffice\PhpWord\Collection\AbstractCollection $collectionObject */ $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 diff --git a/src/PhpWord/Reader/RTF/Document.php b/src/PhpWord/Reader/RTF/Document.php index fcd9703f..3f63e339 100644 --- a/src/PhpWord/Reader/RTF/Document.php +++ b/src/PhpWord/Reader/RTF/Document.php @@ -155,7 +155,7 @@ class Document $char = $this->rtf[$this->offset]; $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]; $this->$markerFunction(); } else { @@ -351,7 +351,7 @@ class Document 'fldinst' => array(self::SKIP, 'link', null), ); - if (array_key_exists($control, $controls)) { + if (isset($controls[$control])) { list($function) = $controls[$control]; if (method_exists($this, $function)) { $directives = $controls[$control]; diff --git a/src/PhpWord/Reader/Word2007.php b/src/PhpWord/Reader/Word2007.php index 6079567f..ebe6c4f7 100644 --- a/src/PhpWord/Reader/Word2007.php +++ b/src/PhpWord/Reader/Word2007.php @@ -63,7 +63,7 @@ class Word2007 extends AbstractReader implements ReaderInterface $stepItems = $step['stepItems']; foreach ($relationships[$stepPart] as $relItem) { $relType = $relItem['type']; - if (array_key_exists($relType, $stepItems)) { + if (isset($stepItems[$relType])) { $partName = $stepItems[$relType]; $xmlFile = $relItem['target']; $this->readPart($phpWord, $relationships, $partName, $docFile, $xmlFile); diff --git a/src/PhpWord/Reader/Word2007/AbstractPart.php b/src/PhpWord/Reader/Word2007/AbstractPart.php index 7d3e0f66..021bdba1 100644 --- a/src/PhpWord/Reader/Word2007/AbstractPart.php +++ b/src/PhpWord/Reader/Word2007/AbstractPart.php @@ -107,7 +107,7 @@ abstract class AbstractPart $headingMatches = array(); if ($xmlReader->elementExists('w:pPr', $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); } } @@ -505,10 +505,9 @@ abstract class AbstractPart private function getMediaTarget($docPart, $rId) { $target = null; - if (array_key_exists($docPart, $this->rels)) { - if (array_key_exists($rId, $this->rels[$docPart])) { - $target = $this->rels[$docPart][$rId]['target']; - } + + if (isset($this->rels[$docPart]) && isset($this->rels[$docPart][$rId])) { + $target = $this->rels[$docPart][$rId]['target']; } return $target; diff --git a/src/PhpWord/Reader/Word2007/DocPropsCore.php b/src/PhpWord/Reader/Word2007/DocPropsCore.php index 4c48ecbc..54537525 100644 --- a/src/PhpWord/Reader/Word2007/DocPropsCore.php +++ b/src/PhpWord/Reader/Word2007/DocPropsCore.php @@ -67,12 +67,12 @@ class DocPropsCore extends AbstractPart $nodes = $xmlReader->getElements('*'); if ($nodes->length > 0) { foreach ($nodes as $node) { - if (!array_key_exists($node->nodeName, $this->mapping)) { + if (!isset($this->mapping[$node->nodeName])) { continue; } $method = $this->mapping[$node->nodeName]; $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); } if (method_exists($docProps, $method)) { diff --git a/src/PhpWord/Reader/Word2007/Document.php b/src/PhpWord/Reader/Word2007/Document.php index 3ced6763..e1beed06 100644 --- a/src/PhpWord/Reader/Word2007/Document.php +++ b/src/PhpWord/Reader/Word2007/Document.php @@ -53,7 +53,7 @@ class Document extends AbstractPart if ($nodes->length > 0) { $section = $this->phpWord->addSection(); foreach ($nodes as $node) { - if (array_key_exists($node->nodeName, $readMethods)) { + if (isset($readMethods[$node->nodeName])) { $readMethod = $readMethods[$node->nodeName]; $this->$readMethod($xmlReader, $node, $section); } @@ -72,9 +72,9 @@ class Document extends AbstractPart { $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) { - if (array_key_exists($rId, $this->rels['document'])) { + if (isset($this->rels['document'][$rId])) { list($hfType, $xmlFile, $docPart) = array_values($this->rels['document'][$rId]); $addMethod = "add{$hfType}"; $hfObject = $section->$addMethod($hfSetting['type']); @@ -85,7 +85,7 @@ class Document extends AbstractPart $nodes = $xmlReader->getElements('*'); if ($nodes->length > 0) { foreach ($nodes as $node) { - if (array_key_exists($node->nodeName, $readMethods)) { + if (isset($readMethods[$node->nodeName])) { $readMethod = $readMethods[$node->nodeName]; $this->$readMethod($xmlReader, $node, $hfObject, $docPart); } diff --git a/src/PhpWord/Reader/Word2007/Footnotes.php b/src/PhpWord/Reader/Word2007/Footnotes.php index c66b13fe..6f6adc87 100644 --- a/src/PhpWord/Reader/Word2007/Footnotes.php +++ b/src/PhpWord/Reader/Word2007/Footnotes.php @@ -62,7 +62,7 @@ class Footnotes extends AbstractPart // Avoid w:type "separator" and "continuationSeparator" // Only look for or without w:type attribute - if (is_null($type) && array_key_exists($id, $collection)) { + if (is_null($type) && isset($collection[$id])) { $element = $collection[$id]; $pNodes = $xmlReader->getElements('w:p/*', $node); foreach ($pNodes as $pNode) { diff --git a/src/PhpWord/Shared/Html.php b/src/PhpWord/Shared/Html.php index 13824f33..2b4acd05 100644 --- a/src/PhpWord/Shared/Html.php +++ b/src/PhpWord/Shared/Html.php @@ -133,8 +133,7 @@ class Html $newElement = null; $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 // Arguments are passed by reference $arguments = array(); diff --git a/src/PhpWord/Style.php b/src/PhpWord/Style.php index 73af4f5d..ab03106f 100644 --- a/src/PhpWord/Style.php +++ b/src/PhpWord/Style.php @@ -163,7 +163,7 @@ class Style */ public static function getStyle($styleName) { - if (array_key_exists($styleName, self::$styles)) { + if (isset(self::$styles[$styleName])) { return self::$styles[$styleName]; } else { return null; @@ -182,7 +182,7 @@ class Style */ private static function setStyleValues($name, $style, $value = null) { - if (!array_key_exists($name, self::$styles)) { + if (!isset(self::$styles[$name])) { if ($value !== null) { if (is_array($value)) { $style->setStyleByArray($value); diff --git a/src/PhpWord/Writer/AbstractWriter.php b/src/PhpWord/Writer/AbstractWriter.php index 31097b89..599d8a6f 100644 --- a/src/PhpWord/Writer/AbstractWriter.php +++ b/src/PhpWord/Writer/AbstractWriter.php @@ -343,7 +343,7 @@ abstract class AbstractWriter implements WriterInterface $type = $element['type']; // image|object|link // Skip nonregistered types and set target - if (!array_key_exists($type, $this->mediaPaths)) { + if (!isset($this->mediaPaths[$type])) { continue; } $target = $this->mediaPaths[$type] . $element['target']; diff --git a/src/PhpWord/Writer/HTML/Part/Body.php b/src/PhpWord/Writer/HTML/Part/Body.php index 4fd61a83..b91ca3ad 100644 --- a/src/PhpWord/Writer/HTML/Part/Body.php +++ b/src/PhpWord/Writer/HTML/Part/Body.php @@ -72,7 +72,7 @@ class Body extends AbstractPart $method = 'get' . ($noteType == 'endnote' ? 'Endnotes' : 'Footnotes'); $collection = $phpWord->$method()->getItems(); - if (array_key_exists($noteTypeId, $collection)) { + if (isset($collection[$noteTypeId])) { $element = $collection[$noteTypeId]; $noteAnchor = ""; $noteAnchor .= "{$noteId}"; diff --git a/src/PhpWord/Writer/RTF/Part/Document.php b/src/PhpWord/Writer/RTF/Part/Document.php index f239f9e2..edcdbd84 100644 --- a/src/PhpWord/Writer/RTF/Part/Document.php +++ b/src/PhpWord/Writer/RTF/Part/Document.php @@ -64,7 +64,7 @@ class Document extends AbstractPart $content .= '{'; $content .= '\info'; 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 = in_array($property, $dateFields) ? $this->getDateValue($value) : $value; $content .= "{\\{$property} {$value}}"; diff --git a/src/PhpWord/Writer/Word2007.php b/src/PhpWord/Writer/Word2007.php index baac8222..09d09509 100644 --- a/src/PhpWord/Writer/Word2007.php +++ b/src/PhpWord/Writer/Word2007.php @@ -302,11 +302,11 @@ class Word2007 extends AbstractWriter implements WriterInterface $mediumType = $medium['type']; if ($mediumType == 'image') { $extension = $medium['imageExtension']; - if (!array_key_exists($extension, $this->contentTypes['default'])) { + if (!isset($this->contentTypes['default'][$extension])) { $this->contentTypes['default'][$extension] = $medium['imageType']; } } 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'; } } diff --git a/src/PhpWord/Writer/Word2007/Part/Rels.php b/src/PhpWord/Writer/Word2007/Part/Rels.php index 80ab6307..9a7f444b 100644 --- a/src/PhpWord/Writer/Word2007/Part/Rels.php +++ b/src/PhpWord/Writer/Word2007/Part/Rels.php @@ -89,8 +89,8 @@ class Rels extends AbstractPart $targetMapping = array('image' => 'media/', 'object' => 'embeddings/'); $mediaType = $mediaRel['type']; - $type = array_key_exists($mediaType, $typeMapping) ? $typeMapping[$mediaType] : $mediaType; - $targetPrefix = array_key_exists($mediaType, $targetMapping) ? $targetMapping[$mediaType] : ''; + $type = isset($typeMapping[$mediaType]) ? $typeMapping[$mediaType] : $mediaType; + $targetPrefix = isset($targetMapping[$mediaType]) ? $targetMapping[$mediaType] : ''; $target = $mediaRel['target']; $targetMode = ($type == 'hyperlink') ? 'External' : ''; diff --git a/src/PhpWord/Writer/Word2007/Part/Styles.php b/src/PhpWord/Writer/Word2007/Part/Styles.php index 6a8de48a..01942229 100644 --- a/src/PhpWord/Writer/Word2007/Part/Styles.php +++ b/src/PhpWord/Writer/Word2007/Part/Styles.php @@ -19,9 +19,9 @@ namespace PhpOffice\PhpWord\Writer\Word2007\Part; use PhpOffice\PhpWord\Settings as PhpWordSettings; use PhpOffice\PhpWord\Shared\XMLWriter; +use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style\Font as FontStyle; use PhpOffice\PhpWord\Style\Paragraph as ParagraphStyle; -use PhpOffice\PhpWord\Style; use PhpOffice\PhpWord\Style\Table as TableStyle; use PhpOffice\PhpWord\Writer\Word2007\Style\Font as FontStyleWriter; use PhpOffice\PhpWord\Writer\Word2007\Style\Paragraph as ParagraphStyleWriter; @@ -114,14 +114,14 @@ class Styles extends AbstractPart $xmlWriter->startElement('w:name'); $xmlWriter->writeAttribute('w:val', 'Normal'); $xmlWriter->endElement(); // w:name - if (array_key_exists('Normal', $styles)) { + if (isset($styles['Normal'])) { $styleWriter = new ParagraphStyleWriter($xmlWriter, $styles['Normal']); $styleWriter->write(); } $xmlWriter->endElement(); // w:style // FootnoteReference style - if (!array_key_exists('FootnoteReference', $styles)) { + if (!isset($styles['FootnoteReference'])) { $xmlWriter->startElement('w:style'); $xmlWriter->writeAttribute('w:type', 'character'); $xmlWriter->writeAttribute('w:styleId', 'FootnoteReference'); diff --git a/src/PhpWord/Writer/Word2007/Style/Frame.php b/src/PhpWord/Writer/Word2007/Style/Frame.php index 2dd61765..28ebeaf5 100644 --- a/src/PhpWord/Writer/Word2007/Style/Frame.php +++ b/src/PhpWord/Writer/Word2007/Style/Frame.php @@ -64,7 +64,7 @@ class Frame extends AbstractStyle // zIndex for infront & behind wrap $wrap = $style->getWrap(); - if ($wrap !== null && array_key_exists($wrap, $zIndices)) { + if ($wrap !== null && isset($zIndices[$wrap])) { $styles['z-index'] = $zIndices[$wrap]; $wrap = null; } @@ -124,10 +124,10 @@ class Frame extends AbstractStyle $xmlWriter->writeAttribute('anchorx', "page"); $xmlWriter->writeAttribute('anchory', "page"); } elseif ($pos == FrameStyle::POS_RELATIVE) { - if (array_key_exists($hPos, $relativePositions)) { + if (isset($relativePositions[$hPos])) { $xmlWriter->writeAttribute('anchorx', $relativePositions[$hPos]); } - if (array_key_exists($vPos, $relativePositions)) { + if (isset($relativePositions[$vPos])) { $xmlWriter->writeAttribute('anchory', $relativePositions[$vPos]); } } diff --git a/src/PhpWord/Writer/Word2007/Style/Line.php b/src/PhpWord/Writer/Word2007/Style/Line.php index fd1c21de..48e27492 100644 --- a/src/PhpWord/Writer/Word2007/Style/Line.php +++ b/src/PhpWord/Writer/Word2007/Style/Line.php @@ -58,7 +58,7 @@ class Line extends Frame $xmlWriter->writeAttributeIf($style->getEndArrow() !== null, 'endarrow', $style->getEndArrow()); if ($dash !== null) { - if (array_key_exists($dash, $dashStyles)) { + if (isset($dashStyles[$dash])) { $xmlWriter->writeAttribute('dashstyle', $dashStyles[$dash]); } if ($dash == LineStyle::DASH_STYLE_ROUND_DOT) { diff --git a/src/PhpWord/Writer/Word2007/Style/MarginBorder.php b/src/PhpWord/Writer/Word2007/Style/MarginBorder.php index fb4afede..30029112 100644 --- a/src/PhpWord/Writer/Word2007/Style/MarginBorder.php +++ b/src/PhpWord/Writer/Word2007/Style/MarginBorder.php @@ -83,7 +83,7 @@ class MarginBorder extends AbstractStyle $xmlWriter->startElement('w:' . $side); if (!empty($this->colors)) { if ($color === null && !empty($this->attributes)) { - if (array_key_exists('defaultColor', $this->attributes)) { + if (isset($this->attributes['defaultColor'])) { $color = $this->attributes['defaultColor']; } } @@ -91,7 +91,7 @@ class MarginBorder extends AbstractStyle $xmlWriter->writeAttribute('w:sz', $width); $xmlWriter->writeAttribute('w:color', $color); if (!empty($this->attributes)) { - if (array_key_exists('space', $this->attributes)) { + if (isset($this->attributes['space'])) { $xmlWriter->writeAttribute('w:space', $this->attributes['space']); } }