Skip to content

Commit 1e82762

Browse files
author
Refactor Studio
authored
Merge pull request #5 from refactorstudio/scrutinizer-patch-1
Scrutinizer Auto-Fixes
2 parents f623912 + 8ba00b3 commit 1e82762

File tree

1 file changed

+31
-32
lines changed

1 file changed

+31
-32
lines changed

src/PhpArrayToXml.php

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function getFormatOutput()
116116
public function setCustomRootName($value)
117117
{
118118
if (!$this->isValidXmlTag($value)) {
119-
throw new \Exception('Not a valid root name: ' . $value);
119+
throw new \Exception('Not a valid root name: '.$value);
120120
}
121121

122122
$this->_custom_root_name = $value;
@@ -154,7 +154,7 @@ public function getDefaultRootName()
154154
public function setCustomTagName($value)
155155
{
156156
if (!$this->isValidXmlTag($value)) {
157-
throw new \Exception('Not a valid tag name: ' . $value);
157+
throw new \Exception('Not a valid tag name: '.$value);
158158
}
159159

160160
$this->_custom_tag_name = $value;
@@ -217,14 +217,14 @@ public function getSeparator()
217217
*/
218218
public function setTransformTags($value = null)
219219
{
220-
switch($value) {
220+
switch ($value) {
221221
case self::LOWERCASE:
222222
case self::UPPERCASE: {
223223
$this->_transform_tags = $value;
224224
break;
225225
}
226226
default: {
227-
if($value === null) {
227+
if ($value === null) {
228228
$this->_transform_tags = null;
229229
}
230230
}
@@ -253,7 +253,7 @@ public function setNumericTagSuffix($value = null)
253253
{
254254
$this->_numeric_tag_suffix = $value;
255255

256-
if($value === true || $value === false) {
256+
if ($value === true || $value === false) {
257257
$this->_numeric_tag_suffix = '';
258258
}
259259
return $this;
@@ -340,7 +340,7 @@ public function getCastNullValue()
340340
*/
341341
public static function hasValidXmlTagStartingChar($value = null)
342342
{
343-
if(preg_match(self::getValidXmlTagStartPattern(), $value) === 1) {
343+
if (preg_match(self::getValidXmlTagStartPattern(), $value) === 1) {
344344
return true;
345345
}
346346
return false;
@@ -354,7 +354,7 @@ public static function hasValidXmlTagStartingChar($value = null)
354354
*/
355355
public static function isValidXmlTagChar($value = null)
356356
{
357-
if(preg_match(self::getValidXmlTagNameChar(), $value) === 1) {
357+
if (preg_match(self::getValidXmlTagNameChar(), $value) === 1) {
358358
return true;
359359
}
360360
return false;
@@ -368,11 +368,11 @@ public static function isValidXmlTagChar($value = null)
368368
*/
369369
public static function isValidXmlTag($value = null)
370370
{
371-
if(empty($value) || is_int($value)) {
371+
if (empty($value) || is_int($value)) {
372372
return false;
373373
}
374374

375-
if(preg_match(self::getValidXmlTagNamePattern(), $value) === 1) {
375+
if (preg_match(self::getValidXmlTagNamePattern(), $value) === 1) {
376376
return true;
377377
}
378378
return false;
@@ -458,19 +458,19 @@ protected function addArrayElements(DOMElement $parent, $array = [])
458458
$parent->appendChild($node);
459459
} else {
460460

461-
if(array_key_exists('@value', $value)) {
461+
if (array_key_exists('@value', $value)) {
462462
$cdata = array_key_exists('@cdata', $value) && $value['@cdata'] === true ? true : false;
463463
$attributes = array_key_exists('@attr', $value) && is_array($value['@attr']) ? $value['@attr'] : [];
464464

465-
if(!is_array($value['@value'])) {
465+
if (!is_array($value['@value'])) {
466466
// Create an XML element
467467
$node = $this->createElement($name, $value['@value'], $cdata, $attributes);
468468
$parent->appendChild($node);
469469
} else {
470470
// Create an empty XML element 'container'
471471
$node = $this->createElement($name, null);
472472

473-
foreach($attributes as $attribute_name => $attribute_value) {
473+
foreach ($attributes as $attribute_name => $attribute_value) {
474474
$node->setAttribute($attribute_name, $this->normalizeAttributeValue($attribute_value));
475475
}
476476

@@ -479,8 +479,7 @@ protected function addArrayElements(DOMElement $parent, $array = [])
479479
// Add all the elements within the array to the 'container'
480480
$this->addArrayElements($node, $value['@value']);
481481
}
482-
}
483-
else {
482+
} else {
484483
// Create an empty XML element 'container'
485484
$node = $this->createElement($name, null);
486485
$parent->appendChild($node);
@@ -501,15 +500,15 @@ protected function addArrayElements(DOMElement $parent, $array = [])
501500
*/
502501
protected function normalizeValue($value)
503502
{
504-
if($value === true) {
503+
if ($value === true) {
505504
return $this->getCastBooleanValueTrue();
506505
}
507506

508-
if($value === false) {
507+
if ($value === false) {
509508
return $this->getCastBooleanValueFalse();
510509
}
511510

512-
if($value === null) {
511+
if ($value === null) {
513512
return $this->getCastNullValue();
514513
}
515514

@@ -524,11 +523,11 @@ protected function normalizeValue($value)
524523
*/
525524
protected function normalizeAttributeValue($value)
526525
{
527-
if($value === true) {
526+
if ($value === true) {
528527
return 'true';
529528
}
530529

531-
if($value === false) {
530+
if ($value === false) {
532531
return 'false';
533532
}
534533

@@ -561,11 +560,11 @@ protected function createElement($name, $value = null, $cdata = false, $attribut
561560
{
562561
$name = $this->createValidTagName($name);
563562

564-
if($cdata === true) {
563+
if ($cdata === true) {
565564
$element = $this->_doc->createElement($name);
566565
$element->appendChild($this->_doc->createCDATASection($value));
567566

568-
foreach($attributes as $attribute_name => $attribute_value) {
567+
foreach ($attributes as $attribute_name => $attribute_value) {
569568
$element->setAttribute($attribute_name, $this->normalizeAttributeValue($attribute_value));
570569
}
571570

@@ -574,7 +573,7 @@ protected function createElement($name, $value = null, $cdata = false, $attribut
574573

575574
$element = $this->_doc->createElement($name, $this->normalizeValue($value));
576575

577-
foreach($attributes as $attribute_name => $attribute_value) {
576+
foreach ($attributes as $attribute_name => $attribute_value) {
578577
$element->setAttribute($attribute_name, $this->normalizeAttributeValue($attribute_value));
579578
}
580579

@@ -589,7 +588,7 @@ protected function createElement($name, $value = null, $cdata = false, $attribut
589588
*/
590589
protected function createValidTagName($name = null)
591590
{
592-
if(empty($name) || $this->isNumericKey($name)) {
591+
if (empty($name) || $this->isNumericKey($name)) {
593592
$key = $name;
594593

595594
if ($this->isValidXmlTag($this->getCustomTagName())) {
@@ -598,16 +597,16 @@ protected function createValidTagName($name = null)
598597
$name = $this->transformTagName($this->getDefaultTagName());
599598
}
600599

601-
if($this->getNumericTagSuffix() !== null) {
602-
$name = $name . (string)$this->getNumericTagSuffix() . $key;
600+
if ($this->getNumericTagSuffix() !== null) {
601+
$name = $name.(string) $this->getNumericTagSuffix().$key;
603602
}
604603
return $name;
605604
}
606605

607-
if(!$this->isValidXmlTag($name)) {
606+
if (!$this->isValidXmlTag($name)) {
608607
$name = $this->replaceInvalidTagChars($name);
609608

610-
if(!self::hasValidXmlTagStartingChar($name)) {
609+
if (!self::hasValidXmlTagStartingChar($name)) {
611610
$name = $this->prefixInvalidTagStartingChar($name);
612611
}
613612
}
@@ -622,7 +621,7 @@ protected function createValidTagName($name = null)
622621
*/
623622
protected function prefixInvalidTagStartingChar($value)
624623
{
625-
return '_' . substr($value, 1);
624+
return '_'.substr($value, 1);
626625
}
627626

628627
/**
@@ -634,13 +633,13 @@ protected function prefixInvalidTagStartingChar($value)
634633
protected function replaceInvalidTagChars($value)
635634
{
636635
$pattern = '';
637-
for($i=0; $i < strlen($value); $i++) {
638-
if(!self::isValidXmlTagChar($value[$i])) {
636+
for ($i = 0; $i < strlen($value); $i++) {
637+
if (!self::isValidXmlTagChar($value[$i])) {
639638
$pattern .= "\\$value[$i]";
640639
}
641640
}
642641

643-
if(!empty($pattern)) {
642+
if (!empty($pattern)) {
644643
$value = preg_replace("/[{$pattern}]/", $this->getSeparator(), $value);
645644
}
646645
return $value;
@@ -671,7 +670,7 @@ protected function createValidRootName($name = null)
671670
*/
672671
protected function transformTagName($name = null)
673672
{
674-
switch($this->getTransformTags()) {
673+
switch ($this->getTransformTags()) {
675674
case self::LOWERCASE: {
676675
return strtolower($name);
677676
}

0 commit comments

Comments
 (0)