Skip to content

Commit

Permalink
Laravel 8 support + lowest dep. on openfoodfacts-php 0.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
epalmans committed Oct 4, 2020
1 parent 9994e1e commit 9f73036
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
"require": {
"php": ">=7.2.5",
"guzzlehttp/guzzle": "^6.3.1|^7.0",
"illuminate/support": "5.7.x|5.8.x|^6.0|^7.0",
"openfoodfacts/openfoodfacts-php": "^0.2.0"
"illuminate/support": "5.7.x|5.8.x|^6.0|^7.0|^8.0",
"openfoodfacts/openfoodfacts-php": "^0.2.3"
},
"require-dev": {
"orchestra/testbench": "^3.7|4.*|5.*",
"orchestra/testbench": "^3.7|4.*|5.*|6.*",
"phpunit/phpunit": "^7.5|^8.4|^9.0"
},
"autoload": {
Expand Down
10 changes: 7 additions & 3 deletions src/OpenFoodFacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace OpenFoodFacts\Laravel;

use Illuminate\Contracts\Config\Repository;
use Illuminate\Contracts\Container\Container;
use Illuminate\Support\Collection;
use InvalidArgumentException;
use OpenFoodFacts\Exception\ProductNotFoundException;

class OpenFoodFacts extends OpenFoodFactsApiWrapper
{
Expand All @@ -27,9 +27,13 @@ public function barcode($value)
throw new InvalidArgumentException("Argument must represent a barcode");
}

$doc = $this->api->getProduct($value);
try {
$doc = $this->api->getProduct($value);

return empty($doc->code) ? [] : reset($doc);
return empty($doc->code) ? [] : reset($doc);
} catch (ProductNotFoundException $notFoundException) {
return [];
}
}

public function find($searchterm)
Expand Down

0 comments on commit 9f73036

Please sign in to comment.