Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Jan 29, 2014
1 parent f73fc2a commit 36f4c90
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/Tmdb/Common/ObjectHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ class ObjectHydrator {
* @return AbstractModel
* @throws RuntimeException
*/
public static function hydrate(AbstractModel $object, $data = array())
public function hydrate(AbstractModel $object, $data = array())
{
if (!empty($data)) {
foreach ($data as $k => $v) {
if (in_array($k, $object::$_properties)) {

$method = self::camelize(
$method = $this->camelize(
sprintf('set_%s', $k)
);

Expand Down
7 changes: 4 additions & 3 deletions lib/Tmdb/Factory/AbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
namespace Tmdb\Factory;

use Tmdb\Common\ObjectHydrator;
use Tmdb\Factory\Common\GenericCollectionFactory;
use Tmdb\Model\AbstractModel;
use Tmdb\Model\Common\GenericCollection;

Expand All @@ -30,7 +29,7 @@ abstract public function create(array $data = array());
* Convert an array with an collection of items to an hydrated object collection
*
* @param array $data
* @return GenericCollectionFactory
* @return GenericCollection
*/
abstract public function createCollection(array $data = array());

Expand Down Expand Up @@ -65,6 +64,8 @@ protected function createGenericCollection(array $data = array(), $class)
*/
protected function hydrate(AbstractModel $object, $data = array())
{
return ObjectHydrator::hydrate($object, $data);
$objectHydrator = new ObjectHydrator();

return $objectHydrator->hydrate($object, $data);
}
}
8 changes: 6 additions & 2 deletions test/Tmdb/Tests/Common/ObjectHydratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class ObjectHydratorTest extends \PHPUnit_Framework_TestCase
*/
public function canHydrateObject()
{
$subject = \Tmdb\Common\ObjectHydrator::hydrate(new TestModel(), array(
$objectHydrator = new \Tmdb\Common\ObjectHydrator();

$subject = $objectHydrator->hydrate(new TestModel(), array(
'id' => 15,
'name' => 'Michael'
));
Expand All @@ -33,7 +35,9 @@ public function canHydrateObject()
*/
public function callingNonExistingMethodThrowsException()
{
\Tmdb\Common\ObjectHydrator::hydrate(new FailingTestModel(), array('lastname' => 'Roterman'));
$objectHydrator = new \Tmdb\Common\ObjectHydrator();

$objectHydrator->hydrate(new FailingTestModel(), array('lastname' => 'Roterman'));
}
}

Expand Down

0 comments on commit 36f4c90

Please sign in to comment.