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

Config   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 7
c 4
b 0
f 0
dl 0
loc 28
rs 10
wmc 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getString() 0 3 2
A getInt() 0 3 2
A getArray() 0 3 2
A getBool() 0 3 2
A getFloat() 0 3 2
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