diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d260dc..97a03ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog All Notable changes to `jobs-common` will be documented in this file +## 2.1.2 - 2017-01-21 + +### Fixed +- Fixed bug that threw an exception for some providers when empty results were returned from the API. + ## 2.1.1 - 2016-12-23 ### Fixed diff --git a/src/Providers/AbstractProvider.php b/src/Providers/AbstractProvider.php index e443ac8..916a98e 100644 --- a/src/Providers/AbstractProvider.php +++ b/src/Providers/AbstractProvider.php @@ -191,17 +191,15 @@ public function setQuery(AbstractQuery $query) } /** - * Create and get collection of jobs from given listings + * Adds a single job item to a collection (passed by reference) * - * @param array $listings + * @param $collection Collection + * @param $item array * - * @return Collection + * @return $collection */ - protected function getJobsCollectionFromListings(array $listings = []) - { - $collection = new Collection; - - array_map(function ($item) use ($collection) { + protected function addJobItemToCollection(&$collection, $item = []) { + if ($item) { $item = static::parseAttributeDefaults( $item, $this->getDefaultResponseFields() @@ -210,6 +208,23 @@ protected function getJobsCollectionFromListings(array $listings = []) $job->setQuery($this->query->getKeyword()) ->setSource($this->getSource()); $collection->add($job); + } + return $collection; + } + + /** + * Create and get collection of jobs from given listings + * + * @param array $listings + * + * @return Collection + */ + protected function getJobsCollectionFromListings(array $listings = []) + { + $collection = new Collection; + + array_map(function ($item) use ($collection) { + $this->addJobItemToCollection($collection, $item); }, $listings); return $collection;