Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Updates patch to follow framework conventions
Browse files Browse the repository at this point in the history
- Import all classes used
- Return from conditionals in order to prevent if/elseif/else
- Add comments for behavior needing explanations
  • Loading branch information
weierophinney committed Sep 20, 2017
1 parent 7b18f65 commit cbc97e8
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/ArraySerializable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace Zend\Hydrator;

use Zend\Stdlib\ArrayUtils;

class ArraySerializable extends AbstractHydrator
{
/**
Expand Down Expand Up @@ -68,18 +70,23 @@ public function hydrate(array $data, $object)
}

if (is_callable([$object, 'exchangeArray'])) {
// Ensure any previously populated values not in the replacement
// remain following population.
if (is_callable([$object, 'getArrayCopy'])) {
$original = $object->getArrayCopy($object);
$replacement = \Zend\Stdlib\ArrayUtils::merge($original, $replacement);
$replacement = ArrayUtils::merge($original, $replacement);
}
$object->exchangeArray($replacement);
} elseif (is_callable([$object, 'populate'])) {
return $object;
}

if (is_callable([$object, 'populate'])) {
$object->populate($replacement);
} else {
throw new Exception\BadMethodCallException(
sprintf('%s expects the provided object to implement exchangeArray() or populate()', __METHOD__)
);
return $object;
}
return $object;

throw new Exception\BadMethodCallException(
sprintf('%s expects the provided object to implement exchangeArray() or populate()', __METHOD__)
);
}
}

0 comments on commit cbc97e8

Please sign in to comment.