public function getPhotos() : PhotoCollection { $collection = new PhotoCollection(); $data = $this->getData(); $photo = null; foreach ($data as $current) { if ($current instanceof \stdClass) { /** @var \stdClass $current */ if ($photo instanceof Photo) { if ($photo->getId() == $current->id) { $photo->addTag(implode('/', [$current->tag1, $current->tag2, $current->tag3])); } else { $photo = Photo::createFromObject($current); } } else { $photo = Photo::createFromObject($current); } } elseif (is_array($current)) { /** @var array $current */ if ($photo instanceof Photo) { if ($photo->getId() == $current['id']) { $photo->addTag(implode('/', [$current['tag1'], $current['tag2'], $current['tag3']])); } else { $photo = Photo::createFromArray($current); } } else { $photo = Photo::createFromArray($current); } } $collection->add($photo); } return $collection; }