Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
Environment
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
4 / 4
8
100.00% covered (success)
100.00%
1 / 1
 description
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
5
 isProduction
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isPreProduction
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isDebugFriendly
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/**
6 * Ergonomic utilities for PHP enums, including names, values, lookups, and option maps.
7 *
8 * This file is part of fast-forward/enum project.
9 *
10 * @author   Felipe SayĆ£o Lobato Abreu <github@mentordosnerds.com>
11 * @license  https://opensource.org/licenses/MIT MIT License
12 *
13 * @see      https://github.com/php-fast-forward/enum
14 * @see      https://github.com/php-fast-forward/enum/issues
15 * @see      https://php-fast-forward.github.io/enum/
16 * @see      https://datatracker.ietf.org/doc/html/rfc2119
17 */
18
19namespace FastForward\Enum\Runtime;
20
21use FastForward\Enum\DescribedEnumInterface;
22use FastForward\Enum\LabeledEnumInterface;
23use FastForward\Enum\Trait\Comparable;
24use FastForward\Enum\Trait\HasLabel;
25use FastForward\Enum\Trait\HasNameLookup;
26use FastForward\Enum\Trait\HasNameMap;
27use FastForward\Enum\Trait\HasNames;
28use FastForward\Enum\Trait\HasOptions;
29use FastForward\Enum\Trait\HasValueMap;
30use FastForward\Enum\Trait\HasValues;
31
32enum Environment: string implements DescribedEnumInterface, LabeledEnumInterface
33{
34    use Comparable;
35    use HasLabel;
36    use HasNameLookup;
37    use HasNameMap;
38    use HasNames;
39    use HasOptions;
40    use HasValueMap;
41    use HasValues;
42
43    case Development = 'development';
44    case Testing = 'testing';
45    case Staging = 'staging';
46    case Production = 'production';
47
48    /**
49     * @return string
50     */
51    public function description(): string
52    {
53        return match ($this) {
54            self::Development => 'Local development environment with fast feedback and debugging enabled.',
55            self::Testing => 'Automated test environment intended for repeatable checks and validation.',
56            self::Staging => 'Pre-production environment used to verify releases before going live.',
57            self::Production => 'Live environment serving real users and production workloads.',
58        };
59    }
60
61    /**
62     * @return bool
63     */
64    public function isProduction(): bool
65    {
66        return self::Production === $this;
67    }
68
69    /**
70     * @return bool
71     */
72    public function isPreProduction(): bool
73    {
74        return $this->in([self::Development, self::Testing, self::Staging]);
75    }
76
77    /**
78     * @return bool
79     */
80    public function isDebugFriendly(): bool
81    {
82        return $this->in([self::Development, self::Testing]);
83    }
84}