Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ChangelogEntryType | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| ordered | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| fromInput | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * Fast Forward Development Tools for PHP projects. |
| 7 | * |
| 8 | * This file is part of fast-forward/dev-tools 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/ |
| 14 | * @see https://github.com/php-fast-forward/dev-tools |
| 15 | * @see https://github.com/php-fast-forward/dev-tools/issues |
| 16 | * @see https://php-fast-forward.github.io/dev-tools/ |
| 17 | * @see https://datatracker.ietf.org/doc/html/rfc2119 |
| 18 | */ |
| 19 | |
| 20 | namespace FastForward\DevTools\Changelog\Entry; |
| 21 | |
| 22 | use InvalidArgumentException; |
| 23 | |
| 24 | /** |
| 25 | * Represents the supported Keep a Changelog entry categories. |
| 26 | */ |
| 27 | enum ChangelogEntryType: string |
| 28 | { |
| 29 | case Added = 'Added'; |
| 30 | case Changed = 'Changed'; |
| 31 | case Deprecated = 'Deprecated'; |
| 32 | case Removed = 'Removed'; |
| 33 | case Fixed = 'Fixed'; |
| 34 | case Security = 'Security'; |
| 35 | |
| 36 | /** |
| 37 | * Returns the changelog section ordering expected by the renderer. |
| 38 | * |
| 39 | * @return list<self> |
| 40 | */ |
| 41 | public static function ordered(): array |
| 42 | { |
| 43 | return [self::Added, self::Changed, self::Deprecated, self::Removed, self::Fixed, self::Security]; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Resolves a user-provided category value to an enum case. |
| 48 | * |
| 49 | * @param string $value the raw category value |
| 50 | * |
| 51 | * @return self the resolved changelog entry type |
| 52 | */ |
| 53 | public static function fromInput(string $value): self |
| 54 | { |
| 55 | $normalized = ucfirst(strtolower(trim($value))); |
| 56 | |
| 57 | return self::tryFrom($normalized) |
| 58 | ?? throw new InvalidArgumentException(\sprintf('Unsupported changelog type "%s".', $value)); |
| 59 | } |
| 60 | } |