Issues (1)

src/OpenFoodFactsApiWrapper.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace OpenFoodFacts\Laravel;
4
5
use GuzzleHttp\Client;
6
use OpenFoodFacts\Api;
7
use Psr\SimpleCache\CacheInterface;
8
9
class OpenFoodFactsApiWrapper
10
{
11
    public readonly Api $api;
12
13 30
    public function __construct(
14
        public readonly array $parameters,
15
        protected readonly ?CacheInterface $cache = null,
16
        string $environment = 'food'
17
    ) {
18 30
        $this->api = $this->setupApi($environment);
0 ignored issues
show
The property api is declared read-only in OpenFoodFacts\Laravel\OpenFoodFactsApiWrapper.
Loading history...
19
    }
20
21 30
    protected function setupApi(string $environment): Api
22
    {
23 30
        return new Api(
24 30
            $environment,
25 30
            $this->parameters['geography'] ?? 'world',
26 30
            null,
27 30
            $this->httpClient(),
28 30
            $this->cache
29 30
        );
30
    }
31
32 30
    protected function httpClient(): Client
33
    {
34 30
        return new Client([
35 30
            'headers' => ['User-Agent' => $this->parameters['app'] ?? 'Laravel Open Food Facts - https://github.com/openfoodfacts/openfoodfacts-laravel'],
36 30
        ]);
37
    }
38
}
39