From c1a8e787e67f30cfe0609a18e78e1b6edcfdc7dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20DELSOL?= Date: Thu, 7 Mar 2019 10:11:11 +0100 Subject: [PATCH] issue #7 - refactor attribute namespace detection and usage try to improve Scrutinizer note :) --- src/Element.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Element.php b/src/Element.php index d712111..ca74ba8 100644 --- a/src/Element.php +++ b/src/Element.php @@ -335,15 +335,11 @@ protected function appendAttributesToElementToSend(\DOMElement $element) { if ($this->hasAttributes()) { foreach ($this->getAttributes() as $attributeName => $attributeValue) { - if (false === strpos($attributeName, ':')) { + $matches = []; + if (0 === preg_match(sprintf('/(%s|%s):/', self::NS_WSSU_NAME, self::NS_WSSE_NAME), $attributeName, $matches)) { $element->setAttribute($attributeName, $attributeValue); } else { - list($ns) = explode(':', $attributeName); - if (self::NS_WSSE_NAME === $ns || self::NS_WSSU_NAME === $ns) { - $element->setAttributeNS(self::NS_WSSE_NAME === $ns ? self::NS_WSSE : self::NS_WSSU, $attributeName, $attributeValue); - } else { - $element->setAttribute($attributeName, $attributeValue); - } + $element->setAttributeNS(self::NS_WSSE_NAME === $matches[1] ? self::NS_WSSE : self::NS_WSSU, $attributeName, $attributeValue); } } }