DotenvAdapter::apiKey()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace CryptoPete\Frost\Adapter\Settings;
4
5
use CryptoPete\Frost\Exception\SettingsException;
6
use CryptoPete\Frost\Exception\SettingsNotFoundException;
7
use Dotenv\Dotenv;
8
9
/**
10
 * Class DotenvAdapter
11
 *
12
 * The dotenv adaptor for loading settings
13
 */
14
class DotenvAdapter implements SettingsInterface
15
{
16
    /**
17
     * DotenvAdapter constructor
18
     *
19
     * @param Dotenv $client
20
     */
21 8
    public function __construct(Dotenv $settings)
22
    {
23
        try {
24 8
            $settings->load();
25 2
        } catch (\Dotenv\Exception\InvalidPathException $e) {
26 1
            throw new SettingsNotFoundException('Invalid path to settings config file');
27 1
        } catch (\Throwable $t) {
28 1
            throw new SettingsException('Access to settings failed');
29
        }
30 6
    }
31
32
    /**
33
     * @inheritdoc
34
     */
35 4
    public function apiKey(): string
36
    {
37 4
        return (string) getenv('FROST_API_KEY');
38
    }
39
}
40