Skip to content

Commit

Permalink
Bugfixes, make sure the factory always is able to return a valid "Per…
Browse files Browse the repository at this point in the history
…son/Cast/Crew" object.
  • Loading branch information
wtfzdotnet committed Feb 22, 2014
1 parent 92ca2a4 commit ff72b62
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
9 changes: 7 additions & 2 deletions lib/Tmdb/Factory/People/CastFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ public function create(array $data = array(), $person = null)

/**
* {@inheritdoc}
* @param \Tmdb\Model\Tv\Person\CastMember $person
* @param \Tmdb\Model\Person\CastMember $person
*/
public function createCollection(array $data = array(), $person = null)
{
$collection = new Cast();

$class = get_class($person);
if (is_object($person)) {
$class = get_class($person);
}
else{
$class = '\Tmdb\Model\Person\CastMember';
}

foreach($data as $item) {
$collection->add(null, $this->create($item, new $class()));
Expand Down
9 changes: 7 additions & 2 deletions lib/Tmdb/Factory/People/CrewFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ public function create(array $data = array(), $person = null)

/**
* {@inheritdoc}
* @param \Tmdb\Model\Tv\Person\CrewMember $person
* @param \Tmdb\Model\Person\CrewMember $person
*/
public function createCollection(array $data = array(), $person = null)
{
$collection = new Crew();

$class = get_class($person);
if (is_object($person)) {
$class = get_class($person);
}
else{
$class = '\Tmdb\Model\Person\CrewMember';
}

foreach($data as $item) {
$collection->add(null, $this->create($item, new $class()));
Expand Down
11 changes: 8 additions & 3 deletions lib/Tmdb/Factory/PeopleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct()
*
* @return Person|CrewMember|CastMember
*/
public function create(array $data = array(), Person\AbstractMember $person = null)
public function create(array $data = array(), $person = null)
{
if (!is_object($person)) {
if (array_key_exists('character', $data)) {
Expand Down Expand Up @@ -143,7 +143,7 @@ protected function getPosterImageForCredit($posterPath)
/**
* {@inheritdoc}
*/
public function createCollection(array $data = array(), Person\AbstractMember $person = null, $collection = null)
public function createCollection(array $data = array(), $person = null, $collection = null)
{
if (!$collection) {
$collection = new People();
Expand All @@ -153,7 +153,12 @@ public function createCollection(array $data = array(), Person\AbstractMember $p
$data = $data['results'];
}

$class = get_class($person);
if (is_object($person)) {
$class = get_class($person);
}
else{
$class = '\Tmdb\Model\Person';
}

foreach($data as $item) {
$collection->add(null, $this->create($item, new $class()));
Expand Down

0 comments on commit ff72b62

Please sign in to comment.