helpers.php ➔ credentials()   A
last analyzed

Complexity

Conditions 2
Paths 4

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 4
nop 2
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
1
<?php
2
3
use BeyondCode\Credentials\Credentials;
4
use Illuminate\Contracts\Container\BindingResolutionException;
5
6
if (! function_exists('credentials')) {
7
    /**
8
     * Get a an encrypted value.
9
     *
10
     * @param string $key
11
     * @param null $default
12
     * @return mixed
13
     */
14
    function credentials(string $key, $default = null)
15
    {
16
        $filename = config('credentials.file');
17
        try {
18
            $credentials = app(Credentials::class);
19
            $credentials->load($filename);
20
21
            return $credentials->get($key, $default);
22
23
        } catch (ReflectionException | BindingResolutionException $e) {
24
25
            return Credentials::CONFIG_PREFIX . $key;
26
27
        }
28
29
    }
30
}
31