Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
73.68% covered (warning)
73.68%
14 / 19
37.50% covered (danger)
37.50%
3 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
Configuration
73.68% covered (warning)
73.68%
14 / 19
37.50% covered (danger)
37.50%
3 / 8
11.82
0.00% covered (danger)
0.00%
0 / 1
 __construct
85.71% covered (warning)
85.71%
6 / 7
0.00% covered (danger)
0.00%
0 / 1
2.01
 getApiKey
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getEnvironment
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getControllerHost
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getAdditionalHeaders
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getTimeout
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDefaultHeaders
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 getApiKeyFromEnvironment
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3declare(strict_types=1);
4
5namespace Mbvb1223\Pinecone\Utils;
6
7use Mbvb1223\Pinecone\Errors\PineconeException;
8
9class Configuration
10{
11    private string $apiKey;
12    private string $environment;
13    private string $controllerHost;
14    private array $additionalHeaders;
15    private int $timeout;
16
17    public function __construct(?string $apiKey = null, ?array $config = null)
18    {
19        $this->apiKey = $apiKey ?? $this->getApiKeyFromEnvironment();
20        $this->environment = $config['environment'] ?? 'us-east1-aws';
21        $this->controllerHost = $config['controllerHost'] ?? 'https://api.pinecone.io';
22        $this->additionalHeaders = $config['additionalHeaders'] ?? [];
23        $this->timeout = $config['timeout'] ?? 30;
24
25        if (empty($this->apiKey)) {
26            throw new PineconeException('API key is required. Set PINECONE_API_KEY environment variable or pass it in configuration.');
27        }
28    }
29
30    public function getApiKey(): string
31    {
32        return $this->apiKey;
33    }
34
35    public function getEnvironment(): string
36    {
37        return $this->environment;
38    }
39
40    public function getControllerHost(): string
41    {
42        return $this->controllerHost;
43    }
44
45    public function getAdditionalHeaders(): array
46    {
47        return $this->additionalHeaders;
48    }
49
50    public function getTimeout(): int
51    {
52        return $this->timeout;
53    }
54
55    public function getDefaultHeaders(): array
56    {
57        return array_merge([
58            'Api-Key' => $this->apiKey,
59            'User-Agent' => 'pinecone-php-client/1.0.0',
60            'Content-Type' => 'application/json',
61            'X-Pinecone-Api-Version' => '2025-10',
62        ], $this->additionalHeaders);
63    }
64
65    private function getApiKeyFromEnvironment(): string
66    {
67        return $_ENV['PINECONE_API_KEY'] ?? getenv('PINECONE_API_KEY') ?: '';
68    }
69}