From 36f4c90f1079ec802a9641b93c0081a907dd5156 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Wed, 29 Jan 2014 01:30:31 +0100 Subject: [PATCH] Clean up --- lib/Tmdb/Common/ObjectHydrator.php | 4 ++-- lib/Tmdb/Factory/AbstractFactory.php | 7 ++++--- test/Tmdb/Tests/Common/ObjectHydratorTest.php | 8 ++++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/Tmdb/Common/ObjectHydrator.php b/lib/Tmdb/Common/ObjectHydrator.php index ba6ab3b2..1b9a73b7 100644 --- a/lib/Tmdb/Common/ObjectHydrator.php +++ b/lib/Tmdb/Common/ObjectHydrator.php @@ -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) ); diff --git a/lib/Tmdb/Factory/AbstractFactory.php b/lib/Tmdb/Factory/AbstractFactory.php index c39a8cae..ba75d318 100644 --- a/lib/Tmdb/Factory/AbstractFactory.php +++ b/lib/Tmdb/Factory/AbstractFactory.php @@ -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; @@ -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()); @@ -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); } } diff --git a/test/Tmdb/Tests/Common/ObjectHydratorTest.php b/test/Tmdb/Tests/Common/ObjectHydratorTest.php index 35a671b8..e6c84177 100644 --- a/test/Tmdb/Tests/Common/ObjectHydratorTest.php +++ b/test/Tmdb/Tests/Common/ObjectHydratorTest.php @@ -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' )); @@ -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')); } }