Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
Fixed default data if response is malformed
Browse files Browse the repository at this point in the history
  • Loading branch information
Edwin Jacobs committed Dec 4, 2019
1 parent 67b754e commit 67f8062
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions app/code/community/Emico/Tweakwise/Model/Bus/Type/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected function setDataFromField(SimpleXMLElement $xmlElement, $field, $type,
$data = $useProvidedAsData ? $xmlElement : $xmlElement->{$field};

if (!is_object($data)) {
$this->setData($dataKey, '');
$this->setData($dataKey, $this->resolveDefaultValue($count));

return $this;
}
Expand All @@ -76,6 +76,22 @@ protected function setDataFromField(SimpleXMLElement $xmlElement, $field, $type,
return $this;
}

/**
* @param $count
* @return array|string|null
*/
protected function resolveDefaultValue($count)
{
switch ($count) {
case self::ELEMENT_COUNT_ONE:
case self::ELEMENT_COUNT_NONE_OR_ONE:
return '';
case self::ELEMENT_COUNT_NONE_OR_MORE:
case self::ELEMENT_COUNT_ONE_OR_MORE:
return [];
}
}

/**
* @param SimpleXMLElement $xmlElement
* @param string $type
Expand Down Expand Up @@ -120,4 +136,4 @@ protected function setDataFromAttribute(SimpleXMLElement $element, $attribute, $
$this->setData($dataKey, $value);
}
}
}
}

0 comments on commit 67f8062

Please sign in to comment.