OpenFoodFactsApiWrapper   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 33
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A setupApi() 0 10 1
A httpClient() 0 6 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