OpenFoodFactsApiWrapper::httpClient()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Palmans\LaravelOpenFoodFacts;
4
5
use GuzzleHttp\Client;
6
use OpenFoodFacts\Api;
7
use Psr\SimpleCache\CacheInterface;
8
9
class OpenFoodFactsApiWrapper
10
{
11
    protected $parameters;
12
    protected $cache;
13
14
    public $api;
15
16 8
    public function __construct(array $parameters, CacheInterface $cache = null)
17
    {
18 8
        $this->parameters = $parameters;
19 8
        $this->cache = $cache;
20
21 8
        $this->api = $this->setupApi();
22 8
    }
23
24 8
    protected function setupApi($environment = 'food')
25
    {
26 8
        return new Api(
27 8
            $environment,
28 8
            $this->parameters['geography'] ?? 'world',
29 8
            null,
30 8
            $this->httpClient(),
31 8
            $this->cache
32
        );
33
    }
34
35 8
    protected function httpClient()
36
    {
37 8
        return new Client([
38 8
            'headers' => ['User-Agent' => $this->parameters['app'] ?? 'Laravel Open Food Facts - https://github.com/palmans/laravel-openfoodfacts'],
39
        ]);
40
    }
41
}
42