Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
Scheme
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
3 / 3
7
100.00% covered (success)
100.00%
1 / 1
 description
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
 defaultPort
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
 isSecure
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\Http;
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 Scheme: 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 Http = 'http';
44    case Https = 'https';
45
46    /**
47     * @return string
48     */
49    public function description(): string
50    {
51        return match ($this) {
52            self::Http => 'Plain HTTP transport without transport-layer encryption.',
53            self::Https => 'HTTP transport secured with TLS encryption.',
54        };
55    }
56
57    /**
58     * @return int
59     */
60    public function defaultPort(): int
61    {
62        return match ($this) {
63            self::Http => 80,
64            self::Https => 443,
65        };
66    }
67
68    /**
69     * @return bool
70     */
71    public function isSecure(): bool
72    {
73        return $this->is(self::Https);
74    }
75}