Passed
Push — master ( 9c41dd...0881bb )
by Caen
03:41 queued 12s
created

Config::getString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Facades;
6
7
/**
8
 * An extension of the Laravel Config facade with extra
9
 * accessors that ensure the types of the returned values.
10
 *
11
 * @internal This facade is not meant to be used by the end user.
12
 * @experimental This facade is experimental and may change in the future.
13
 *
14
 * @todo If class is kept internal, the facade alias should be removed from config.
15
 *
16
 * @see \Illuminate\Config\Repository
17
 * @see \Illuminate\Support\Facades\Config
18
 * @see \Hyde\Framework\Testing\Feature\TypedConfigFacadeTest
19
 */
20
class Config extends \Illuminate\Support\Facades\Config
21
{
22
    /** @var false {@todo Consider setting to true} */
23
    protected const STRICT_DEFAULT = false;
24
25
    public static function getArray(array|string $key, array $default = null, bool $strict = self::STRICT_DEFAULT): array
26
    {
27
        return $strict ? static::get($key, $default) : (array) static::get($key, $default);
28
    }
29
30
    public static function getString(string $key, string $default = null, bool $strict = self::STRICT_DEFAULT): string
31
    {
32
        return $strict ? static::get($key, $default) : (string) static::get($key, $default);
33
    }
34
35
    public static function getInt(string $key, int $default = null, bool $strict = self::STRICT_DEFAULT): int
36
    {
37
        return $strict ? static::get($key, $default) : (int) static::get($key, $default);
38
    }
39
40
    public static function getBool(string $key, bool $default = null, bool $strict = self::STRICT_DEFAULT): bool
41
    {
42
        return $strict ? static::get($key, $default) : (bool) static::get($key, $default);
43
    }
44
45
    public static function getFloat(string $key, float $default = null, bool $strict = self::STRICT_DEFAULT): float
46
    {
47
        return $strict ? static::get($key, $default) : (float) static::get($key, $default);
48
    }
49
}
50