Test Failed
Pull Request — master (#11)
by Stanislau
04:37 queued 58s
created

AppModeEnum::isTest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 *  This file is part of the Micro framework package.
7
 *
8
 *  (c) Stanislau Komar <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Micro\Framework\Kernel;
15
16
enum AppModeEnum: string
17
{
18
    case DEV = 'dev';
19
    case TEST = 'test';
20
    case PROD = 'prod';
21
22
    /**
23
     * @psalm-suppress PossiblyUnusedMethod
24
     */
25
    public function isDev(): bool
26
    {
27
        return self::DEV === $this;
28
    }
29
30
    /**
31
     * @psalm-suppress PossiblyUnusedMethod
32
     */
33
    public function isTest(): bool
34
    {
35
        return self::TEST === $this;
36
    }
37
38
    public function isProd(): bool
39
    {
40
        return self::PROD === $this;
41
    }
42
43
    /**
44
     * @psalm-suppress PossiblyUnusedMethod
45
     */
46
    public static function fromString(string $mode): self
47
    {
48
        $normalized = strtolower($mode);
49
50
        return match ($normalized) {
51
            'dev', 'development' => self::DEV,
52
            'test' => self::TEST,
53
            'prod', 'production' => self::PROD,
54
            default => throw new \InvalidArgumentException("Unknown app mode: {$mode}"),
55
        };
56
    }
57
}
58